1 package Analysis.SSJava;
3 import IR.TypeExtension;
5 public class CompositeLocation implements TypeExtension {
7 protected NTuple<Location> locTuple;
9 public CompositeLocation() {
10 locTuple = new NTuple<Location>();
13 public CompositeLocation(Location loc) {
14 locTuple = new NTuple<Location>();
15 locTuple.addElement(loc);
18 public NTuple<Location> getTuple() {
22 public int getSize() {
23 return locTuple.size();
26 public void addLocation(Location loc) {
27 locTuple.addElement(loc);
30 public Location get(int idx) {
31 return locTuple.get(idx);
34 public boolean isEmpty(){
35 return locTuple.size()==0;
38 // public void addLocationSet(Set<Location> set) {
40 // for (Iterator iterator = set.iterator(); iterator.hasNext();) {
41 // Location location = (Location) iterator.next();
42 // locTuple.addElement(location);
47 // public Location getLocation(ClassDescriptor cd) {
49 // // need to get more optimization version later
50 // Set<Location> locSet = getBaseLocationSet();
51 // for (Iterator iterator = locSet.iterator(); iterator.hasNext();) {
52 // Location location = (Location) iterator.next();
53 // if (location.getClassDescriptor().equals(cd)) {
62 // public Map<ClassDescriptor, Location> getCd2Loc() {
64 // Map<ClassDescriptor, Location> cd2loc = new Hashtable<ClassDescriptor,
67 // Set<Location> baseLocSet = getBaseLocationSet();
68 // for (Iterator iterator = baseLocSet.iterator(); iterator.hasNext();) {
69 // Location location = (Location) iterator.next();
70 // cd2loc.put(location.getClassDescriptor(), location);
77 public NTuple<Location> getBaseLocationTuple() {
81 // NTuple<Location> baseLocationTuple = new NTuple<Location>();
82 // int tupleSize = locTuple.size();
83 // for (int i = 0; i < tupleSize; i++) {
84 // Location locElement = locTuple.at(i);
86 // if (locElement instanceof DeltaLocation) {
87 // // baseLocationSet.addAll(((DeltaLocation)
88 // // locElement).getDeltaOperandLocationVec());
89 // baseLocationTuple.addAll(((DeltaLocation)
90 // locElement).getBaseLocationTuple());
92 // baseLocationTuple.addElement(locElement);
95 // return baseLocationTuple;
99 // public List<Location> getBaseLocationList() {
101 // Set<Location> baseLocationSet = new HashSet<Location>();
102 // int tupleSize = locTuple.size();
103 // for (int i = 0; i < tupleSize; i++) {
104 // Location locElement = locTuple.at(i);
106 // if (locElement instanceof DeltaLocation) {
107 // // baseLocationSet.addAll(((DeltaLocation)
108 // // locElement).getDeltaOperandLocationVec());
109 // baseLocationSet.addAll(((DeltaLocation) locElement).getBaseLocationSet());
111 // baseLocationSet.add(locElement);
114 // return baseLocationSet;
117 // public int getNumofDelta() {
121 // if (locTuple.size() == 1) {
122 // Location locElement = locTuple.at(0);
123 // if (locElement instanceof DeltaLocation) {
125 // result += getNumofDelta((DeltaLocation) locElement);
131 // public int getNumofDelta(DeltaLocation delta) {
134 // if (delta.getDeltaOperandLocationVec().size() == 1) {
135 // Location locElement = delta.getDeltaOperandLocationVec().at(0);
136 // if (locElement instanceof DeltaLocation) {
138 // result += getNumofDelta((DeltaLocation) locElement);
145 // public void removieLocation(ClassDescriptor cd) {
146 // for (int i = 0; i < locTuple.size(); i++) {
147 // if (locTuple.at(i).getClassDescriptor().equals(cd)) {
148 // locTuple.removeAt(i);
154 public String toString() {
156 // for better representation
157 // if compositeLoc has only one single location,
158 // just print out single location
159 // if(locTuple.size()==1){
160 // Location locElement=locTuple.at(0);
161 // if(locElement instanceof Location){
162 // return locElement.toString();
166 String rtr = "CompLoc[";
168 int tupleSize = locTuple.size();
169 for (int i = 0; i < tupleSize; i++) {
170 Location locElement = locTuple.get(i);
181 public boolean equals(Object o) {
183 if (!(o instanceof CompositeLocation)) {
187 CompositeLocation compLoc = (CompositeLocation) o;
189 if (compLoc.getTuple().equals(getTuple())) {
197 public int hashCode() {
199 return locTuple.hashCode();