switch to spaces only..
[IRC.git] / Robust / src / Analysis / OwnershipAnalysis / ChangeTupleSet.java
1 package Analysis.OwnershipAnalysis;
2
3 import IR.*;
4 import IR.Flat.*;
5 import java.util.*;
6 import java.io.*;
7
8
9 public class ChangeTupleSet extends Canonical {
10
11   private HashSet<ChangeTuple> changeTuples;
12
13   public ChangeTupleSet() {
14     changeTuples = new HashSet<ChangeTuple>();
15   }
16
17   public ChangeTupleSet(ChangeTuple ct) {
18     this();
19     changeTuples.add(ct);
20   }
21
22   public ChangeTupleSet(ChangeTupleSet cts) {
23     changeTuples = (HashSet<ChangeTuple>)cts.changeTuples.clone();
24   }
25
26   public ChangeTupleSet makeCanonical() {
27     return (ChangeTupleSet) Canonical.makeCanonical(this);
28   }
29
30   public Iterator iterator() {
31     return changeTuples.iterator();
32   }
33
34   public int size() {
35     return changeTuples.size();
36   }
37
38   public ChangeTupleSet union(ChangeTupleSet ctsIn) {
39     assert ctsIn != null;
40
41     ChangeTupleSet ctsOut = new ChangeTupleSet(this);
42     ctsOut.changeTuples.addAll(ctsIn.changeTuples);
43     return ctsOut.makeCanonical();
44   }
45
46   public ChangeTupleSet union(ChangeTuple ctIn) {
47     assert ctIn != null;
48
49     ChangeTupleSet ctsOut = new ChangeTupleSet(this);
50     ctsOut.changeTuples.add(ctIn);
51     return ctsOut.makeCanonical();
52   }
53
54   public boolean isEmpty() {
55     return changeTuples.isEmpty();
56   }
57
58   public boolean isSubset(ChangeTupleSet ctsIn) {
59     assert ctsIn != null;
60     return ctsIn.changeTuples.containsAll(this.changeTuples);
61   }
62
63
64   public boolean equals(Object o) {
65     if( o == null ) {
66       return false;
67     }
68
69     if( !(o instanceof ChangeTupleSet) ) {
70       return false;
71     }
72
73     ChangeTupleSet cts = (ChangeTupleSet) o;
74     return changeTuples.equals(cts.changeTuples);
75   }
76
77   private boolean oldHashSet = false;
78   private int oldHash    = 0;
79   public int hashCode() {
80     int currentHash = changeTuples.hashCode();
81
82     if( oldHashSet == false ) {
83       oldHash = currentHash;
84       oldHashSet = true;
85     } else {
86       if( oldHash != currentHash ) {
87         System.out.println("IF YOU SEE THIS A CANONICAL ChangeTupleSet CHANGED");
88         Integer x = null;
89         x.toString();
90       }
91     }
92
93     return currentHash;
94   }
95
96
97   public String toString() {
98     String s = "[";
99
100     Iterator i = this.iterator();
101     while( i.hasNext() ) {
102       s += "\n  "+i.next();
103     }
104
105     s += "\n]";
106
107     return s;
108   }
109 }