|
[Deprecated API] | ||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | CURRENT API | |||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||
java.lang.Object | +--com.interface21.util.Constants
This class can be used to parse other classes containing constant definitions in public static final members. The asXXXX() methods of this class allow these constant values to be accessed via their string names.
Consider class Foo containing public final static int CONSTANT1 = 66; An instance of this class wrapping Foo.class will return the constant value of 66 from its asInt() method given the argument "CONSTANT1".
This class is ideal for use in PropertyEditors, enabling them to recognize the same names as the constants themselves, and freeing them from maintaining their own mapping.
TODO: add asBoolean, asDouble methods, keys method
| Constructor Summary | |
Constants(java.lang.Class clazz)
Create a new Constants converter class wrapping the given class. |
|
| Method Summary | |
int |
asInt(java.lang.String code)
Return a constant value cast to an int |
java.lang.Object |
asObject(java.lang.String code)
Parse the given string (upper or lower case accepted) and return the appropriate value if it's the name of a constant field in the class we're analysing. |
java.lang.String |
asString(java.lang.String code)
Return a constant value as a String |
int |
getSize()
Return the number of constants exposed |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
public Constants(java.lang.Class clazz)
clazz - class to analyze.| Method Detail |
public int getSize()
public int asInt(java.lang.String code)
throws ConstantException
code - name of the fieldConstantException - if the field name wasn't found or
if the type wasn't compatible with intasObject(java.lang.String)
public java.lang.String asString(java.lang.String code)
throws ConstantException
code - name of the fieldConstantException - if the field name wasn't foundasObject(java.lang.String)
public java.lang.Object asObject(java.lang.String code)
throws ConstantException
ConstantException - if there's no such field
|
[Deprecated API] | ||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | CURRENT API | |||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||