changes.
[IRC.git] / Robust / src / Analysis / SSJava / CompositeLocation.java
1 package Analysis.SSJava;
2
3 import IR.TypeExtension;
4
5 public class CompositeLocation implements TypeExtension {
6
7   protected NTuple<Location> locTuple;
8
9   public CompositeLocation() {
10     locTuple = new NTuple<Location>();
11   }
12
13   public CompositeLocation(NTuple<Location> locTuple) {
14     this.locTuple = locTuple.clone();
15   }
16
17   public CompositeLocation(Location loc) {
18     locTuple = new NTuple<Location>();
19     locTuple.add(loc);
20   }
21
22   public NTuple<Location> getTuple() {
23     return locTuple;
24   }
25
26   public int getSize() {
27     return locTuple.size();
28   }
29
30   public void addLocation(Location loc) {
31     locTuple.add(loc);
32   }
33
34   public Location get(int idx) {
35     return locTuple.get(idx);
36   }
37
38   public boolean isEmpty() {
39     return locTuple.size() == 0;
40   }
41
42   public boolean startsWith(CompositeLocation prefix) {
43     // tests if this composite location starts with the prefix
44
45     for (int i = 0; i < prefix.getSize(); i++) {
46       if (!prefix.get(i).equals(get(i))) {
47         return false;
48       }
49     }
50     return true;
51
52   }
53
54   public String toString() {
55
56     String rtr = "CompLoc[";
57
58     int tupleSize = locTuple.size();
59     for (int i = 0; i < tupleSize; i++) {
60       Location locElement = locTuple.get(i);
61       if (i != 0) {
62         rtr += ",";
63       }
64       rtr += locElement;
65     }
66     rtr += "]";
67
68     return rtr;
69   }
70
71   public boolean equals(Object o) {
72
73     if (!(o instanceof CompositeLocation)) {
74       return false;
75     }
76
77     CompositeLocation compLoc = (CompositeLocation) o;
78
79     if (compLoc.getTuple().equals(getTuple())) {
80       return true;
81     } else {
82       return false;
83     }
84
85   }
86
87   public int hashCode() {
88
89     return locTuple.hashCode();
90
91   }
92
93   public CompositeLocation clone() {
94     CompositeLocation clone = new CompositeLocation();
95     clone.getTuple().addAll(locTuple);
96     return clone;
97   }
98
99 }