@Status(stage=PRODUCTION, unitTests=COMPLETE) @Review(by="Kees Schotanus", at="2009-09-28") public final class CEnumeration extends Object
LocalizableEnumeration
Planet
for an example where a backing properties file is
used.
Modifier and Type | Method and Description |
---|---|
static <T extends Enum<T> & LocalizableEnumeration> |
enumFromCode(Class<T> localizableEnumeration,
Object code)
Gets the localizable enumerated constant of type T with the supplied code.
|
static <T extends Enum<T>> |
enumFromOrdinal(Class<T> enumeration,
int ordinal)
Gets the enumerated constant of type T with the supplied ordinal.
|
static <T extends Enum<T> & LocalizableEnumeration> |
getCodeDescription(T localizableEnumeratedConstant,
Locale locale)
Gets the CodeDescription of the supplied localizableEnumeratedConstant.
|
static <T extends Enum<T> & LocalizableEnumeration> |
getCodeDescriptions(Class<T> localizableEnumeration,
Locale locale)
Gets
CodeDescriptions for all the localizable enumerated constants of the supplied
localizableEnumeration. |
static <T extends Enum<T>> |
getCodeDescriptionsUsingEnumNameAsCode(Class<T> enumeration,
Locale locale)
Gets
CodeDescriptions for all the enumerated constants of the supplied enumeration, using the
names of the enumerated constants as the code for the different CodeDescriptions . |
static <T extends Enum<T>> |
getCodeDescriptionUsingEnumNameAsCode(T enumeratedConstant,
Locale locale)
Gets the CodeDescription of the supplied enumeratedConstant, using the name of the supplied enumerated constant as the
code for the returned CodeDescription.
|
static String |
getDescription(Class<? extends Enum<?>> enumeration,
Locale locale)
Gets the description of the enumeration as a whole.
|
static String |
getDescription(Enum<?> enumeratedConstant,
Locale locale)
Gets the description of the supplied enumeratedConstant.
|
static String |
getDescription(Enum<?> enumeratedConstant,
String key,
Locale locale)
Gets the description of the supplied enumeratedConstant using the supplied key as the key to the resource bundle..
|
static <T extends Enum<T> & LocalizableEnumeration> |
getDescriptionOfLocalizableEnum(T enumeratedConstant,
Locale locale)
Gets the description of the supplied enumeratedConstant using the name of the enumerated constant as the key to the
resouce bundle.
|
public static String getDescription(Class<? extends Enum<?>> enumeration, Locale locale)
ResourceBundle
is used, a MissingResourceException
is never thrown. Instead a
warning is logged and the simple class name of the supplied enumeration is returned.enumeration
- The enumeration to get the description for.locale
- Locale used to localize the description.
NullPointerException
- When the supplied enumeration is null.public static String getDescription(Enum<?> enumeratedConstant, Locale locale)
LocalizableEnumeration
, this method
will, as a convenience, try to get the description, using LocalizableEnumeration.getCode()
as the key to the
resource bundle file. Note that for a LocalizableEnumeration
, you normally call its getDescription() method.
However, lots of these methods are implemented by calling this method, causing infinite recursion, so here the code is
used as the resource bundle key. Naturally, this will fail for enumerations that are not backed by a properties file.
ResourceBundle
is used, a MissingResourceException
is never thrown. Instead a
warning is logged and the String representation of the supplied enumeratedConstant is returned.enumeratedConstant
- The enumerated constant to get the description for.locale
- Locale used to localize the description.
NullPointerException
- When the supplied enumeratedConstant is null.public static String getDescription(Enum<?> enumeratedConstant, String key, Locale locale)
enumeratedConstant
- The enumerated constant to get the description for.key
- The key to the resource bundle.locale
- Locale used to localize the description.
NullPointerException
- When either the supplied enumeratedConstant or key is null.IllegalArgumentException
- When the supplied key is empty.MissingResourceException
- When the description could not be retrieved from the resource bundle.public static <T extends Enum<T> & LocalizableEnumeration> String getDescriptionOfLocalizableEnum(T enumeratedConstant, Locale locale)
T
- The enumerated type.enumeratedConstant
- The enumerated constant to get the description for.locale
- Locale used to localize the description.
NullPointerException
- When the supplied enumeratedConstant is null.MissingResourceException
- When the description could not be retrieved from the resource bundle.public static <T extends Enum<T> & LocalizableEnumeration> List<CodeDescription> getCodeDescriptions(Class<T> localizableEnumeration, Locale locale)
CodeDescriptions
for all the localizable enumerated constants of the supplied
localizableEnumeration.T
- Type of the localizable enumeration.localizableEnumeration
- The localizable enumeration to get the CodeDescription objects for.locale
- Locale used to localize the descriptions.
CodeDescriptions
for the localizable enumerated constants of the supplied
localizableEnumeration.NullPointerException
- When the supplied localizableEnumeration is null.public static <T extends Enum<T> & LocalizableEnumeration> CodeDescription getCodeDescription(T localizableEnumeratedConstant, Locale locale)
T
- The type of the localizable enumerated constant.localizableEnumeratedConstant
- The localizable enumerated constant to get the CodeDescription for.locale
- Locale used to localize the description.
NullPointerException
- When the supplied localizableEnumeratedConstant is null.public static <T extends Enum<T>> List<CodeDescription> getCodeDescriptionsUsingEnumNameAsCode(Class<T> enumeration, Locale locale)
CodeDescriptions
for all the enumerated constants of the supplied enumeration, using the
names of the enumerated constants as the code for the different CodeDescriptions
.T
- The type of the enumeration.enumeration
- The enumeration to get the CodeDescription objects for.locale
- Locale used to localize the descriptions.
CodeDescriptions
for the enumerated constants of the supplied enumeration.NullPointerException
- When the supplied enumeration is null.public static <T extends Enum<T>> CodeDescription getCodeDescriptionUsingEnumNameAsCode(T enumeratedConstant, Locale locale)
T
- The type of the enumerated constant.enumeratedConstant
- The enumerated constant to get the CodeDescription for.locale
- Locale used to localize the description.
NullPointerException
- When the supplied enumeratedConstant is null.public static <T extends Enum<T>> T enumFromOrdinal(Class<T> enumeration, int ordinal)
T
- The type of the enumeration.enumeration
- The enumeration containing the enumerated constants.ordinal
- Ordinal of the enumerated constant.IllegalArgumentException
- When the supplied ordinal is out of range.NullPointerException
- When the supplied enumeration is null.public static <T extends Enum<T> & LocalizableEnumeration> T enumFromCode(Class<T> localizableEnumeration, Object code)
T
- The type of the enumeration.localizableEnumeration
- The localizable enumeration containing the enumerated constants.code
- The code of the enumerated constant.IllegalArgumentException
- When no enumerated constant has the supplied code.NullPointerException
- When either the supplied localizableEnumeration or code is null.Copyright © 2008–2018. All rights reserved.