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;
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>();
80 int tupleSize = locTuple.size();
81 for (int i = 0; i < tupleSize; i++) {
82 Location locElement = locTuple.at(i);
84 if (locElement instanceof DeltaLocation) {
85 // baseLocationSet.addAll(((DeltaLocation)
86 // locElement).getDeltaOperandLocationVec());
87 baseLocationSet.addAll(((DeltaLocation) locElement).getBaseLocationSet());
89 baseLocationSet.add(locElement);
92 return baseLocationSet;
95 public int getNumofDelta() {
99 if (locTuple.size() == 1) {
100 Location locElement = locTuple.at(0);
101 if (locElement instanceof DeltaLocation) {
103 result += getNumofDelta((DeltaLocation) locElement);
109 public int getNumofDelta(DeltaLocation delta) {
112 if (delta.getDeltaOperandLocationVec().size() == 1) {
113 Location locElement = delta.getDeltaOperandLocationVec().get(0);
114 if (locElement instanceof DeltaLocation) {
116 result += getNumofDelta((DeltaLocation) locElement);
123 public String toString() {
125 // for better representation
126 // if compositeLoc has only one single location,
127 // just print out single location
128 // if(locTuple.size()==1){
129 // Location locElement=locTuple.at(0);
130 // if(locElement instanceof Location){
131 // return locElement.toString();
135 String rtr = "CompLoc[";
137 int tupleSize = locTuple.size();
138 for (int i = 0; i < tupleSize; i++) {
139 Location locElement = locTuple.at(i);
150 public boolean equals(Object o) {
152 if (!(o instanceof CompositeLocation)) {
156 CompositeLocation compLoc = (CompositeLocation) o;
158 if (compLoc.getClassDescriptor().equals(getClassDescriptor())
159 && compLoc.getTuple().equals(getTuple())) {
167 public int hashCode() {
169 int hashCode = getClassDescriptor().hashCode();
170 return hashCode + locTuple.hashCode();