Web Site

org.codehaus.janino.util.enumerator
Class EnumeratorSet

java.lang.Object
  extended byorg.codehaus.janino.util.enumerator.EnumeratorSet
Direct Known Subclasses:
DebuggingInformation

public abstract class EnumeratorSet
extends Object

A class that represents a set of enumerated values.

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. Both is done through reflection.

Use this class as follows:

 public class Food extends EnumeratorSet {
     public static final Food BEEF    = new Food(1);
     public static final Food LETTUCE = new Food(2);
     public static final Food BREAD   = new Food(4);

     public static final Food NONE    = new Food(0);
     public static final Food ALL     = new Food(7);

     public Food(String s) throws EnumeratorFormatException { super(s); }
     public Food add(Food that) { return new Food(super.add(that)); }
     public Food remove(Food that) { return new Food(super.remove(that)); }

     private Food(int values) { super(values); }
 }
 


Constructor Summary
protected EnumeratorSet(int values)
          Initialize the enumerator to the given OR'ed set of values.
protected EnumeratorSet(String s)
          Initialize an EnumeratorSet from a string.
protected EnumeratorSet(String s, String delimiter)
          Initialize an EnumeratorSet from a string.
 
Method Summary
protected  int add(EnumeratorSet that)
          Add to the object's values the given OR'ed set of values.
 boolean contains(EnumeratorSet that)
          Check if the object contains any of the given values.
 boolean containsAllOf(EnumeratorSet that)
          Check if the object contain all of the given values.
 boolean containsAnyOf(EnumeratorSet that)
          Check if the object contain any of the given values.
 boolean equals(Object that)
          Check the values' identity.
 int hashCode()
           
protected  int remove(EnumeratorSet that)
          Remove an OR'ed set of values from the object's values.
 String toString()
          Convert an EnumeratorSet to a clear-text string.
 String toString(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

protected EnumeratorSet(int values)
Initialize the enumerator to the given OR'ed set of values.


EnumeratorSet

protected EnumeratorSet(String s)
                 throws EnumeratorFormatException
Initialize an EnumeratorSet from a string.

Equivalent to EnumeratorSet(s, ",").


EnumeratorSet

protected EnumeratorSet(String s,
                        String delimiter)
                 throws EnumeratorFormatException
Initialize an EnumeratorSet from a string.

The given string is parsed into tokens; each token is converted into a value by looking at the class's public static final fields which have the same type as the class itself. The values are OR'ed together.

Throws:
EnumeratorFormatException - if a token cannot be identified
Method Detail

add

protected int add(EnumeratorSet that)
Add to the object's values the given OR'ed set of values.


remove

protected int remove(EnumeratorSet that)
Remove an OR'ed set of values from the object's values.


contains

public boolean contains(EnumeratorSet that)
Check if the object contains any of the given values.


containsAnyOf

public boolean containsAnyOf(EnumeratorSet that)
Check if the object contain any of the given values.


containsAllOf

public boolean containsAllOf(EnumeratorSet that)
Check if the object contain all of the given values.


equals

public boolean equals(Object that)
Check the values' identity.


hashCode

public int hashCode()

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.

Examine the object through reflection for public static final fields that have the same type as this object, and collect the names of all fields who's values are contained in the object's values. Return the names of these fields, concatenated with the given delimiter.


Web Site