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 EnumDefinition s. |
<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
EnumDefinition s are available . |
void |
setStringUtil(StringUtil stringUtil) |
createLogger, getLogger
doInitialized, getInitializationState, initialize
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
require
forEach, spliterator
private final Map<String,AbstractEnumProvider.EnumContainer> enumContainerMap
private StringUtil stringUtil
public AbstractEnumProvider()
public AbstractEnumProvider(MapFactory<?> mapFactory)
mapFactory
- is the MapFactory
used to create internal Map
s for cache or registration.protected StringUtil getStringUtil()
StringUtil
instance.@Inject public void setStringUtil(StringUtil stringUtil)
stringUtil
- is the StringUtil
to Inject
.protected void doInitialize()
AbstractComponent
initialization
. It is called when AbstractComponent.initialize()
is
invoked for the first time. super.
AbstractComponent.doInitialize()
.doInitialize
in class AbstractLoggableComponent
protected void registerEnumDefinitions()
add
custom EnumDefinition
s or replace defaults.public final Iterator<EnumDefinition<?,?>> iterator()
EnumProvider
EnumProvider.getEnumDefinitions()
.
iterator
in interface Iterable<EnumDefinition<?,?>>
iterator
in interface EnumProvider
public Iterator<EnumDefinition<?,?>> getEnumDefinitions()
EnumProvider
Iterator
with all existing EnumDefinition
s. In most cases this
is a static list, however it may also be dynamic.getEnumDefinitions
in interface EnumProvider
Iterator
with all existing EnumDefinition
s.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
EnumProvider
EnumDefinition
with the given enumType
.getEnumDefinitionWithCategory
in interface EnumProvider
CATEGORY
- 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
EnumProvider
EnumDefinition
with the given enumType
.getEnumDefinition
in interface EnumProvider
TYPE
- 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
EnumProvider
EnumDefinition
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 EnumDefinition
s 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 EnumProvider
key
- is the key
of the requested definition.EnumDefinition
.ObjectNotFoundException
- if no such EnumDefinition
exists.public boolean isAvailable(EnumDefinition<?,?> enumDefinition)
EnumProvider
EnumDefinition
is available, so it is ensured that the
enum values
can be retrieved.isAvailable
in interface EnumProvider
enumDefinition
- 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
EnumProvider
getEnumValue
in interface EnumProvider
ENUM
- 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)
EnumProvider
getEnumValue
in interface EnumProvider
ENUM
- 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.EnumDefaultFormatter
public <ENUM> List<ENUM> getEnumValues(EnumDefinition<ENUM,?> enumDefinition)
EnumProvider
List
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 EnumProvider
ENUM
- is the generic for the enum type
.enumDefinition
- is the EnumDefinition
for which the values are requested.List
of EnumType
s.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)
EnumProvider
List
of enum values
filtered by the given
categories
. So only these enum
values
are returned that have a category
getEnumValues
in interface EnumProvider
CATEGORY
- 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 EnumType
s.public void clear(EnumDefinition<?,?> enumDefinition)
EnumProvider
enum values
of the given
EnumDefinition
. If the enum is dynamic
it is NOT
available
(anymore) after this operation.clear
in interface EnumProvider
enumDefinition
- is the EnumDefinition
to clear.public void require(EnumDefinition<?,?>... enumDefinitions)
EnumProvider
EnumDefinition
s are available
.require
in interface EnumProvider
enumDefinitions
- are the EnumDefinition
s of the required enumerations.Copyright © 2001–2016 mmm-Team. All rights reserved.