1 package gov.nasa.jpf; 20 21 import gov.nasa.jpf.util.Printable; 22 23 import java.io.PrintWriter ; 24 25 import java.util.LinkedList ; 26 27 28 38 public class Path implements Printable { 39 String application; 40 private LinkedList list; 41 42 public Path (String app) { 43 application = app; 44 list = new LinkedList (); 45 } 46 47 private Path (String app, LinkedList l) { 48 application = app; 49 list = l; 50 } 51 52 public String getApplication () { 53 return application; 54 } 55 56 public Transition getLast () { 57 if (list.size() > 0) { 58 return (Transition) list.getLast(); 59 } else { 60 return null; 61 } 62 } 63 64 public void add (Transition t) { 65 list.add(t); 66 } 67 68 public Object clone () { 69 return new Path(application, (LinkedList ) list.clone()); 71 } 72 73 public Transition get (int pos) { 74 return (Transition) list.get(pos); 75 } 76 77 public int length () { 78 return list.size(); 79 } 80 81 public boolean hasOutput () { 82 int len = list.size(); 83 for (int i=0; i<len; i++) { 84 Transition t = (Transition)list.get(i); 85 if (t.getOutput() != null) { 86 return true; 87 } 88 } 89 90 return false; 91 } 92 93 public void printOutputOn (PrintWriter pw) { 94 int i; 95 int length = list.size(); 96 Transition t; 97 String s; 98 99 for (i=0; i<length; i++) { 100 t = (Transition)list.get(i); 101 s = t.getOutput(); 102 if (s != null) { 103 pw.print(s); 104 } 105 } 106 } 107 108 public void printOn (PrintWriter pw) { 109 int length = list.size(); 110 Object entry; 111 112 for (int index = 0; index < length; index++) { 113 pw.print("Transition #"); 114 pw.print(index); 115 116 if ((entry = list.get(index)) != null) { 117 pw.print(' '); 118 119 if (entry instanceof Printable) { 120 ((Printable) entry).printOn(pw); 121 } else { 122 pw.print(entry); 123 pw.flush(); 124 } 125 } 126 } 127 } 128 129 public void removeLast () { 130 list.removeLast(); 131 } 132 } 133 | Popular Tags |