Deprecated
since 6.1.
since 6.1 with no replacement; use an enum, map, or similar custom solution instead
asXXXX methods of this class
allow these constant values to be accessed via their string names.
Consider class Foo containing public static final int CONSTANT1 = 66;
An instance of this class wrapping Foo.class will return the constant value
of 66 from its asNumber 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.
| Modifier and Type | Class and Description |
|---|---|
| public static class | Constants.ConstantException
Exception thrown when the |
| Modifier and Type | Field and Description |
|---|---|
| private final String | className
The name of the introspected class. |
| private final Map | fieldCache
Map from String field name to object value. |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public Number | |
| public Object | |
| public String | |
| public final String | |
| protected final Map | |
| public Set | |
| public Set | Returns: the set of valuesthe name of the bean property propertyName)Return all names of the group of constants for the given bean property name. |
| public Set | Returns: the set of constant namessuffix of the constant names to search (may be nameSuffix)null)Return all names of the given group of constants. |
| public final int | |
| public Set | |
| public Set | Returns: the set of valuesthe name of the bean property propertyName)Return all values of the group of constants for the given bean property name. |
| public Set | Returns: the set of valuessuffix of the constant names to search (may be nameSuffix)null)Return all values of the given group of constants. |
| public String | Returns: the corresponding constant name prefixthe name of the bean property propertyName)Convert the given bean property name to a constant name prefix. |
| public String | |
| public String | Returns: the name of the constant fieldconstant value to look up value, String the name of the bean property propertyName)Look up the given value within the group of constants for the given bean property name. |
| public String | Returns: the name of the constant fieldconstant value to look up value, String suffix of the constant names to search (may be nameSuffix)null)Look up the given value within the given group of constants. |
| className | back to summary |
|---|---|
| private final String className The name of the introspected class. | |
| fieldCache | back to summary |
|---|---|
| private final Map<String, Object> fieldCache Map from String field name to object value. | |
| Constants | back to summary |
|---|---|
| public Constants(Class<?> clazz) Create a new Constants converter class wrapping the given class. All public static final variables will be exposed, whatever their type.
| |
| asNumber | back to summary |
|---|---|
| public Number asNumber(String code) throws ConstantException Return a constant value cast to a Number.
| |
| asObject | back to summary |
|---|---|
| public Object asObject(String code) throws ConstantException 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 that we're analyzing.
| |
| asString | back to summary |
|---|---|
| public String asString(String code) throws ConstantException Return a constant value as a String.
| |
| getClassName | back to summary |
|---|---|
| public final String getClassName() Return the name of the analyzed class. | |
| getFieldCache | back to summary |
|---|---|
| protected final Map Exposes the field cache to subclasses: a Map from String field name to object value. | |
| getNames | back to summary |
|---|---|
| public Set Return all names of the given group of constants. Note that this method assumes that constants are named
in accordance with the standard Java convention for constant
values (i.e. all uppercase). The supplied | |
| getNamesForProperty | back to summary |
|---|---|
| public Set Return all names of the group of constants for the given bean property name.
| |
| getNamesForSuffix | back to summary |
|---|---|
| public Set Return all names of the given group of constants. Note that this method assumes that constants are named
in accordance with the standard Java convention for constant
values (i.e. all uppercase). The supplied | |
| getSize | back to summary |
|---|---|
| public final int getSize() Return the number of constants exposed. | |
| getValues | back to summary |
|---|---|
| public Set Return all values of the given group of constants. Note that this method assumes that constants are named
in accordance with the standard Java convention for constant
values (i.e. all uppercase). The supplied | |
| getValuesForProperty | back to summary |
|---|---|
| public Set Return all values of the group of constants for the given bean property name.
| |
| getValuesForSuffix | back to summary |
|---|---|
| public Set Return all values of the given group of constants. Note that this method assumes that constants are named
in accordance with the standard Java convention for constant
values (i.e. all uppercase). The supplied | |
| propertyToConstantNamePrefix | back to summary |
|---|---|
| public String propertyToConstantNamePrefix(String propertyName) Convert the given bean property name to a constant name prefix. Uses a common naming idiom: turning all lower case characters to upper case, and prepending upper case characters with an underscore. Example: "imageSize" → "IMAGE_SIZE"
| |
| toCode | back to summary |
|---|---|
| public String toCode(Object value, String namePrefix) throws ConstantException Look up the given value within the given group of constants. Will return the first match.
| |
| toCodeForProperty | back to summary |
|---|---|
| public String toCodeForProperty(Object value, String propertyName) throws ConstantException Look up the given value within the group of constants for the given bean property name. Will return the first match.
| |
| toCodeForSuffix | back to summary |
|---|---|
| public String toCodeForSuffix(Object value, String nameSuffix) throws ConstantException Look up the given value within the given group of constants. Will return the first match.
| |
Constants class is asked for
an invalid constant name.
| Access | Constructor and Description |
|---|---|
| public | ConstantException(String
name of the class containing the constant definitions className, String invalid constant name field, String description of the problem message)Thrown when an invalid constant name is requested. |
| public | ConstantException(String
name of the class containing the constant definitions className, String prefix of the searched constant names namePrefix, Object the looked up constant value value)Thrown when an invalid constant value is looked up. |
| ConstantException | back to summary |
|---|---|
| public ConstantException(String className, String field, String message) Thrown when an invalid constant name is requested. | |
| ConstantException | back to summary |
|---|---|
| public ConstantException(String className, String namePrefix, Object value) Thrown when an invalid constant value is looked up. | |