1 package Analysis.Disjoint;
8 ///////////////////////////////////////////
10 // This class is an immutable Canonical, so
12 // 0) construct them with a factory pattern
13 // to ensure only canonical versions escape
15 // 1) any operation that modifies a Canonical
16 // is a static method in the Canonical class
18 // 2) operations that just read this object
19 // should be defined here
21 // 3) every Canonical subclass hashCode should
22 // throw an error if the hash ever changes
24 ///////////////////////////////////////////
26 // a reach set is a set of reach states
28 public class ReachSet extends Canonical {
30 protected HashSet<ReachState> reachStates;
33 public static ReachSet factory() {
34 ReachSet out = new ReachSet();
35 out = (ReachSet) Canonical.makeCanonical( out );
39 public static ReachSet factory( ReachState state ) {
41 assert state.isCanonical();
42 ReachSet out = new ReachSet();
43 out.reachStates.add( state );
44 out = (ReachSet) Canonical.makeCanonical( out );
48 protected ReachSet() {
49 reachStates = new HashSet<ReachState>();
53 public Iterator<ReachState> iterator() {
54 return reachStates.iterator();
58 return reachStates.size();
61 public boolean isEmpty() {
62 return reachStates.isEmpty();
65 public boolean contains( ReachState state ) {
67 return reachStates.contains( state );
71 public boolean containsWithZeroes( ReachState state ) {
74 if( reachStates.contains( state ) ) {
78 Iterator<ReachState> itr = iterator();
79 while( itr.hasNext() ) {
80 ReachState stateThis = itr.next();
81 if( stateThis.containsWithZeroes( state ) ) {
90 public boolean containsSuperSet( ReachState state ) {
91 return containsSuperSet( state, false );
94 public boolean containsStrictSuperSet( ReachState state ) {
95 return containsSuperSet( state, true );
98 public boolean containsSuperSet( ReachState state,
100 assert state != null;
102 if( !strict && reachStates.contains( state ) ) {
106 Iterator<ReachState> itr = iterator();
107 while( itr.hasNext() ) {
108 ReachState stateThis = itr.next();
110 if( !state.equals( stateThis ) &&
111 state.isSubset( stateThis ) ) {
115 if( state.isSubset( stateThis ) ) {
125 public boolean containsTuple( ReachTuple rt ) {
126 Iterator<ReachState> itr = iterator();
127 while( itr.hasNext() ) {
128 ReachState state = itr.next();
129 if( state.containsTuple( rt ) ) {
136 public boolean containsStateWithBoth( ReachTuple rt1,
138 Iterator<ReachState> itr = iterator();
139 while( itr.hasNext() ) {
140 ReachState state = itr.next();
141 if( state.containsTuple( rt1 ) &&
142 state.containsTuple( rt2 ) ) {
151 public boolean equals( Object o ) {
156 if( !(o instanceof ReachSet) ) {
160 ReachSet rs = (ReachSet) o;
161 return reachStates.equals( rs.reachStates );
165 public int hashCodeSpecific() {
166 return reachStates.hashCode();
170 public String toStringEscNewline( boolean hideSubsetReachability ) {
173 Iterator<ReachState> i = this.iterator();
174 while( i.hasNext() ) {
175 ReachState state = i.next();
177 // skip this if there is a superset already
178 if( hideSubsetReachability &&
179 containsStrictSuperSet( state ) ) {
194 public String toString() {
195 return toString( false );
198 public String toString( boolean hideSubsetReachability ) {
201 Iterator<ReachState> i = this.iterator();
202 while( i.hasNext() ) {
203 ReachState state = i.next();
205 // skip this if there is a superset already
206 if( hideSubsetReachability &&
207 containsStrictSuperSet( state ) ) {