switch to spaces only..
[IRC.git] / Robust / src / Analysis / OwnershipAnalysis / ChangeTuple.java
1 package Analysis.OwnershipAnalysis;
2
3 import IR.*;
4 import IR.Flat.*;
5 import java.util.*;
6 import java.io.*;
7
8
9 // a change touple is a pair that indicates if the
10 // first TokenTupleSet is found in a ReachabilitySet,
11 // then the second TokenTupleSet should be added
12
13 // THIS CLASS IS IMMUTABLE!
14
15 public class ChangeTuple extends Canonical
16 {
17   private TokenTupleSet toMatch;
18   private TokenTupleSet toAdd;
19
20   public ChangeTuple(TokenTupleSet toMatch,
21                      TokenTupleSet toAdd) {
22     this.toMatch = toMatch;
23     this.toAdd   = toAdd;
24   }
25
26   public ChangeTuple makeCanonical() {
27     return (ChangeTuple) Canonical.makeCanonical(this);
28   }
29
30   public TokenTupleSet getSetToMatch() {
31     return toMatch;
32   }
33   public TokenTupleSet getSetToAdd() {
34     return toAdd;
35   }
36
37
38   public boolean equals(Object o) {
39     if( o == null ) {
40       return false;
41     }
42
43     if( !(o instanceof ChangeTuple) ) {
44       return false;
45     }
46
47     ChangeTuple ct = (ChangeTuple) o;
48
49     return toMatch.equals(ct.getSetToMatch() ) &&
50            toAdd.equals(ct.getSetToAdd()   );
51   }
52
53   private boolean oldHashSet = false;
54   private int oldHash    = 0;
55   public int hashCode() {
56     int currentHash = toMatch.hashCode() + toAdd.hashCode()*3;
57
58     if( oldHashSet == false ) {
59       oldHash = currentHash;
60       oldHashSet = true;
61     } else {
62       if( oldHash != currentHash ) {
63         System.out.println("IF YOU SEE THIS A CANONICAL ChangeTuple CHANGED");
64         Integer x = null;
65         x.toString();
66       }
67     }
68
69     return currentHash;
70   }
71
72
73   public String toString() {
74     return new String("("+toMatch+" -> "+toAdd+")");
75   }
76 }