1 package Analysis.OwnershipAnalysis;
9 public class ReachabilitySet extends Canonical {
11 private HashSet<TokenTupleSet> possibleReachabilities;
13 public ReachabilitySet() {
14 possibleReachabilities = new HashSet<TokenTupleSet>();
15 TokenTupleSet ttsEmpty = new TokenTupleSet().makeCanonical();
16 possibleReachabilities.add( ttsEmpty );
19 public ReachabilitySet( TokenTupleSet tts ) {
22 possibleReachabilities.add( tts );
25 public ReachabilitySet( TokenTuple tt ) {
26 this( new TokenTupleSet( tt ).makeCanonical() );
29 public ReachabilitySet( ReachabilitySet rs ) {
31 possibleReachabilities = (HashSet<TokenTupleSet>) rs.possibleReachabilities.clone(); // again, DEEP COPY?!
34 public ReachabilitySet makeCanonical() {
35 return (ReachabilitySet) Canonical.makeCanonical( this );
38 public boolean contains( TokenTupleSet tts ) {
40 return possibleReachabilities.contains( tts );
43 public Iterator iterator() {
44 return possibleReachabilities.iterator();
47 public ReachabilitySet union( ReachabilitySet rsIn ) {
50 ReachabilitySet rsOut = new ReachabilitySet( this );
52 System.out.println( "rsIn = "+rsIn );
53 System.out.println( "rsOut = "+rsOut );
55 rsOut.possibleReachabilities.addAll( rsIn.possibleReachabilities );
57 System.out.println( "union = "+rsOut );
59 return rsOut.makeCanonical();
62 public ReachabilitySet union( TokenTupleSet ttsIn ) {
65 ReachabilitySet rsOut = new ReachabilitySet( this );
66 rsOut.possibleReachabilities.add( ttsIn );
67 return rsOut.makeCanonical();
70 public ReachabilitySet intersection( ReachabilitySet rsIn ) {
73 ReachabilitySet rsOut = new ReachabilitySet();
75 Iterator i = this.iterator();
76 while( i.hasNext() ) {
77 TokenTupleSet tts = (TokenTupleSet) i.next();
78 if( rsIn.possibleReachabilities.contains( tts ) ) {
79 rsOut.possibleReachabilities.add( tts );
83 return rsOut.makeCanonical();
86 public ChangeTupleSet unionUpArity( ReachabilitySet rsIn ) {
89 ChangeTupleSet ctsOut = new ChangeTupleSet();
91 Iterator itrO = this.iterator();
92 while( itrO.hasNext() ) {
93 TokenTupleSet o = (TokenTupleSet) itrO.next();
95 Iterator itrR = rsIn.iterator();
96 while( itrR.hasNext() ) {
97 TokenTupleSet r = (TokenTupleSet) itrR.next();
99 TokenTupleSet theUnion = new TokenTupleSet();
101 Iterator itrRelement = r.iterator();
102 while( itrRelement.hasNext() ) {
103 TokenTuple e = (TokenTuple) itrRelement.next();
105 if( o.containsToken( e.getToken() ) ) {
106 theUnion = theUnion.union( new TokenTupleSet( e.increaseArity() ) ).makeCanonical();
108 theUnion = theUnion.union( new TokenTupleSet( e ) ).makeCanonical();
112 Iterator itrOelement = o.iterator();
113 while( itrOelement.hasNext() ) {
114 TokenTuple e = (TokenTuple) itrOelement.next();
116 if( !theUnion.containsToken( e.getToken() ) ) {
117 theUnion = theUnion.union( new TokenTupleSet( e ) ).makeCanonical();
121 if( !theUnion.isEmpty() ) {
122 ctsOut = ctsOut.union(
123 new ChangeTupleSet( new ChangeTuple( o, theUnion ) )
129 return ctsOut.makeCanonical();
133 public boolean equals( Object o ) {
134 if( !(o instanceof ReachabilitySet) ) {
138 ReachabilitySet rs = (ReachabilitySet) o;
139 return possibleReachabilities.equals( rs.possibleReachabilities );
142 public int hashCode() {
143 return possibleReachabilities.hashCode();
147 public String toStringEscapeNewline() {
150 Iterator i = this.iterator();
151 while( i.hasNext() ) {
152 if( possibleReachabilities.size() > 1 ) {
158 if( possibleReachabilities.size() > 1 ) {
167 public String toString() {
170 Iterator i = this.iterator();
171 while( i.hasNext() ) {
172 if( possibleReachabilities.size() > 1 ) {
178 if( possibleReachabilities.size() > 1 ) {