org.codehaus.janino.util.enumerator

Class EnumeratorSet

public class EnumeratorSet extends 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(Class enumeratorClass)
Construct an empty set for values of the given Enumerator-derived type.
EnumeratorSet(Class enumeratorClass, boolean full)
Construct a set for values of the given Enumerator-derived type.
EnumeratorSet(Class enumeratorClass, String s)
Construct a set for values of the given Enumerator-derived type and initialize it from a string.
EnumeratorSet(Class enumeratorClass, String s, 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
EnumeratorSetadd(Enumerator value)
Add the given value to the set.
EnumeratorSetadd(EnumeratorSet that)
Add the values of the given set to this set.
booleancontains(Enumerator value)
Check whether this set contains the given value
booleancontainsAllOf(EnumeratorSet that)
Check if this set contains all values of the given set.
booleancontainsAnyOf(EnumeratorSet that)
Check if this set contains any of the values of the given set.
booleanequals(Object that)
Check the values' identity.
inthashCode()
EnumeratorSetremove(Enumerator value)
If this EnumeratorSet contains the given value, return an EnumeratorSet that lacks the value.
EnumeratorSetremove(EnumeratorSet that)
Return this EnumeratorSet less that EnumeratorSet.
EnumeratorSetsetName(String optionalName)
An EnumeratorSet can optionally be assigned a name, which is used by toString.
StringtoString()
Convert an EnumeratorSet to a clear-text string.
StringtoString(String delimiter)
Convert an EnumeratorSet into a clear-text string.

Constructor Detail

EnumeratorSet

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

EnumeratorSet

public EnumeratorSet(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(Class enumeratorClass, String s)
Construct a set for values of the given Enumerator-derived type and initialize it from a string.

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

EnumeratorSet

public EnumeratorSet(Class enumeratorClass, String s, String delimiter)
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 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

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

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

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

equals

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

hashCode

public int hashCode()

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

setName

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

Returns: this object

toString

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

Identical with toString(",").

toString

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

If this EnumeratorSet has a name (see setName, 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.