org.codehaus.spice.salt.lang
Class EnumSet

java.lang.Object
  |
  +--org.codehaus.spice.salt.lang.EnumSet

public final class EnumSet
extends Object

A Utility class for managing a set of name-integer constants.

The Class has factory methods that will allow the user to scan a Class and find all integer constants and place them in an EnumSet. The constants are placed into the EnumSet based on the name of the field that declared constant. The createFrom(Class,String) factory method accepts a Regular Expression which is used to match thje constants to place in the set and to extract the name for the constant. The first "group" in the Regex is the name of the constant. Consider the example;

 public class ShaderRenderer
 {
    public static final int CLIP_NOCLIP     = 0;
    public static final int CLIP_BACK       = 1;
    public static final int CLIP_FRONT      = 2;
    public static final EnumSet CLIP_ENUMS  =
              EnumSet.createFrom( ShaderRenderer.class, "CLIP_(.*)" );

    public static final int FUNC_SIN        = 0;
    public static final int FUNC_COS        = 1;
    public static final int FUNC_MOD        = 2;
    public static final EnumSet FUNC_ENUMS  =
              EnumSet.createFrom( ShaderRenderer.class, "FUNC_(.*)" );
 }
 

The above example will create two EnumSets for the class. The first EnumSet includes the enums {NOCLIP=0,BACK=1,FRONT=2} and the seconds includes the enums {SIN=0,COS=1,MOD=2}

Author:
Peter Donald

Constructor Summary
EnumSet()
           
 
Method Summary
static EnumSet createFrom(Class clazz)
          Create an EnumSet for specified Class including all integer constants.
static EnumSet createFrom(Class clazz, String patternString)
          Create an EnumSet for specified Class including all integer constants that match specified pattern.
static EnumSet createFrom(Class clazz, String patternString, boolean deep)
          Create an EnumSet for specified Class including all integer constants that match specified pattern and scanning superclass if deep is true.
 int getCodeFor(String name)
          Return the code for specified name.
 Set getCodes()
          Return a read-only set of codes in the EnumSet.
 String getNameFor(int code)
          Return the name for specified code.
 Set getNames()
          Return a read-only set of names in the EnumSet.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

EnumSet

public EnumSet()
Method Detail

getNames

public final Set getNames()
Return a read-only set of names in the EnumSet.

Returns:
a read-only set of names in the EnumSet.

getCodes

public final Set getCodes()
Return a read-only set of codes in the EnumSet.

Returns:
a read-only set of codes in the EnumSet.

getNameFor

public final String getNameFor(int code)
Return the name for specified code.

Parameters:
code - the code to lookup.
Returns:
the name for specified code.
Throws:
IllegalArgumentException - if code is not in the EnumSet.

getCodeFor

public final int getCodeFor(String name)
Return the code for specified name.

Parameters:
name - the name to lookup.
Returns:
the code for specified name.
Throws:
IllegalArgumentException - if name is not in the EnumSet.

createFrom

public static EnumSet createFrom(Class clazz)
Create an EnumSet for specified Class including all integer constants. A shortcut for createFrom( clazz, "(.*)" ).

Parameters:
clazz - the class to extract constants from
Returns:
the created EnumSet

createFrom

public static EnumSet createFrom(Class clazz,
                                 String patternString)
Create an EnumSet for specified Class including all integer constants that match specified pattern. A shortcut for createFrom( clazz, "(.*)", true ).

Parameters:
clazz - the class to extract constants from
patternString - the pattern that constants must match
Returns:
the created EnumSet

createFrom

public static EnumSet createFrom(Class clazz,
                                 String patternString,
                                 boolean deep)
Create an EnumSet for specified Class including all integer constants that match specified pattern and scanning superclass if deep is true.

Parameters:
clazz - the class to extract constants from
patternString - the pattern that constants must match
deep - if true will scan all parent classes to locate constants
Returns:
the created EnumSet


Copyright © 1999-2003 Codehaus. All Rights Reserved.