1 package Analysis.SSJava;
3 import java.util.HashSet;
4 import java.util.Hashtable;
5 import java.util.Iterator;
9 import IR.ClassDescriptor;
11 public class CompositeLocation extends Location {
13 private NTuple<Location> locTuple;
14 private Hashtable<ClassDescriptor, Location> cd2loc;
17 public CompositeLocation(ClassDescriptor cd) {
19 locTuple = new NTuple<Location>();
20 cd2loc = new Hashtable<ClassDescriptor, Location>();
24 public NTuple<Location> getTuple() {
28 public int getTupleSize() {
32 public void addLocation(Location loc) {
33 locTuple.addElement(loc);
35 if (loc instanceof DeltaLocation) {
36 DeltaLocation deltaLoc = (DeltaLocation) loc;
37 for (Iterator iterator = deltaLoc.getDeltaOperandLocationVec().iterator(); iterator.hasNext();) {
38 Location opLoc = (Location) iterator.next();
39 cd2loc.put(opLoc.getClassDescriptor(), opLoc);
43 cd2loc.put(loc.getClassDescriptor(), loc);
48 public Map<ClassDescriptor, Location> getCd2Loc() {
52 public Location getLocation(ClassDescriptor cd) {
53 return cd2loc.get(cd);
56 public Set<Location> getBaseLocationSet() {
58 Set<Location> baseLocationSet = new HashSet<Location>();
60 int tupleSize = locTuple.size();
61 for (int i = 0; i < tupleSize; i++) {
62 Location locElement = locTuple.at(i);
64 if (locElement instanceof DeltaLocation) {
65 baseLocationSet.addAll(((DeltaLocation) locElement).getDeltaOperandLocationVec());
67 baseLocationSet.add(locElement);
70 return baseLocationSet;
73 public int getNumofDelta() {
77 if (locTuple.size() == 1) {
78 Location locElement = locTuple.at(0);
79 if (locElement instanceof DeltaLocation) {
81 result += getNumofDelta((DeltaLocation) locElement);
87 public int getNumofDelta(DeltaLocation delta) {
90 if (delta.getDeltaOperandLocationVec().size() == 1) {
91 Location locElement = delta.getDeltaOperandLocationVec().get(0);
92 if (locElement instanceof DeltaLocation) {
94 result += getNumofDelta((DeltaLocation) locElement);
101 public String toString() {
103 // for better representation
104 // if compositeLoc has only one single location,
105 // just print out single location
106 // if(locTuple.size()==1){
107 // Location locElement=locTuple.at(0);
108 // if(locElement instanceof Location){
109 // return locElement.toString();
113 String rtr = "CompLoc[";
115 int tupleSize = locTuple.size();
116 for (int i = 0; i < tupleSize; i++) {
117 Location locElement = locTuple.at(i);
128 public boolean equals(Object o) {
130 if (!(o instanceof CompositeLocation)) {
134 CompositeLocation compLoc = (CompositeLocation) o;
136 if (compLoc.getClassDescriptor().equals(getClassDescriptor())
137 && compLoc.getTuple().equals(getTuple())) {
145 public int hashCode() {
147 int hashCode = getClassDescriptor().hashCode();
148 return hashCode + locTuple.hashCode();