public abstract class AbstractEnumProvider extends AbstractLoggableComponent implements EnumProvider
EnumProvider.| Modifier and Type | Class and Description |
|---|---|
protected static class |
AbstractEnumProvider.EnumContainer
This inner class is a container for an
EnumDefinition with its values. |
private static class |
AbstractEnumProvider.EnumDefinitionIterator |
| Modifier and Type | Field and Description |
|---|---|
private Map<String,AbstractEnumProvider.EnumContainer> |
enumContainerMap |
private StringUtil |
stringUtil |
| Constructor and Description |
|---|
AbstractEnumProvider()
The constructor.
|
AbstractEnumProvider(MapFactory<?> mapFactory)
The constructor.
|
| Modifier and Type | Method and Description |
|---|---|
void |
clear(EnumDefinition<?,?> enumDefinition)
This method clears the (potentially) cached
enum values of the given
EnumDefinition. |
protected void |
doInitialize()
This method performs the actual
initialization. |
protected AbstractEnumProvider.EnumContainer |
getEnumContainer(String key) |
<TYPE> EnumDefinition<TYPE,?> |
getEnumDefinition(Class<TYPE> enumType)
This method gets the
EnumDefinition with the given enumType. |
EnumDefinition<?,?> |
getEnumDefinition(String key)
This method gets the
EnumDefinition with the given key. |
Iterator<EnumDefinition<?,?>> |
getEnumDefinitions()
This method gets an (unmodifiable)
Iterator with all existing EnumDefinitions. |
<CATEGORY,ENUM extends EnumTypeWithCategory<?,CATEGORY>> |
getEnumDefinitionWithCategory(Class<? extends ENUM> enumType)
This method gets the
EnumDefinition with the given enumType. |
<ENUM> ENUM |
getEnumValue(Class<ENUM> enumType,
String value,
boolean required)
|
<ENUM> ENUM |
getEnumValue(EnumDefinition<ENUM,?> enumDefinition,
String value,
boolean required)
|
<ENUM> List<ENUM> |
getEnumValues(EnumDefinition<ENUM,?> enumDefinition)
This method gets the
List of EnumType-instances that represent the values of the given
EnumDefinition. |
<CATEGORY,ENUM extends EnumTypeWithCategory<?,CATEGORY>> |
getEnumValues(EnumDefinition<ENUM,CATEGORY> enumDefinition,
CATEGORY... categories)
|
protected StringUtil |
getStringUtil() |
boolean |
isAvailable(EnumDefinition<?,?> enumDefinition)
This method determines if the given
EnumDefinition is available, so it is ensured that the
enum values can be retrieved. |
protected boolean |
isSupportEnumAutoRegistration() |
Iterator<EnumDefinition<?,?>> |
iterator()
The same as
EnumProvider.getEnumDefinitions(). |
protected abstract void |
loadEnumValues(AbstractEnumProvider.EnumContainer container) |
private String |
normalizeStringRepresentation(String value)
Normalizes the given
String. |
protected <ENUM extends Enum<ENUM>> |
registerEnum(Class<ENUM> enumClass)
This method registers the given
enumClass as EnumDefinition. |
protected void |
registerEnumDefinition(AbstractEnumDefinition<?,?> enumDefinition)
This method registers the given
EnumDefinition. |
protected void |
registerEnumDefinitions()
Registers the enum definitions to support.
|
void |
require(EnumDefinition<?,?>... enumDefinitions)
This method triggers that the given
EnumDefinitions are available. |
void |
setStringUtil(StringUtil stringUtil) |
createLogger, getLoggerdoInitialized, getInitializationState, initializeclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitrequireforEach, spliteratorprivate final Map<String,AbstractEnumProvider.EnumContainer> enumContainerMap
private StringUtil stringUtil
public AbstractEnumProvider()
public AbstractEnumProvider(MapFactory<?> mapFactory)
mapFactory - is the MapFactory used to create internal Maps for cache or registration.protected StringUtil getStringUtil()
StringUtil instance.@Inject public void setStringUtil(StringUtil stringUtil)
stringUtil - is the StringUtil to Inject.protected void doInitialize()
AbstractComponentinitialization. It is called when AbstractComponent.initialize() is
invoked for the first time. super.AbstractComponent.doInitialize().doInitialize in class AbstractLoggableComponentprotected void registerEnumDefinitions()
add custom EnumDefinitions or replace defaults.public final Iterator<EnumDefinition<?,?>> iterator()
EnumProviderEnumProvider.getEnumDefinitions().
iterator in interface Iterable<EnumDefinition<?,?>>iterator in interface EnumProviderpublic Iterator<EnumDefinition<?,?>> getEnumDefinitions()
EnumProviderIterator with all existing EnumDefinitions. In most cases this
is a static list, however it may also be dynamic.getEnumDefinitions in interface EnumProviderIterator with all existing EnumDefinitions.EnumProvider.iterator()protected <ENUM extends Enum<ENUM>> void registerEnum(Class<ENUM> enumClass)
enumClass as EnumDefinition.protected void registerEnumDefinition(AbstractEnumDefinition<?,?> enumDefinition)
EnumDefinition.enumDefinition - is the EnumDefinition to register.registerEnum(Class)public <CATEGORY,ENUM extends EnumTypeWithCategory<?,CATEGORY>> EnumDefinition<ENUM,CATEGORY> getEnumDefinitionWithCategory(Class<? extends ENUM> enumType) throws ObjectNotFoundException
EnumProviderEnumDefinition with the given enumType.getEnumDefinitionWithCategory in interface EnumProviderCATEGORY - is the generic for the category.ENUM - is the generic for the enum type.enumType - is the enum type of the requested definition.EnumDefinition.ObjectNotFoundException - if no such EnumDefinition exists.public <TYPE> EnumDefinition<TYPE,?> getEnumDefinition(Class<TYPE> enumType) throws ObjectNotFoundException
EnumProviderEnumDefinition with the given enumType.getEnumDefinition in interface EnumProviderTYPE - is the generic for the enum type.enumType - is the enum type of the requested definition.EnumDefinition.ObjectNotFoundException - if no such EnumDefinition exists.protected boolean isSupportEnumAutoRegistration()
true to automatically registerEnum(Class) requested Enum types (default),
false otherwise (override to disable).protected AbstractEnumProvider.EnumContainer getEnumContainer(String key)
key - is the identifier of the requested AbstractEnumProvider.EnumContainer.AbstractEnumProvider.EnumContainer.public EnumDefinition<?,?> getEnumDefinition(String key) throws ObjectNotFoundException
EnumProviderEnumDefinition with the given key. To get the default EnumDefinition
for a particular enum type you should use EnumProvider.getEnumDefinition(Class)
instead. However, for the same enum type multiple EnumDefinitions can exists. The default definition should
have the qualified name of the enum type while
additional definitions should have more specific keys that do not clash with others (e.g.
"java.lang.Boolean_All_None").getEnumDefinition in interface EnumProviderkey - is the key of the requested definition.EnumDefinition.ObjectNotFoundException - if no such EnumDefinition exists.public boolean isAvailable(EnumDefinition<?,?> enumDefinition)
EnumProviderEnumDefinition is available, so it is ensured that the
enum values can be retrieved.isAvailable in interface EnumProviderenumDefinition - is the EnumDefinition to check.true if the enum values for the given EnumDefinition
are available (already loaded / in cache), false otherwise.public <ENUM> ENUM getEnumValue(Class<ENUM> enumType, String value, boolean required) throws IllegalCaseException
EnumProvidergetEnumValue in interface EnumProviderENUM - is the generic for the enum type.enumType - is the EnumType for which the value is requested.value - is the string representation of the requested EnumType
instance based on EnumDefinition.getFormatter().required - - true if the requested EnumType-instance is required, false otherwise.EnumType-instance. Will be null if value is null or if required
is false and no such EnumType instance exists.IllegalCaseException - if required is true and no such EnumType instance exists.public <ENUM> ENUM getEnumValue(EnumDefinition<ENUM,?> enumDefinition, String value, boolean required)
EnumProvidergetEnumValue in interface EnumProviderENUM - is the generic for the enum type.enumDefinition - is the EnumDefinition for which the value is requested.value - is the string representation of the requested EnumType
instance based on EnumDefinition.getFormatter().required - - true if the requested EnumType-instance is required, false otherwise.EnumType-instance. Will be null if value is null or if required
is false and no such EnumType instance exists.private String normalizeStringRepresentation(String value)
String.value - is the value to normalize.StringUtil.toCamlCase(String),
EnumEnumDefinition.EnumDefaultFormatterpublic <ENUM> List<ENUM> getEnumValues(EnumDefinition<ENUM,?> enumDefinition)
EnumProviderList of EnumType-instances that represent the values of the given
EnumDefinition. In case the enum type implements
AttributeReadDeprecated the
deprecated enum values will be
excluded from the returned List.getEnumValues in interface EnumProviderENUM - is the generic for the enum type.enumDefinition - is the EnumDefinition for which the values are requested.List of EnumTypes.protected abstract void loadEnumValues(AbstractEnumProvider.EnumContainer container)
container - is the AbstractEnumProvider.EnumContainer for which the getEnumValues(EnumDefinition) should be
loaded.public <CATEGORY,ENUM extends EnumTypeWithCategory<?,CATEGORY>> List<ENUM> getEnumValues(EnumDefinition<ENUM,CATEGORY> enumDefinition, CATEGORY... categories)
EnumProviderList of enum values filtered by the given
categories. So only these enum
values are returned that have a categorygetEnumValues in interface EnumProviderCATEGORY - is the generic type of the category
type.ENUM - is the generic for the enum type.enumDefinition - is the EnumDefinition for which the values are requested.categories - are the categories.List of matching EnumTypes.public void clear(EnumDefinition<?,?> enumDefinition)
EnumProviderenum values of the given
EnumDefinition. If the enum is dynamic it is NOT
available (anymore) after this operation.clear in interface EnumProviderenumDefinition - is the EnumDefinition to clear.public void require(EnumDefinition<?,?>... enumDefinitions)
EnumProviderEnumDefinitions are available.require in interface EnumProviderenumDefinitions - are the EnumDefinitions of the required enumerations.Copyright © 2001–2016 mmm-Team. All rights reserved.