KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > ca > mcgill > sable > soot > interaction > DataKeeper


1 /* Soot - a J*va Optimization Framework
2  * Copyright (C) 2004 Jennifer Lhotak
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */

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         // this will be called from InteractionStepBack
40
// it will cause the most recent flow info data
41
// to be removed resulting in a blank if on iteration
42
// 0 or the results at this node from the
43
// previous iteration
44
// if it is the very fist node and
45
// very first iteration nothing will happen
46

47         // no where to go back to
48
if (getCurrent() == null) return;
49         int index = getFlowInfoList().indexOf(getCurrent());
50         FlowInfo previous;
51         FlowInfo clearTo;
52         // on first iter need to replace with empty
53
if (index > 0) {
54             previous = (FlowInfo)getFlowInfoList().get(index-1);
55             
56         }
57         else {
58             // at first node and want to go back
59
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 JavaDoc 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     /**
133      * @return
134      */

135     public FlowInfo getCurrent() {
136         return current;
137     }
138
139     /**
140      * @return
141      */

142     public List getFlowInfoList() {
143         return flowInfoList;
144     }
145
146     /**
147      * @return
148      */

149     public int getRepeat() {
150         return repeat;
151     }
152
153     /**
154      * @return
155      */

156     public int getTotal() {
157         return total;
158     }
159
160     /**
161      * @param info
162      */

163     public void setCurrent(FlowInfo info) {
164         current = info;
165     }
166
167     /**
168      * @param list
169      */

170     public void setFlowInfoList(List list) {
171         flowInfoList = list;
172     }
173
174     /**
175      * @param i
176      */

177     public void setRepeat(int i) {
178         repeat = i;
179     }
180
181     /**
182      * @param i
183      */

184     public void setTotal(int i) {
185         total = i;
186     }
187
188     /**
189      * @return
190      */

191     public InteractionController getController() {
192         return controller;
193     }
194
195     /**
196      * @param controller
197      */

198     public void setController(InteractionController controller) {
199         this.controller = controller;
200     }
201
202 }
203
Popular Tags