Token propagation implemented, stable but incorrect. This is just a capture.
[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(); //COPY?!
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 ChangeTupleSet union( ChangeTupleSet ctsIn ) {
35         assert ctsIn != null;
36
37         ChangeTupleSet ctsOut = new ChangeTupleSet( this );
38         ctsOut.changeTuples.addAll( ctsIn.changeTuples );
39         return ctsOut.makeCanonical();
40     }
41
42     public ChangeTupleSet union( ChangeTuple ctIn ) {
43         assert ctIn != null;
44
45         ChangeTupleSet ctsOut = new ChangeTupleSet( this );
46         ctsOut.changeTuples.add( ctIn );
47         return ctsOut.makeCanonical();
48     }
49
50     public boolean isEmpty() {
51         return changeTuples.isEmpty();
52     }
53
54     public boolean isSubset( ChangeTupleSet ctsIn ) {
55         assert ctsIn != null;
56         return ctsIn.changeTuples.containsAll( this.changeTuples );
57     }
58
59     public boolean equals( Object o ) {
60         if( !(o instanceof ChangeTupleSet) ) {
61             return false;
62         }
63
64         ChangeTupleSet cts = (ChangeTupleSet) o;
65         return changeTuples.equals( cts.changeTuples );
66     }
67
68     public int hashCode() {
69         return changeTuples.hashCode();
70     }
71
72     public String toString() {
73         String s = "[";
74
75         Iterator i = this.iterator();
76         while( i.hasNext() ) {
77             s += "\n  "+i.next();
78         }
79
80         s += "\n]";
81
82         return s;
83     }
84 }