gumbo.util.state
Class StateFlags

java.lang.Object
  |
  +--gumbo.util.state.StateFlags

public final class StateFlags
extends java.lang.Object

Constants and utilities related to the use of objects in collections as state flags.

In the "generic" state flag utilities, note that the target of the action described by the method name is always the first parameter. Also, the parameter order for new and old states is newState followed by oldState, which is consistent throughout the state classes.

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

Method Summary
static boolean added(java.lang.Object flag, java.util.Collection newState, java.util.Collection oldState)
          Returns true if the input flag was newly added.
static boolean addedAll(java.util.Collection flags, java.util.Collection newState, java.util.Collection oldState)
          Returns true if all input flags were newly added.
static boolean addedAny(java.util.Collection flags, java.util.Collection newState, java.util.Collection oldState)
          Returns true if any input flag was newly added.
static int addedCount(java.util.Set flags, java.util.Collection newState, java.util.Collection oldState)
          Returns the number of input flags newly added.
static boolean addedNone(java.util.Collection newState, java.util.Collection oldState)
          Returns true if no flags were added.
static boolean changed(java.lang.Object flag, java.util.Collection newState, java.util.Collection oldState)
          Returns true if the input flag was newly changed.
static boolean changedAll(java.util.Collection flags, java.util.Collection newState, java.util.Collection oldState)
          Returns true if all input flags were newly changed.
static boolean changedAny(java.util.Collection flags, java.util.Collection newState, java.util.Collection oldState)
          Returns true if any input flag was newly changed.
static int changedCount(java.util.Set flags, java.util.Collection newState, java.util.Collection oldState)
          Returns the number of input flags newly changed.
static boolean changedNone(java.util.Collection newState, java.util.Collection oldState)
          Returns true if no flags were changed.
static java.util.Collection collectFlags(java.util.Collection elements, java.util.Collection retVal)
          Converts a collection of "state elements" into an equivalent collection of state flags.
static java.util.Set collectFlags(java.lang.Object[] elements)
          Converts an array of "state elements" into an equivalent collection of state flags.
static java.util.Set collectFlagsImm(java.lang.Object[] elements)
          Converts an array of "state elements" into an equivalent immutable collection of state flags.
static java.util.Set flagObjects(java.util.Collection flags, java.util.Set retVal)
          Gets the objects in the object flags in a group of flags.
static java.util.Set flagsAdded(java.util.Collection newState, java.util.Collection oldState, java.util.Set retVal)
          Returns the state flag objects that were added.
static java.util.Set flagsChanged(java.util.Collection newState, java.util.Collection oldState, java.util.Set retVal)
          Returns the state flag objects that were changed.
static java.util.Set flagsRemoved(java.util.Collection newState, java.util.Collection oldState, java.util.Set retVal)
          Returns the state flag objects that were removed.
static java.util.Set flagTypes(java.util.Collection flags, java.util.Set retVal)
          Gets the types in the type flags in a group of flags.
static boolean has(java.lang.Object flag, java.util.Collection state)
          Returns true if the input flag is set in state.
static boolean hasAll(java.util.Collection flags, java.util.Collection state)
          Returns true if all of the input flags are set in state.
static boolean hasAny(java.util.Collection flags, java.util.Collection state)
          Returns true if any of the input flags are set in state.
static int hasCount(java.util.Set flags, java.util.Collection state)
          Returns the number of input flags set in state.
static boolean hasNone(java.util.Collection state)
          Returns true if the state has no flags set (is clear).
static boolean removed(java.lang.Object flag, java.util.Collection newState, java.util.Collection oldState)
          Returns true if the input flag was newly removed.
static boolean removedAll(java.util.Collection flags, java.util.Collection newState, java.util.Collection oldState)
          Returns true if all input flags were newly removed.
static boolean removedAny(java.util.Collection flags, java.util.Collection newState, java.util.Collection oldState)
          Returns true if any input flag was newly removed.
static int removedCount(java.util.Set flags, java.util.Collection newState, java.util.Collection oldState)
          Returns the number of input flags newly removed.
static boolean removedNone(java.util.Collection newState, java.util.Collection oldState)
          Returns true if no flags were removed.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

collectFlags

public static java.util.Set collectFlags(java.lang.Object[] elements)
Converts an array of "state elements" into an equivalent collection of state flags. A state element is defined as a StateFlag or a Collection of state elements. Throws an exception if any other object type is found.

Parameters:
elements - State elements (StateFlag or Collection). Never null.
Returns:
New set of state flags (StateFlag). Never null.
Throws:
java.lang.IllegalArgumentException - A state element must be a StateFlag or Collection.

collectFlagsImm

public static java.util.Set collectFlagsImm(java.lang.Object[] elements)
Converts an array of "state elements" into an equivalent immutable collection of state flags. See collectFlags(Object[]).


collectFlags

public static java.util.Collection collectFlags(java.util.Collection elements,
                                                java.util.Collection retVal)
Converts a collection of "state elements" into an equivalent collection of state flags. A state element is defined as a StateFlag or a Collection of state elements. Throws an exception if any other object type is found.

Parameters:
elements - State elements (StateFlag or Collection). Clear if null.
retVal - Return value object. State flags (StateFlag). Never null.
Returns:
Reference to retVal. Never null.
Throws:
java.lang.IllegalArgumentException - A state element must be a StateFlag or Collection.

flagObjects

public static java.util.Set flagObjects(java.util.Collection flags,
                                        java.util.Set retVal)
Gets the objects in the object flags in a group of flags. If a flag is not an ObjectFlag it is ignored.

Parameters:
flags - State flags (Object). Clear if null.
retVal - Return value object. Type flag objects (Object). Never null.
Returns:
Reference to retVal. Never null.

flagTypes

public static java.util.Set flagTypes(java.util.Collection flags,
                                      java.util.Set retVal)
Gets the types in the type flags in a group of flags. If a flag is not a TypeFlag it is ignored.

Parameters:
flags - State flags (Object). Clear if null.
retVal - Return value object. Type flag types (Class). Never null.
Returns:
Reference to retVal. Never null.

flagsAdded

public static java.util.Set flagsAdded(java.util.Collection newState,
                                       java.util.Collection oldState,
                                       java.util.Set retVal)
Returns the state flag objects that were added.

Parameters:
newState - New state flags (Object). Clear if null.
oldState - Old state flags (Object). Clear if null.
retVal - Return value object. The added state flags (Object). Never null.
Returns:
Reference to retVal. Never null.

flagsRemoved

public static java.util.Set flagsRemoved(java.util.Collection newState,
                                         java.util.Collection oldState,
                                         java.util.Set retVal)
Returns the state flag objects that were removed.

Parameters:
newState - New state flags (Object). Clear if null.
oldState - Old state flags (Object). Clear if null.
retVal - Return value object. The removed state flags (Object). Never null.
Returns:
Reference to retVal. Never null.

flagsChanged

public static java.util.Set flagsChanged(java.util.Collection newState,
                                         java.util.Collection oldState,
                                         java.util.Set retVal)
Returns the state flag objects that were changed.

Parameters:
newState - New state flags (Object). Clear if null.
oldState - Old state flags (Object). Clear if null.
retVal - Return value object. The changed state flags (Object). Never null.
Returns:
Reference to retVal. Never null.

hasNone

public static boolean hasNone(java.util.Collection state)
Returns true if the state has no flags set (is clear).

Parameters:
state - State flags (Object). Clear if null.

has

public static boolean has(java.lang.Object flag,
                          java.util.Collection state)
Returns true if the input flag is set in state. False otherwise, or if flag is clear.

Parameters:
flag - Flag to test for. Clear if null.
state - State flags (Object). Clear if null.

hasAny

public static boolean hasAny(java.util.Collection flags,
                             java.util.Collection state)
Returns true if any of the input flags are set in state. False otherwise, or if flags is clear.

Parameters:
flags - Flags to test for. Clear if null.
state - State flags (Object). Clear if null.

hasAll

public static boolean hasAll(java.util.Collection flags,
                             java.util.Collection state)
Returns true if all of the input flags are set in state. False otherwise, or if flags is clear.

Parameters:
flags - Flags to test for. Clear if null.
state - State flags (Object). Clear if null.

hasCount

public static int hasCount(java.util.Set flags,
                           java.util.Collection state)
Returns the number of input flags set in state. False otherwise, or if flags is clear.

Parameters:
flags - Flags to test for. Clear if null.
state - State flags (Object). Clear if null.

addedNone

public static boolean addedNone(java.util.Collection newState,
                                java.util.Collection oldState)
Returns true if no flags were added. False otherwise.

Parameters:
newState - New state flags (Object). Clear if null.
oldState - Old state flags (Object). Clear if null.

added

public static boolean added(java.lang.Object flag,
                            java.util.Collection newState,
                            java.util.Collection oldState)
Returns true if the input flag was newly added. False otherwise, or if flag is clear.

Parameters:
flag - Flag to test for. Clear if null.
newState - New state flags (Object). Clear if null.
oldState - Old state flags (Object). Clear if null.

addedAny

public static boolean addedAny(java.util.Collection flags,
                               java.util.Collection newState,
                               java.util.Collection oldState)
Returns true if any input flag was newly added. False otherwise, or if flags is clear.

Parameters:
flags - Flags to test for. Clear if null.
newState - New state flags (Object). Clear if null.
oldState - Old state flags (Object). Clear if null.

addedAll

public static boolean addedAll(java.util.Collection flags,
                               java.util.Collection newState,
                               java.util.Collection oldState)
Returns true if all input flags were newly added. False otherwise, or if flags is clear.

Parameters:
flags - Flags to test for. Clear if null.
newState - New state flags (Object). Clear if null.
oldState - Old state flags (Object). Clear if null.

addedCount

public static int addedCount(java.util.Set flags,
                             java.util.Collection newState,
                             java.util.Collection oldState)
Returns the number of input flags newly added. False otherwise, or if flags is clear.

Parameters:
flags - Flags to test for. Clear if null.
newState - New state flags (Object). Clear if null.
oldState - Old state flags (Object). Clear if null.

removedNone

public static boolean removedNone(java.util.Collection newState,
                                  java.util.Collection oldState)
Returns true if no flags were removed. False otherwise.

Parameters:
newState - New state flags (Object). Clear if null.
oldState - Old state flags (Object). Clear if null.

removed

public static boolean removed(java.lang.Object flag,
                              java.util.Collection newState,
                              java.util.Collection oldState)
Returns true if the input flag was newly removed. False otherwise, or if flag is clear.

Parameters:
flag - Flag to test for. Clear if null.
newState - New state flags (Object). Clear if null.
oldState - Old state flags (Object). Clear if null.

removedAny

public static boolean removedAny(java.util.Collection flags,
                                 java.util.Collection newState,
                                 java.util.Collection oldState)
Returns true if any input flag was newly removed. False otherwise, or if flags is clear.

Parameters:
flags - Flags to test for. Clear if null.
newState - New state flags (Object). Clear if null.
oldState - Old state flags (Object). Clear if null.

removedAll

public static boolean removedAll(java.util.Collection flags,
                                 java.util.Collection newState,
                                 java.util.Collection oldState)
Returns true if all input flags were newly removed. False otherwise, or if flags is clear.

Parameters:
flags - Flags to test for. Clear if null.
newState - New state flags (Object). Clear if null.
oldState - Old state flags (Object). Clear if null.

removedCount

public static int removedCount(java.util.Set flags,
                               java.util.Collection newState,
                               java.util.Collection oldState)
Returns the number of input flags newly removed. False otherwise, or if flags is clear.

Parameters:
flags - Flags to test for. Clear if null.
newState - New state flags (Object). Clear if null.
oldState - Old state flags (Object). Clear if null.

changedNone

public static boolean changedNone(java.util.Collection newState,
                                  java.util.Collection oldState)
Returns true if no flags were changed. False otherwise.

Parameters:
newState - New state flags (Object). Clear if null.
oldState - Old state flags (Object). Clear if null.

changed

public static boolean changed(java.lang.Object flag,
                              java.util.Collection newState,
                              java.util.Collection oldState)
Returns true if the input flag was newly changed. False otherwise, or if flag is clear.

Parameters:
flag - Flag to test for. Clear if null.
newState - New state flags (Object). Clear if null.
oldState - Old state flags (Object). Clear if null.

changedAny

public static boolean changedAny(java.util.Collection flags,
                                 java.util.Collection newState,
                                 java.util.Collection oldState)
Returns true if any input flag was newly changed. False otherwise, or if flags is clear.

Parameters:
flags - Flags to test for. Clear if null.
newState - New state flags (Object). Clear if null.
oldState - Old state flags (Object). Clear if null.

changedAll

public static boolean changedAll(java.util.Collection flags,
                                 java.util.Collection newState,
                                 java.util.Collection oldState)
Returns true if all input flags were newly changed. False otherwise, or if flags is clear.

Parameters:
flags - Flags to test for. Clear if null.
newState - New state flags (Object). Clear if null.
oldState - Old state flags (Object). Clear if null.

changedCount

public static int changedCount(java.util.Set flags,
                               java.util.Collection newState,
                               java.util.Collection oldState)
Returns the number of input flags newly changed. False otherwise, or if flags is clear.

Parameters:
flags - Flags to test for. Clear if null.
newState - New state flags (Object). Clear if null.
oldState - Old state flags (Object). Clear if null.