facets.util
Class StringFlags

java.lang.Object
  extended by facets.util.StringFlags
All Implemented Interfaces:
java.io.Serializable

public final class StringFlags
extends java.lang.Object
implements java.io.Serializable

Container for flags defined using strings.

StringFlags offers an alternative to int constants to encode flags, being

StringFlags defines flags as set or reset by the presence or absence in its (immutable) contained string of string constants which should be created with newFlag(String). Collisions between partial or complete flag strings are avoided by prefixing each with the PREFIX constant and by numbering flags sequentially.

See Also:
Serialized Form

Field Summary
static StringFlags EMPTY
           
static java.lang.String FLAG_NONE
           
static java.lang.String PREFIX
           
 
Constructor Summary
StringFlags(java.lang.String flags)
          Unique constructor.
 
Method Summary
 StringFlags addFlag(java.lang.String flag)
          Add a flag.
 boolean includeFlag(java.lang.String flag)
          Do the flags set include this flagged string?
static java.lang.String newFlag(java.lang.String text)
          Converts text into an appropriate flag.
 StringFlags removeFlag(java.lang.String flag)
          Remove a flag.
 java.lang.String toString()
          Lists the current set of flags.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

PREFIX

public static final java.lang.String PREFIX
See Also:
Constant Field Values

FLAG_NONE

public static final java.lang.String FLAG_NONE

EMPTY

public static final StringFlags EMPTY
Constructor Detail

StringFlags

public StringFlags(java.lang.String flags)
Unique constructor.

Parameters:
flags - must a concatenation of strings created using newFlag(String).
Method Detail

newFlag

public static final java.lang.String newFlag(java.lang.String text)
Converts text into an appropriate flag.

The flag is guaranteed to be acceptable when passed to the constructor either on its own or concatenated with others created by this method. Such flags are therefore suitable as constants for use by application code.

Parameters:
text - may be any string not including the PREFIX constant beyond its start and will define a single flag

includeFlag

public boolean includeFlag(java.lang.String flag)
Do the flags set include this flagged string?

Parameters:
flag - must have been created with newFlag(String).

addFlag

public StringFlags addFlag(java.lang.String flag)
Add a flag.

Parameters:
flag - must have been created with newFlag(String).
Returns:
a StringFlags with flag appended to the flags if not already included

removeFlag

public StringFlags removeFlag(java.lang.String flag)
Remove a flag.

Parameters:
flag - must have been created with newFlag(String).
Returns:
a StringFlags with flag absent from the flags

toString

public java.lang.String toString()
Lists the current set of flags.

Overrides:
toString in class java.lang.Object