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 protected NTuple<Location> locTuple;
15 public CompositeLocation(ClassDescriptor cd) {
17 locTuple = new NTuple<Location>();
20 public NTuple<Location> getTuple() {
24 public int getBaseLocationSize() {
25 return getBaseLocationSet().size();
28 public void addLocation(Location loc) {
30 if (loc instanceof DeltaLocation) {
31 type = Location.DELTA;
34 locTuple.addElement(loc);
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, Location>();
66 Set<Location> baseLocSet = getBaseLocationSet();
67 for (Iterator iterator = baseLocSet.iterator(); iterator.hasNext();) {
68 Location location = (Location) iterator.next();
69 cd2loc.put(location.getClassDescriptor(), location);
76 public Set<Location> getBaseLocationSet() {
78 Set<Location> baseLocationSet = new HashSet<Location>();
79 int tupleSize = locTuple.size();
80 for (int i = 0; i < tupleSize; i++) {
81 Location locElement = locTuple.at(i);
83 if (locElement instanceof DeltaLocation) {
84 // baseLocationSet.addAll(((DeltaLocation)
85 // locElement).getDeltaOperandLocationVec());
86 baseLocationSet.addAll(((DeltaLocation) locElement).getBaseLocationSet());
88 baseLocationSet.add(locElement);
91 return baseLocationSet;
94 public int getNumofDelta() {
98 if (locTuple.size() == 1) {
99 Location locElement = locTuple.at(0);
100 if (locElement instanceof DeltaLocation) {
102 result += getNumofDelta((DeltaLocation) locElement);
108 public int getNumofDelta(DeltaLocation delta) {
111 if (delta.getDeltaOperandLocationVec().size() == 1) {
112 Location locElement = delta.getDeltaOperandLocationVec().at(0);
113 if (locElement instanceof DeltaLocation) {
115 result += getNumofDelta((DeltaLocation) locElement);
122 public String toString() {
124 // for better representation
125 // if compositeLoc has only one single location,
126 // just print out single location
127 // if(locTuple.size()==1){
128 // Location locElement=locTuple.at(0);
129 // if(locElement instanceof Location){
130 // return locElement.toString();
134 String rtr = "CompLoc[";
136 int tupleSize = locTuple.size();
137 for (int i = 0; i < tupleSize; i++) {
138 Location locElement = locTuple.at(i);
149 public boolean equals(Object o) {
151 if (!(o instanceof CompositeLocation)) {
155 CompositeLocation compLoc = (CompositeLocation) o;
157 if (compLoc.getClassDescriptor().equals(getClassDescriptor())
158 && compLoc.getTuple().equals(getTuple())) {
166 public int hashCode() {
168 int hashCode = getClassDescriptor().hashCode();
169 return hashCode + locTuple.hashCode();