public class EnumPresentationFactory extends Object implements LocalizedEnums
Note that it is expected that the resource bundle is in the class path, in the same package as the enum class, and has the same base name as the enum class. For example, for the following enumeration, there would be the properties resource bundle:
com.company.SomeEnum com.company.SomeEnum.properties com.company.SomeClass.SomeInnerEnum com.company.SomeClass$SomeInnerEnum.propertiesMoreover, it is required that each constant in the enum has a corresponding pair of entries in the properties file that are the constant name, suffixed with "-name" and "-desc" for the name and description respectively. Thus for the following enum declaration:
public enum Fruit { APPLE, ORANGE, BANANA }The contents of the resource bundle should look something like
# fruity resources APPLE-name = Apple APPLE-desc = A delicious fruit, often red or green. ORANGE-name = Orange ORANGE-desc = A citrus fruit, round in shape. BANANA-name = Banana BANANA-desc = A yellow fruit that grows in bunches.Using an enum presentation factory is very simple:
EnumPresentationFactory epf = new EnumPresentationFactory(); epf.register(Fruit.class); ... String appleName = epf.getName(Fruit.APPLE); String appleDesc = epf.getDescription(Fruit.APPLE);
Constructor and Description |
---|
EnumPresentationFactory()
Constructs an enum presentation factory.
|
Modifier and Type | Method and Description |
---|---|
int |
getBindingsCount()
Returns the number of enum class bindings currently registered with this factory.
|
String |
getDescription(Enum<?> e)
Returns the description for the specified enumeration constant.
|
String |
getName(Enum<?> e)
Returns the name for the specified enumeration constant.
|
void |
register(Class<? extends Enum<?>> enumClass)
Registers the specified enum class with the factory.
|
String |
toDebugString()
Returns a detailed, multi-line string showing the contents of this factory.
|
String |
toString() |
public EnumPresentationFactory()
public int getBindingsCount()
public void register(Class<? extends Enum<?>> enumClass) throws MissingResourceException
enumClass
- the enum classMissingResourceException
- if no associated resource bundle is foundpublic String getName(Enum<?> e)
getName
in interface LocalizedEnums
e
- the enum constantpublic String getDescription(Enum<?> e)
getDescription
in interface LocalizedEnums
e
- the enum constantpublic String toDebugString()
Copyright © 2016. All Rights Reserved.