gumbo.util.state
Class AbstractStatePolicy

java.lang.Object
  |
  +--gumbo.util.state.AbstractStatePolicy
All Implemented Interfaces:
StatePolicy
Direct Known Subclasses:
InteractorPolicy

public abstract class AbstractStatePolicy
extends java.lang.Object
implements StatePolicy

Abstract base class for implementing state assurance policies, which only involve flag type and state value checking. Can also be used for state transition policies, involving an input value, but there is no direct support (have to override StatePolicy interface methods).

Version:
$Revision: 1.2 $
Author:
Jon Barrilleaux (jonb@jmbaai.com) of JMB and Associates Inc.

Constructor Summary
AbstractStatePolicy()
          Creates an instance.
 
Method Summary
 void checkInitialState(java.util.Set newState, java.util.Set oldState)
          The default implementation calls checkNewFlags(), then checkNewState(), with the new state value.
protected abstract  void checkNewFlags(java.util.Collection flags)
          Called by this policy to check new state value flag types.
protected abstract  void checkNewState(java.util.Set state)
          Called by this policy to check new state values (flag combinations).
 void checkTransitState(java.util.Collection input, java.util.Set newState, java.util.Set oldState)
          The default implementation calls checkNewFlags(), then checkNewState(), with the new state value.
 boolean isCompatible(StatePolicy policy)
          The default implementation always returns false.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractStatePolicy

public AbstractStatePolicy()
Creates an instance.

Method Detail

checkNewFlags

protected abstract void checkNewFlags(java.util.Collection flags)
Called by this policy to check new state value flag types. Modify the flags or throw an exception if a flag is invalid.


checkNewState

protected abstract void checkNewState(java.util.Set state)
Called by this policy to check new state values (flag combinations). Modify the value or throw an exception if the new state is invalid.

Parameters:
state - Reference to the new state (Object). Never null.

isCompatible

public boolean isCompatible(StatePolicy policy)
The default implementation always returns false.

Specified by:
isCompatible in interface StatePolicy
Parameters:
policy - Other state policy. None if null.
Returns:
True if the other policy (or the lack of a policy, if policy is null) is compatible with this one.

checkInitialState

public void checkInitialState(java.util.Set newState,
                              java.util.Set oldState)
The default implementation calls checkNewFlags(), then checkNewState(), with the new state value. oldState is ignored.

Specified by:
checkInitialState in interface StatePolicy
Parameters:
newState - Reference to the new target state value (Object). Never null. Contains the initial state value and, upon return, the modified initial value. Must be mutable and must NOT loop back to this method.
oldState - The old state value (Object). Never null.

checkTransitState

public void checkTransitState(java.util.Collection input,
                              java.util.Set newState,
                              java.util.Set oldState)
The default implementation calls checkNewFlags(), then checkNewState(), with the new state value. input and oldState are ignored.

Specified by:
checkTransitState in interface StatePolicy
Parameters:
input - Input value (Object). None if null (such as in a "set state" operation), which may be distinct from an empty value. If the same reference as state, may cause concurrent modification exceptions.
newState - Reference to the new target state value (Object). Contains the new state value and, upon return, the modified new value. Never null. Must be mutable and must NOT loop back to this method.
oldState - The old state value (Object). Never null.