adding a test case
[IRC.git] / Robust / src / Analysis / SSJava / ReadSummary.java
1 package Analysis.SSJava;
2
3 import java.util.HashSet;
4 import java.util.Hashtable;
5 import java.util.Iterator;
6 import java.util.Set;
7
8 import IR.Descriptor;
9
10 public class ReadSummary {
11
12   Hashtable<NTuple<Descriptor>, Hashtable<Location, Set<Descriptor>>> summary;
13
14   public ReadSummary() {
15     summary = new Hashtable<NTuple<Descriptor>, Hashtable<Location, Set<Descriptor>>>();
16   }
17
18   public Hashtable<NTuple<Descriptor>, Hashtable<Location, Set<Descriptor>>> getSummary() {
19     return summary;
20   }
21
22   public Set<NTuple<Descriptor>> keySet() {
23     return summary.keySet();
24   }
25
26   public Hashtable<Location, Set<Descriptor>> get(NTuple<Descriptor> hp) {
27     return summary.get(hp);
28   }
29
30   private Set<Descriptor> getReadSet(NTuple<Descriptor> key, Location loc) {
31     Hashtable<Location, Set<Descriptor>> map = summary.get(key);
32     if (map == null) {
33       map = new Hashtable<Location, Set<Descriptor>>();
34       summary.put(key, map);
35     }
36     Set<Descriptor> descSet = map.get(loc);
37     if (descSet == null) {
38       descSet = new HashSet<Descriptor>();
39       map.put(loc, descSet);
40     }
41     return descSet;
42   }
43
44   public void addRead(NTuple<Descriptor> key, Location loc, Descriptor in) {
45     if (loc != null) {
46       // if location is null, we do not need to care about it!
47       Set<Descriptor> readSet = getReadSet(key, loc);
48       readSet.add(in);
49     }
50   }
51
52   public void addReadSet(NTuple<Descriptor> key, Location loc, Set<Descriptor> inSet) {
53     Set<Descriptor> readSet = getReadSet(key, loc);
54     readSet.addAll(inSet);
55   }
56
57   public int hashCode() {
58     return summary.hashCode();
59   }
60
61   public boolean equals(Object o) {
62
63     if (!(o instanceof ReadSummary)) {
64       return false;
65     }
66
67     ReadSummary in = (ReadSummary) o;
68
69     if (getSummary().equals(in.getSummary())) {
70       return true;
71     }
72
73     return false;
74   }
75
76   public void put(NTuple<Descriptor> boundHeapPath, Hashtable<Location, Set<Descriptor>> inTable) {
77
78     Set<Location> keySet = inTable.keySet();
79     for (Iterator iterator = keySet.iterator(); iterator.hasNext();) {
80       Location locKey = (Location) iterator.next();
81       Set<Descriptor> readSet = inTable.get(locKey);
82       addReadSet(boundHeapPath, locKey, readSet);
83     }
84
85   }
86
87   public void merge(ReadSummary in) {
88
89     Set<NTuple<Descriptor>> keySet = in.keySet();
90     for (Iterator iterator = keySet.iterator(); iterator.hasNext();) {
91       NTuple<Descriptor> heapPathKey = (NTuple<Descriptor>) iterator.next();
92       put(heapPathKey, in.get(heapPathKey));
93     }
94   }
95
96   public String toString() {
97     return summary.toString();
98   }
99 }