Fix tabbing.... Please fix your editors so they do tabbing correctly!!! (Spaces...
[IRC.git] / Robust / src / Analysis / Disjoint / ChangeSet.java
1 package Analysis.Disjoint;
2
3 import IR.*;
4 import IR.Flat.*;
5 import java.util.*;
6 import java.io.*;
7
8 ///////////////////////////////////////////
9 //  IMPORTANT
10 //  This class is an immutable Canonical, so
11 //
12 //  0) construct them with a factory pattern
13 //  to ensure only canonical versions escape
14 //
15 //  1) any operation that modifies a Canonical
16 //  is a static method in the Canonical class
17 //
18 //  2) operations that just read this object
19 //  should be defined here
20 //
21 //  3) every Canonical subclass hashCode should
22 //  throw an error if the hash ever changes
23 //
24 ///////////////////////////////////////////
25
26 public class ChangeSet extends Canonical {
27
28   protected HashSet<ChangeTuple> changeTuples;
29
30   public static ChangeSet factory() {
31     ChangeSet out = new ChangeSet();
32     out = (ChangeSet) Canonical.makeCanonical(out);
33     return out;
34   }
35
36   public static ChangeSet factory(ChangeTuple ct) {
37     assert ct != null;
38     assert ct.isCanonical();
39     ChangeSet out = new ChangeSet();
40     out.changeTuples.add(ct);
41     out = (ChangeSet) Canonical.makeCanonical(out);
42     return out;
43   }
44
45   protected ChangeSet() {
46     changeTuples = new HashSet<ChangeTuple>();
47   }
48
49   public Iterator<ChangeTuple> iterator() {
50     return changeTuples.iterator();
51   }
52
53   public int size() {
54     return changeTuples.size();
55   }
56
57   public boolean isEmpty() {
58     return changeTuples.isEmpty();
59   }
60
61   public boolean isSubset(ChangeSet ctsIn) {
62     assert ctsIn != null;
63     return ctsIn.changeTuples.containsAll(this.changeTuples);
64   }
65
66
67   public boolean equalsSpecific(Object o) {
68     if( o == null ) {
69       return false;
70     }
71
72     if( !(o instanceof ChangeSet) ) {
73       return false;
74     }
75
76     ChangeSet cts = (ChangeSet) o;
77     return changeTuples.equals(cts.changeTuples);
78   }
79
80   public int hashCodeSpecific() {
81     return changeTuples.hashCode();
82   }
83
84
85   public String toString() {
86     String s = "[";
87
88     Iterator i = this.iterator();
89     while( i.hasNext() ) {
90       s += "\n  "+i.next();
91     }
92
93     s += "\n]";
94
95     return s;
96   }
97 }