Web Site

org.codehaus.janino.util.enumerator
Class EnumeratorSet

java.lang.Object
  extended by org.codehaus.janino.util.enumerator.EnumeratorSet

public class EnumeratorSet
extends java.lang.Object

A class that represents an immutable set of Enumerators.

Its main features are its constructor, which initializes the object from a clear-text string, and its toString() method, which reconstructs the clear text values.

Sample code can be found in the documentation of Enumerator.


Constructor Summary
EnumeratorSet(java.lang.Class enumeratorClass)
          Construct an empty set for values of the given Enumerator-derived type.
EnumeratorSet(java.lang.Class enumeratorClass, boolean full)
          Construct a set for values of the given Enumerator-derived type.
EnumeratorSet(java.lang.Class enumeratorClass, java.lang.String s)
          Construct a set for values of the given Enumerator-derived type and initialize it from a string.
EnumeratorSet(java.lang.Class enumeratorClass, java.lang.String s, java.lang.String delimiter)
          Construct a set for values of the given Enumerator-derived type and initialize it from a string.
EnumeratorSet(EnumeratorSet that)
          Construct a copy of the given set.
 
Method Summary
 EnumeratorSet add(Enumerator value)
          Add the given value to the set.
 EnumeratorSet add(EnumeratorSet that)
          Add the values of the given set to this set.
 boolean contains(Enumerator value)
          Check whether this set contains the given value
 boolean containsAllOf(EnumeratorSet that)
          Check if this set contains all values of the given set.
 boolean containsAnyOf(EnumeratorSet that)
          Check if this set contains any of the values of the given set.
 boolean equals(java.lang.Object that)
          Check the values' identity.
 int hashCode()
           
 EnumeratorSet remove(Enumerator value)
          If this EnumeratorSet contains the given value, return an EnumeratorSet that lacks the value.
 EnumeratorSet remove(EnumeratorSet that)
          Return this EnumeratorSet less that EnumeratorSet.
 EnumeratorSet setName(java.lang.String optionalName)
          An EnumeratorSet can optionally be assigned a name, which is used by toString().
 java.lang.String toString()
          Convert an EnumeratorSet to a clear-text string.
 java.lang.String toString(java.lang.String delimiter)
          Convert an EnumeratorSet into a clear-text string.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

EnumeratorSet

public EnumeratorSet(java.lang.Class enumeratorClass)
Construct an empty set for values of the given Enumerator-derived type.


EnumeratorSet

public EnumeratorSet(java.lang.Class enumeratorClass,
                     boolean full)
Construct a set for values of the given Enumerator-derived type. If the full flag is true, all possible values are added to the set.


EnumeratorSet

public EnumeratorSet(java.lang.Class enumeratorClass,
                     java.lang.String s)
              throws EnumeratorFormatException
Construct a set for values of the given Enumerator-derived type and initialize it from a string.

Equivalent to EnumeratorSet(enumeratorClass, s, ",").

Throws:
EnumeratorFormatException

EnumeratorSet

public EnumeratorSet(java.lang.Class enumeratorClass,
                     java.lang.String s,
                     java.lang.String delimiter)
              throws EnumeratorFormatException
Construct a set for values of the given Enumerator-derived type and initialize it from a string.

The given string is parsed into tokens; each token is converted into a value as Enumerator.fromString(String, Class) does and added to this set. Named EnumeratorSets declared in the enumeratorClass are also recognized and added. If the string names exactly one of those EnumeratorSets declared in the enumeratorClass, then the resulting set inherits the name of theat EnumeratorSet.

Throws:
EnumeratorFormatException - if a token cannot be identified

EnumeratorSet

public EnumeratorSet(EnumeratorSet that)
Construct a copy of the given set.

Method Detail

add

public EnumeratorSet add(Enumerator value)
Add the given value to the set.

Throws:
EnumeratorSetTypeException - if this set was constructed for a different Enumerator-derived type

add

public EnumeratorSet add(EnumeratorSet that)
Add the values of the given set to this set.

Throws:
EnumeratorSetTypeException - if this set was constructed for a different Enumerator-derived type

remove

public EnumeratorSet remove(Enumerator value)
If this EnumeratorSet contains the given value, return an EnumeratorSet that lacks the value. Otherwise, return this EnumeratorSet.

Returns:
the reduced set
Throws:
EnumeratorSetTypeException - if this set was constructed for a different Enumerator-derived type

remove

public EnumeratorSet remove(EnumeratorSet that)
Return this EnumeratorSet less that EnumeratorSet.

Returns:
the reduced set
Throws:
EnumeratorSetTypeException - if this set was constructed for a different Enumerator-derived type

contains

public boolean contains(Enumerator value)
Check whether this set contains the given value

Throws:
EnumeratorSetTypeException - if this set was constructed for a different Enumerator-derived type

containsAnyOf

public boolean containsAnyOf(EnumeratorSet that)
Check if this set contains any of the values of the given set.

Returns false if either of the two sets is empty.

Throws:
EnumeratorSetTypeException - if this set was constructed for a different Enumerator-derived type

containsAllOf

public boolean containsAllOf(EnumeratorSet that)
Check if this set contains all values of the given set.

Throws:
EnumeratorSetTypeException - if this set was constructed for a different Enumerator-derived type

setName

public EnumeratorSet setName(java.lang.String optionalName)
An EnumeratorSet can optionally be assigned a name, which is used by toString().

Returns:
this object

equals

public boolean equals(java.lang.Object that)
Check the values' identity. Notice that the objects' names (see setName(String) is not considered.

Overrides:
equals in class java.lang.Object

hashCode

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

toString

public java.lang.String toString()
Convert an EnumeratorSet to a clear-text string.

Identical with toString(",").

Overrides:
toString in class java.lang.Object

toString

public java.lang.String toString(java.lang.String delimiter)
Convert an EnumeratorSet into a clear-text string.

If this EnumeratorSet has a name (see setName(String), then this name is returned.

Otherwise, if this EnumeratorSet is empty, an empty String is returned.

Otherwise, the values' names are concatenated, separated by the given delimiter, and returned.


Web Site