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 convertEnumtype-safe (exact type isenumTypefrom 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
nullvalue.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 ObjectdefaultValueDefault value to use if try to convertnullvalue and flaguseDefaultis on.protected Class<E>enumTypeEnum type-safe.protected booleanuseDefaultflag 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> Tconvert(Class<T> aClass, Object value)protected ObjectconvertFromOrdinal(Class<?> aClass, Object value)Class<E>getType()protected static booleanisEnabled(Class<?> aClass, Class<?> enumType)protected ObjectvalueOf(Class<?> aClass, Object value)
-
-
-
Field Detail
-
defaultValue
protected Object defaultValue
Default value to use if try to convertnullvalue and flaguseDefaultis on.
-
useDefault
protected boolean useDefault
flag to use or not default value.
-
-