bug fixes
[IRC.git] / Robust / src / Analysis / TaskStateAnalysis / FEdge.java
1 package Analysis.TaskStateAnalysis;
2 import IR.*;
3 import Analysis.TaskStateAnalysis.*;
4 import IR.Tree.*;
5 import IR.Flat.*;
6 import java.util.*;
7 import Util.Edge;
8
9 /* Edge *****************/
10
11 public class FEdge extends Edge {
12
13     private String label;
14     private TaskDescriptor td;
15     private int parameterindex;
16     
17     // jzhou
18     private int executeTime;
19     private Hashtable<ClassDescriptor, NewObjInfo> newObjInfos;
20     private int probability;
21     private int invokeNum;
22     private int expInvokeNum;
23     
24     public class NewObjInfo {
25         int newRate;
26         int probability;
27         FlagState root;
28         int invokeNum;
29         
30         public NewObjInfo() {
31             newRate = 0;
32             probability = 0;
33             root = null;
34             invokeNum = 0;
35         }
36         
37         public NewObjInfo(int newRate, int probability) {
38             this.newRate = newRate;
39             this.probability = probability;
40         }
41         
42         public int getNewRate() {
43             return this.newRate;
44         }
45         
46         public void setNewRate(int newRate) {
47             this.newRate = newRate;
48         }
49         
50         public int getProbability() {
51             return this.probability;
52         }
53         
54         public void setProbability(int probability) {
55             this.probability = probability;
56         }
57         
58         public FlagState getRoot() {
59             return root;
60         }
61
62         public void setRoot(FlagState root) {
63             this.root = root;
64         }
65
66         public int getInvokeNum() {
67             return invokeNum;
68         }
69
70         public void incInvokeNum() {
71             this.invokeNum++;
72         }
73
74         public boolean equals(Object o) {
75             if (o instanceof NewObjInfo) {
76                 NewObjInfo e=(NewObjInfo)o;
77                 if (e.newRate == this.newRate &&
78                     e.probability == this.probability &&
79                     e.invokeNum == this.invokeNum &&
80                     e.root.equals(this.root)) {
81                     return true;
82                 }
83             }
84             return false;
85         }
86     }
87     
88     /** Class Constructor
89      * 
90      */
91     public FEdge(FlagState target, String label, TaskDescriptor td, int parameterindex) {
92         super(target);
93         this.label = label;
94         this.td=td;
95         this.parameterindex=parameterindex;
96         this.executeTime = -1;
97         this.newObjInfos = null;
98         this.probability = -1;
99         this.invokeNum = 0;
100         this.expInvokeNum = 0;
101     }
102
103     public int getProbability() {
104         return probability;
105     }
106
107     public void setProbability(int probability) {
108         this.probability = probability;
109     }
110
111     public String getLabel() {
112         return label;
113     }
114     
115     public int hashCode(){
116         int hashcode = label.hashCode()^target.hashCode()^source.hashCode()^td.hashCode()^parameterindex^executeTime;
117         if(newObjInfos != null) {
118             hashcode ^= newObjInfos.hashCode();
119         }
120         return hashcode;
121     }
122
123     public TaskDescriptor getTask() {
124         return td;
125     }
126
127     public int getIndex() {
128         return parameterindex;
129     }
130         
131     public boolean equals(Object o) {
132         if (o instanceof FEdge) {
133             FEdge e=(FEdge)o;
134             if (e.label.equals(label)&&
135                 e.target.equals(target)&&
136                 e.source.equals(source) &&
137                 e.td==td&&
138                 e.parameterindex==parameterindex &&
139                 e.executeTime == executeTime) {
140                 if(this.newObjInfos != null) {
141                     if(e.newObjInfos == null) {
142                         return false;
143                     } else {
144                         return e.newObjInfos.equals(this.newObjInfos);
145                     }
146                 }
147                 return true;
148             }
149         }
150         return false;
151     }
152     
153     public int getExeTime() {
154         return this.executeTime;
155     }
156     
157     public void setExeTime(int eTime) {
158         this.executeTime = eTime;
159     }
160     
161     public Hashtable<ClassDescriptor, NewObjInfo> getNewObjInfoHashtable() {
162         return this.newObjInfos;
163     }
164     
165     public NewObjInfo getNewObjInfo(ClassDescriptor cd) {
166         if(this.newObjInfos == null) {
167             return null;
168         }
169         return this.newObjInfos.get(cd);
170     }
171     
172     public void addNewObjInfo(ClassDescriptor cd, int newRate, int probability) {
173         if(this.newObjInfos == null) {
174             this.newObjInfos = new Hashtable<ClassDescriptor, NewObjInfo>();
175         }
176         this.newObjInfos.put(cd, new NewObjInfo(newRate, probability));
177     }
178     
179     public void process() {
180         this.invokeNum++;
181     }
182
183     public int getInvokeNum() {
184         return invokeNum;
185     }
186
187     public int getInvokeNumGap() {
188         return expInvokeNum - invokeNum;
189     }
190
191     public void setExpInvokeNum(int expInvokeNum) {
192         this.expInvokeNum = expInvokeNum;
193     }
194     
195 }