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