edu.umd.cs.findbugs.ba.obl
Class StateSet

java.lang.Object
  extended by edu.umd.cs.findbugs.ba.obl.StateSet

public class StateSet
extends java.lang.Object

A dataflow fact used in ObligationAnalysis. It is a set of State objects, plus the additional capability to represent top and bottom elements.

Invariant: no StateSet may contain more than one State with the same ObligationSet.

See Weimer and Necula, Finding and preventing run-time error handling mistakes, OOPSLA 2004.

Author:
David Hovemeyer

Nested Class Summary
static interface StateSet.StateCallback
           
 
Constructor Summary
StateSet()
           
 
Method Summary
 void addObligation(Obligation obligation)
          Add an obligation to every State in the StateSet.
 void applyToAllStates(StateSet.StateCallback callback)
          Apply a callback to all States in the StateSet.
 void applyToAllStatesAndUpdateMap(StateSet.StateCallback callback, java.util.Map<ObligationSet,State> updatedStateMap)
          Apply a callback to all States and replace the ObligationSet -> State map with the one given (which is assumed to be updated by the callback.)
 void copyFrom(StateSet other)
          Make this StateSet an exact copy of the given StateSet.
 java.util.Map<ObligationSet,State> createEmptyMap()
          Return a newly allocated Map of ObligationSet to State that may be passed to applyToAllStatesAndUpdateMap().
 void deleteObligation(Obligation obligation)
          Remove an Obligation from every State in the StateSet.
 StateSet duplicate()
          Return an exact deep copy of this StateSet.
 boolean equals(java.lang.Object o)
           
 State getStateWithObligationSet(ObligationSet obligationSet)
          Get the State which has the given ObligationSet.
 int hashCode()
           
 void initEntryFact(ObligationFactory factory)
          Initialize this object as the entry fact for a method: a single state with empty obligation set and path.
 boolean isBottom()
           
 boolean isTop()
           
 boolean isValid()
           
 void setBottom()
           
 void setTop()
           
 java.util.Iterator<State> stateIterator()
          Return an Iterator over the States in the StateSet.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

StateSet

public StateSet()
Method Detail

setTop

public void setTop()

isTop

public boolean isTop()

setBottom

public void setBottom()

isBottom

public boolean isBottom()

isValid

public boolean isValid()

stateIterator

public java.util.Iterator<State> stateIterator()
Return an Iterator over the States in the StateSet.

Returns:
an Iterator over the States in the StateSet

getStateWithObligationSet

public State getStateWithObligationSet(ObligationSet obligationSet)
Get the State which has the given ObligationSet. Returns null if there is no such state.

Parameters:
obligationSet - we want to get the State with this ObligationSet
Returns:
the State with the given ObligationSet, or null if there is no such State

initEntryFact

public void initEntryFact(ObligationFactory factory)
Initialize this object as the entry fact for a method: a single state with empty obligation set and path.

Parameters:
factory - the ObligationFactory used for the analysis

copyFrom

public void copyFrom(StateSet other)
Make this StateSet an exact copy of the given StateSet.

Parameters:
other - a StateSet; this StateSet will be made identical to it

duplicate

public StateSet duplicate()
Return an exact deep copy of this StateSet.

Returns:
an exact deep copy of this StateSet

addObligation

public void addObligation(Obligation obligation)
Add an obligation to every State in the StateSet.

Parameters:
obligation - the obligation to add

deleteObligation

public void deleteObligation(Obligation obligation)
                      throws NonexistentObligationException
Remove an Obligation from every State in the StateSet.

Parameters:
obligation - the obligation to remove
Throws:
NonexistentObligationException

equals

public boolean equals(java.lang.Object o)
Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

createEmptyMap

public java.util.Map<ObligationSet,State> createEmptyMap()
Return a newly allocated Map of ObligationSet to State that may be passed to applyToAllStatesAndUpdateMap().


applyToAllStatesAndUpdateMap

public void applyToAllStatesAndUpdateMap(StateSet.StateCallback callback,
                                         java.util.Map<ObligationSet,State> updatedStateMap)
                                  throws NonexistentObligationException
Apply a callback to all States and replace the ObligationSet -> State map with the one given (which is assumed to be updated by the callback.)

Parameters:
callback - the callback
updatedStateMap - updated map of ObligationSets to States
Throws:
NonexistentObligationException

applyToAllStates

public void applyToAllStates(StateSet.StateCallback callback)
                      throws NonexistentObligationException
Apply a callback to all States in the StateSet.

Parameters:
callback -
Throws:
NonexistentObligationException