2 * Copyright (C) 2014, United States Government, as represented by the
3 * Administrator of the National Aeronautics and Space Administration.
6 * The Java Pathfinder core (jpf-core) platform is licensed under the
7 * Apache License, Version 2.0 (the "License"); you may not use this file except
8 * in compliance with the License. You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0.
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
18 package gov.nasa.jpf.vm;
20 import gov.nasa.jpf.util.Printable;
22 import java.io.PrintWriter;
23 import java.util.Iterator;
24 import java.util.LinkedList;
28 * Path represents the data structure in which a execution trace is recorded.
30 public class Path implements Printable, Iterable<Transition>, Cloneable {
32 private LinkedList<Transition> stack;
34 private Path() {} // for cloning
36 public Path (String app) {
38 stack = new LinkedList<Transition>();
43 Path clone = new Path();
44 clone.application = application;
46 // we need to deep copy the stack to preserve CG and ThreadInfo state
47 LinkedList<Transition> clonedStack = new LinkedList<Transition>();
48 for (Transition t : stack){
49 clonedStack.add( (Transition)t.clone());
51 clone.stack = clonedStack;
56 public String getApplication () {
60 public Transition getLast () {
61 if (stack.isEmpty()) {
64 return stack.getLast();
68 public void add (Transition t) {
72 public Transition get (int pos) {
73 return stack.get(pos);
76 public boolean isEmpty() {
77 return (stack.size() == 0);
84 public boolean hasOutput () {
85 for (Transition t : stack) {
86 if (t.getOutput() != null) {
94 public void printOutputOn (PrintWriter pw) {
95 for (Transition t : stack) {
96 String output = t.getOutput();
104 public void printOn (PrintWriter pw) {
105 /**** <2do> this is going away
109 for (int index = 0; index < length; index++) {
110 pw.print("Transition #");
113 if ((entry = get(index)) != null) {
122 public void removeLast () {
127 public Iterator<Transition> iterator () {
128 return stack.iterator();
131 public Iterator<Transition> descendingIterator() {
132 return stack.descendingIterator();