|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.codehaus.spice.salt.lang.EnumSet
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}
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 |
public EnumSet()
Method Detail |
public final Set getNames()
public final Set getCodes()
public final String getNameFor(int code)
code
- the code to lookup.
IllegalArgumentException
- if code is not in the EnumSet.public final int getCodeFor(String name)
name
- the name to lookup.
IllegalArgumentException
- if name is not in the EnumSet.public static EnumSet createFrom(Class clazz)
clazz
- the class to extract constants from
public static EnumSet createFrom(Class clazz, String patternString)
clazz
- the class to extract constants frompatternString
- the pattern that constants must match
public static EnumSet createFrom(Class clazz, String patternString, boolean deep)
clazz
- the class to extract constants frompatternString
- the pattern that constants must matchdeep
- if true will scan all parent classes to locate constants
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |