org.spicefactory.lib.reflect.convert
Class EnumConverter
java.lang.Object
org.spicefactory.lib.reflect.convert.EnumConverter
- All Implemented Interfaces:
- Converter<Enum<?>>
public class EnumConverter
- extends Object
- implements Converter<Enum<?>>
Converter implementation for converting Enum types.
It can handle String values which will be interpreted as the name of the Enum and
Number values which will be interpreted as the ordinal of the Enum.
For values that are already instances of Enum it will only check if the type matches the
required target type and return the value unchanged.
- Author:
- Jens Halm
|
Method Summary |
Enum<? extends Enum<?>> |
convert(Object value,
TypeContext typeContext)
Converts the given value to the target type of this converter. |
boolean |
supports(Class<?> type)
Checks if this converter can convert instances of the given class to the target type of this converter. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
EnumConverter
public EnumConverter()
convert
public Enum<? extends Enum<?>> convert(Object value,
TypeContext typeContext)
throws ConversionException
- Description copied from interface:
Converter
- Converts the given value to the target type of this converter.
The TypeContext parameter serves as an additional hint for the required type of the converted value.
Example: If a Converter implementation handles all kinds of Collections (implements
Converter<Collection>) the given TypeContext might provide information for the
exact nature of the Collection (like List<String>).
- Specified by:
convert in interface Converter<Enum<?>>
- Parameters:
value - the value to be convertedtypeContext - additional information for the required type of the converted value
- Returns:
- the converted value
- Throws:
ConversionException - if the conversion fails
supports
public boolean supports(Class<?> type)
- Description copied from interface:
Converter
- Checks if this converter can convert instances of the given class to the target type of this converter.
Of course this does not give any guarantee that conversion will succeed for any instance of the given
type.
- Specified by:
supports in interface Converter<Enum<?>>
- Parameters:
type - the class to be checked
- Returns:
- true if this converter can convert instances of the given class