changes.
[IRC.git] / Robust / src / Analysis / SSJava / DeltaLocation.java
1 package Analysis.SSJava;
2
3 import java.util.HashSet;
4 import java.util.List;
5 import java.util.Set;
6 import java.util.Vector;
7
8 import IR.ClassDescriptor;
9 import IR.TypeDescriptor;
10
11 public class DeltaLocation extends CompositeLocation {
12
13   private TypeDescriptor refOperand = null;
14
15   public DeltaLocation(ClassDescriptor cd) {
16     super(cd);
17   }
18
19   public DeltaLocation(ClassDescriptor cd, Set<Location> set) {
20     super(cd);
21     locTuple.addAll(set);
22   }
23
24   public DeltaLocation(ClassDescriptor cd, TypeDescriptor refOperand) {
25     super(cd);
26     this.refOperand = refOperand;
27   }
28
29   public TypeDescriptor getRefLocationId() {
30     return this.refOperand;
31   }
32
33   public void addDeltaOperand(Location op) {
34     locTuple.addElement(op);
35   }
36
37   public NTuple<Location> getDeltaOperandLocationVec() {
38     return locTuple;
39   }
40
41   // public Set<Location> getBaseLocationSet() {
42   //
43   // if (operandVec.size() == 1 && (operandVec.get(0) instanceof DeltaLocation))
44   // {
45   // // nested delta definition
46   // DeltaLocation deltaLoc = (DeltaLocation) operandVec.get(0);
47   // return deltaLoc.getBaseLocationSet();
48   // } else {
49   // Set<Location> set = new HashSet<Location>();
50   // set.addAll(operandVec);
51   // return set;
52   // }
53   //
54   // }
55
56   public boolean equals(Object o) {
57
58     if (!(o instanceof DeltaLocation)) {
59       return false;
60     }
61
62     DeltaLocation deltaLoc = (DeltaLocation) o;
63
64     if (deltaLoc.getDeltaOperandLocationVec().equals(getDeltaOperandLocationVec())) {
65       return true;
66     }
67     return false;
68   }
69
70   public int hashCode() {
71     int hash = cd.hashCode();
72     hash += locTuple.hashCode();
73     if (refOperand != null) {
74       hash += refOperand.hashCode();
75     }
76     return hash;
77   }
78
79   public String toString() {
80     String rtr = "delta(";
81
82     if (locTuple.size() != 0) {
83       int tupleSize = locTuple.size();
84       for (int i = 0; i < tupleSize; i++) {
85         Location locElement = locTuple.at(i);
86         if (i != 0) {
87           rtr += ",";
88         }
89         rtr += locElement;
90       }
91     } else {
92       rtr += "LOC_REF";
93     }
94
95     rtr += ")";
96
97     return rtr;
98   }
99
100 }