gumbo.util.state
Class States.ImmutableStateSet

java.lang.Object
  |
  +--gumbo.util.GumboCollections.ImmutableCollection
        |
        +--gumbo.util.state.States.ImmutableStateSet
All Implemented Interfaces:
java.util.Collection, java.util.Set, StateSet
Direct Known Subclasses:
Interactors.ImmutableInteractorState
Enclosing class:
States

public static class States.ImmutableStateSet
extends GumboCollections.ImmutableCollection
implements StateSet

Immutable wrapper for a target state set. Identity (hashCode(), equals()) forwards to the target object, which is possible because target identity is based on contents.


Constructor Summary
States.ImmutableStateSet(StateSet target)
           
 
Method Summary
 boolean change(java.lang.Object remove, java.lang.Object add)
          Removes then adds the specified state flags, as allowed by the state policy.
 boolean change(StateSet changes)
          Performs a "masked change" by imposing a target's state set changes (deltas) on this state set, as allowed by the state policy, with the union of the target's old and new states acting as the mask.
 boolean changeAll(java.util.Collection remove, java.util.Collection add)
          Removes then adds the specified state flags, as allowed by the state policy.
 java.util.Set getOldState()
          Gets a singleton immutable view of this set's old state value, which was the state value prior to the last transit, or the same state value as the current one after a reset.
 StatePolicy getStatePolicy()
          Gets the state policy for this state set, which assures that the state value contains valid combinations and types of state flags following state initialization and transition.
 StateSet getStateSet()
          Gets a singleton immutable view of this set, which is the current state value, resulting from the last reset or transit.
 boolean reset(java.util.Collection state)
          Resets (re-initializes) this state set's value to a new state, as allowed by the state policy.
 boolean set(java.util.Collection state)
          Sets this state set's value to a new state, as allowed by the state policy.
 boolean transit(java.util.Collection input)
          Causes this state set's value to transit from one state to another (possibly with no change in value) according to an input value.
 
Methods inherited from class gumbo.util.GumboCollections.ImmutableCollection
add, addAll, clear, contains, containsAll, equals, hashCode, isEmpty, iterator, remove, removeAll, retainAll, size, toArray, toArray, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Set
add, addAll, clear, contains, containsAll, equals, hashCode, isEmpty, iterator, remove, removeAll, retainAll, size, toArray, toArray
 

Constructor Detail

States.ImmutableStateSet

public States.ImmutableStateSet(StateSet target)
Method Detail

getStatePolicy

public StatePolicy getStatePolicy()
Description copied from interface: StateSet
Gets the state policy for this state set, which assures that the state value contains valid combinations and types of state flags following state initialization and transition.

Specified by:
getStatePolicy in interface StateSet
Returns:
The policy. Null if none.

reset

public boolean reset(java.util.Collection state)
Description copied from interface: StateSet
Resets (re-initializes) this state set's value to a new state, as allowed by the state policy. Unlike other mutators, the old state will be left equal to the new state. If there is no policy, this state set will be effectively cleared and the new state added. If reset is not allowed, should throw UnsupportedOperationException.

Specified by:
reset in interface StateSet
Parameters:
state - The new state value (Object). Never null.
Returns:
True if the contents of this set changed (same as for Set.add() and Set.remove()).

set

public boolean set(java.util.Collection state)
Description copied from interface: StateSet
Sets this state set's value to a new state, as allowed by the state policy. Effectively a clear() then addAll(), as a single operation.

Specified by:
set in interface StateSet
Parameters:
state - The new state value (Object). Never null.
Returns:
True if the contents of this set changed (same as for Set.add() and Set.remove()).

change

public boolean change(StateSet changes)
Description copied from interface: StateSet
Performs a "masked change" by imposing a target's state set changes (deltas) on this state set, as allowed by the state policy, with the union of the target's old and new states acting as the mask. Effectively a removeAll() of the target's old state, then an addAll() of its new state, as a single operation.

Specified by:
change in interface StateSet
Parameters:
changes - The state value changes. Never null.
Returns:
True if the contents of this set changed (same as for Set.add() and Set.remove()).

change

public boolean change(java.lang.Object remove,
                      java.lang.Object add)
Description copied from interface: StateSet
Removes then adds the specified state flags, as allowed by the state policy. Effectively a remove() then add(), as a single operation.

Specified by:
change in interface StateSet
Parameters:
remove - Flag to be removed. None if null.
add - Flag to be added. None if null.
Returns:
True if the contents of this set changed (same as for Set.add() and Set.remove()).

changeAll

public boolean changeAll(java.util.Collection remove,
                         java.util.Collection add)
Description copied from interface: StateSet
Removes then adds the specified state flags, as allowed by the state policy. Effectively a removeAll() then addAll(), as a single operation.

Specified by:
changeAll in interface StateSet
Parameters:
remove - Flags to be removed. Never null.
add - Flags to be added. Never null.
Returns:
True if the contents of this set changed (same as for Set.add() and Set.remove()).

transit

public boolean transit(java.util.Collection input)
Description copied from interface: StateSet
Causes this state set's value to transit from one state to another (possibly with no change in value) according to an input value. If there is no policy nothing happens.

Specified by:
transit in interface StateSet
Parameters:
input - The input value (Object). Never null.
Returns:
True if the contents of this set changed (same as for Set.add() and Set.remove()).

getOldState

public java.util.Set getOldState()
Description copied from interface: StateSet
Gets a singleton immutable view of this set's old state value, which was the state value prior to the last transit, or the same state value as the current one after a reset.

Specified by:
getOldState in interface StateSet
Returns:
The view (Object). Never null.

getStateSet

public StateSet getStateSet()
Description copied from interface: StateSet
Gets a singleton immutable view of this set, which is the current state value, resulting from the last reset or transit.

Specified by:
getStateSet in interface StateSet
Returns:
The view (Object). Never null.