1 19 20 21 package ca.mcgill.sable.soot.interaction; 22 23 import soot.toolkits.graph.interaction.*; 24 import java.util.*; 25 26 public class DataKeeper { 27 28 private List flowInfoList; 29 private FlowInfo current; 30 private int total; 31 private int repeat; 32 private InteractionController controller; 33 34 public DataKeeper(InteractionController controller){ 35 setController(controller); 36 } 37 38 public void stepBack(){ 39 47 if (getCurrent() == null) return; 49 int index = getFlowInfoList().indexOf(getCurrent()); 50 FlowInfo previous; 51 FlowInfo clearTo; 52 if (index > 0) { 54 previous = (FlowInfo)getFlowInfoList().get(index-1); 55 56 } 57 else { 58 previous = null; 60 } 61 clearTo = findLast(); 62 63 setCurrent(previous); 64 getController().setEvent(new InteractionEvent(IInteractionConstants.CLEARTO, clearTo)); 65 getController().handleEvent(); 66 if (previous != null){ 67 getController().setEvent(new InteractionEvent(IInteractionConstants.REPLACE, previous)); 68 getController().handleEvent(); 69 } 70 71 } 72 73 private FlowInfo findLast(){ 74 Iterator it = getFlowInfoList().iterator(); 75 FlowInfo retInfo = new FlowInfo("", getCurrent().unit(), getCurrent().isBefore()); 76 77 while (it.hasNext()){ 78 FlowInfo next = (FlowInfo)it.next(); 79 80 if (getCurrent().equals(next)) break; 81 if (getCurrent().unit().equals(next.unit()) && (getCurrent().isBefore() == next.isBefore())){ 82 retInfo = next; 83 84 } 85 } 86 return retInfo; 87 } 88 89 public void addFlowInfo(Object fi){ 90 if (getFlowInfoList() == null){ 91 setFlowInfoList(new ArrayList()); 92 } 93 getFlowInfoList().add(fi); 94 setCurrent((FlowInfo)fi); 95 } 96 97 public boolean inMiddle(){ 98 if (getFlowInfoList() == null) return false; 99 if (getFlowInfoList().indexOf(getCurrent()) == getFlowInfoList().size()-1) return false; 100 return true; 101 } 102 103 public boolean canGoBack(){ 104 if (getFlowInfoList() == null) return false; 105 106 if (getFlowInfoList().size() == 0) return false; 107 108 if (getCurrent().equals(getFlowInfoList().get(0))) return false; 109 110 return true; 111 } 112 113 public void stepForward(){ 114 int index = getFlowInfoList().indexOf(getCurrent()); 115 FlowInfo next = (FlowInfo)getFlowInfoList().get(index+1); 116 getController().setEvent(new InteractionEvent(IInteractionConstants.REPLACE, next)); 117 getController().handleEvent(); 118 setCurrent(next); 119 120 } 121 122 public void stepForwardAuto(){ 123 int index = getFlowInfoList().indexOf(getCurrent()); 124 for (int i = index + 1; i < getFlowInfoList().size(); i++){ 125 FlowInfo next = (FlowInfo)getFlowInfoList().get(i); 126 getController().setEvent(new InteractionEvent(IInteractionConstants.REPLACE, next)); 127 getController().handleEvent(); 128 setCurrent(next); 129 } 130 } 131 132 135 public FlowInfo getCurrent() { 136 return current; 137 } 138 139 142 public List getFlowInfoList() { 143 return flowInfoList; 144 } 145 146 149 public int getRepeat() { 150 return repeat; 151 } 152 153 156 public int getTotal() { 157 return total; 158 } 159 160 163 public void setCurrent(FlowInfo info) { 164 current = info; 165 } 166 167 170 public void setFlowInfoList(List list) { 171 flowInfoList = list; 172 } 173 174 177 public void setRepeat(int i) { 178 repeat = i; 179 } 180 181 184 public void setTotal(int i) { 185 total = i; 186 } 187 188 191 public InteractionController getController() { 192 return controller; 193 } 194 195 198 public void setController(InteractionController controller) { 199 this.controller = controller; 200 } 201 202 } 203 | Popular Tags |