Package org.nuiton.converter
Class EnumConverter<E extends Enum>
- java.lang.Object
-
- org.nuiton.converter.EnumConverter<E>
-
- All Implemented Interfaces:
org.apache.commons.beanutils.Converter
,NuitonConverter<E>
public class EnumConverter<E extends Enum> extends Object implements NuitonConverter<E>
To convertEnum
type-safe (exact type isenumType
from and toString
.It is possible also to convert the enum object from his ordinal using method
convertFromOrdinal(Class, Object)
.you can also define a default value while trying to convert
null
value.To register a new such converter use methods
ConverterUtil.registerEnumConverter(Class)
, orConverterUtil.registerEnumConverter(Class, Object)
.- Since:
- 1.0
- Author:
- Tony Chemit - chemit@codelutin.com
- See Also:
Enum
,Enum.ordinal()
-
-
Field Summary
Fields Modifier and Type Field Description protected Object
defaultValue
Default value to use if try to convertnull
value and flaguseDefault
is on.protected Class<E>
enumType
Enum type-safe.protected boolean
useDefault
flag to use or not default value.
-
Constructor Summary
Constructors Constructor Description EnumConverter(Class<E> enumType)
EnumConverter(Class<E> enumType, Object defaultValue)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected EnumSet<?>
allOf(Class<?> aClass)
<T> T
convert(Class<T> aClass, Object value)
protected Object
convertFromOrdinal(Class<?> aClass, Object value)
Class<E>
getType()
protected static boolean
isEnabled(Class<?> aClass, Class<?> enumType)
protected Object
valueOf(Class<?> aClass, Object value)
-
-
-
Field Detail
-
defaultValue
protected Object defaultValue
Default value to use if try to convertnull
value and flaguseDefault
is on.
-
useDefault
protected boolean useDefault
flag to use or not default value.
-
-