T - the enumeration type whose constants will be converted from/to Stringpublic class EnumConversion<T extends Enum<T>> extends ObjectConversion<T>
This class supports multiple types of identification of enumeration constants. For example, you can match the literal (Enum.name() the ordinal (Enum.ordinal() or
the result of a method defined in your enumeration.
The reverse conversion from an enumeration to String (in revert(Enum) will return a String using the first EnumSelector provided in the constructor of this class.
ObjectConversion,
EnumSelector| Constructor and Description |
|---|
EnumConversion(Class<T> enumType)
Defines a conversion for an enumeration type that will attempt to match Strings against
the results of the output produced by (
Enum.name(), (Enum.ordinal() and (Enum.toString()
of each constant of the given enumeration (@link Class.getEnumConstants()). |
EnumConversion(Class<T> enumType,
EnumSelector... selectors)
Defines a conversion for an enumeration type that will attempt to match Strings the list of
EnumSelectors, in the specified order. |
EnumConversion(Class<T> enumType,
String customEnumElement,
EnumSelector... selectors)
Defines a conversion for an enumeration type that will attempt to match Strings the list of
EnumSelectors, in the specified order. |
EnumConversion(Class<T> enumType,
T valueIfStringIsNull,
String valueIfEnumIsNull,
String customEnumElement,
EnumSelector... selectors)
Defines a conversion for an enumeration type that will attempt to match Strings the list of
EnumSelectors, in the specified order. |
| Modifier and Type | Method and Description |
|---|---|
protected T |
fromString(String input)
Creates an instance of T from a String representation.
|
String |
revert(T input)
Converts a value of type T back to a String
|
execute, fromInput, getValueIfObjectIsNull, getValueIfStringIsNull, setValueIfObjectIsNull, setValueIfStringIsNull, undogetValueOnNullInput, getValueOnNullOutput, setValueOnNullInput, setValueOnNullOutputpublic EnumConversion(Class<T> enumType)
Enum.name(), (Enum.ordinal() and (Enum.toString()
of each constant of the given enumeration (@link Class.getEnumConstants()).enumType - the enumeration type to be converted from/to Stringpublic EnumConversion(Class<T> enumType, EnumSelector... selectors)
EnumSelectors, in the specified order.
Each EnumSelector identifies which element of each constant of the enumeration class (@link Class.getEnumConstants()
should be used to match equivalent Strings.enumType - the enumeration type to be converted from/to Stringselectors - the selection elements of the enumeration to use for matching Strings.public EnumConversion(Class<T> enumType, String customEnumElement, EnumSelector... selectors)
EnumSelectors, in the specified order.
Each EnumSelector identifies which element of each constant of the enumeration class (@link Class.getEnumConstants()
should be used to match equivalent Strings.enumType - the enumeration type to be converted from/to StringcustomEnumElement - name of custom element of the enumeration (attribute or method) whose values should be used to match equivalent Strings.selectors - the selection elements of the enumeration to use for matching Strings.public EnumConversion(Class<T> enumType, T valueIfStringIsNull, String valueIfEnumIsNull, String customEnumElement, EnumSelector... selectors)
EnumSelectors, in the specified order.
Each EnumSelector identifies which element of each constant of the enumeration class (@link Class.getEnumConstants()
should be used to match equivalent Strings.enumType - the enumeration type to be converted from/to StringvalueIfStringIsNull - the default enumeration constant to use if the input String is nullvalueIfEnumIsNull - the default String value to use if the input enum constant is nullcustomEnumElement - name of custom element of the enumeration (attribute or method) whose values should be used to match equivalent Strings.selectors - the selection elements of the enumeration to use for matching Strings.public String revert(T input)
ObjectConversionThis is a general implementation that simply returns the result of input.toString()
revert in interface Conversion<String,T extends Enum<T>>revert in class ObjectConversion<T extends Enum<T>>input - the input of type T to be converted to a StringObjectConversion.getValueIfObjectIsNull() if the input object is null.protected T fromString(String input)
ObjectConversionfromString in class ObjectConversion<T extends Enum<T>>input - The String to be converted to TCopyright © 2021 Univocity Software Pty Ltd. All rights reserved.