public class EnumTranslator extends Object implements EnumTranslationConfiguration
| Constructor and Description |
|---|
EnumTranslator(MessageSourceAccessor messageSourceAccessor)
Creates a new
EnumTranslator using the given MessageSourceAccessor. |
| Modifier and Type | Method and Description |
|---|---|
String |
asText(Enum<?> value)
Resolves the given enum value into a
String consulting the configured MessageSourceAccessor
potentially falling back to the default translation if configured. |
<T extends Enum<?>> |
fromText(Class<T> type,
String text)
Parses the given source text into the corresponding enum value using the configured
MessageSourceAccessor
potentially falling back to the default translation or the plain enum name if configured. |
List<String> |
getValues(Class<? extends Enum<?>> type)
Returns all potentially translated values for the given
Enum type. |
void |
setEnableDefaultTranslation(boolean enableDefaultTranslation) |
void |
setParseEnumNameAsFallback(boolean parseEnumNameAsFallback) |
public EnumTranslator(MessageSourceAccessor messageSourceAccessor)
EnumTranslator using the given MessageSourceAccessor.messageSourceAccessor - must not be null.public void setEnableDefaultTranslation(boolean enableDefaultTranslation)
setEnableDefaultTranslation in interface EnumTranslationConfigurationpublic void setParseEnumNameAsFallback(boolean parseEnumNameAsFallback)
setParseEnumNameAsFallback in interface EnumTranslationConfigurationpublic String asText(Enum<?> value)
String consulting the configured MessageSourceAccessor
potentially falling back to the default translation if configured. Returning the plain enum name if no resolution
applies.value - must not be null.public List<String> getValues(Class<? extends Enum<?>> type)
Enum type.type - must not be null.public <T extends Enum<?>> T fromText(Class<T> type, String text)
MessageSourceAccessor
potentially falling back to the default translation or the plain enum name if configured.type - must not be null.text - can be nullCopyright © 2011–2019 Pivotal Software, Inc.. All rights reserved.