|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.vaadin.data.util.converter.StringToEnumConverter
public class StringToEnumConverter
A converter that converts from String
to an Enum
and back.
Designed to provide nice human readable strings for Enum
classes
where the constants are named SOME_UPPERCASE_WORDS. Will not necessarily work
correctly for other cases.
Nested Class Summary |
---|
Nested classes/interfaces inherited from interface com.vaadin.data.util.converter.Converter |
---|
Converter.ConversionException |
Constructor Summary | |
---|---|
StringToEnumConverter()
|
Method Summary | ||
---|---|---|
java.lang.Enum |
convertToModel(java.lang.String value,
java.lang.Class<? extends java.lang.Enum> targetType,
java.util.Locale locale)
Converts the given value from target type to source type. |
|
java.lang.String |
convertToPresentation(java.lang.Enum value,
java.lang.Class<? extends java.lang.String> targetType,
java.util.Locale locale)
Converts the given value from source type to target type. |
|
static java.lang.String |
enumToString(java.lang.Enum<?> value,
java.util.Locale locale)
Converts the given enum to a human readable string using the given locale |
|
java.lang.Class<java.lang.Enum> |
getModelType()
The source type of the converter. |
|
java.lang.Class<java.lang.String> |
getPresentationType()
The target type of the converter. |
|
static
|
stringToEnum(java.lang.String value,
java.lang.Class<T> enumType,
java.util.Locale locale)
Converts the given string to the given enum type using the given locale |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public StringToEnumConverter()
Method Detail |
---|
public java.lang.Enum convertToModel(java.lang.String value, java.lang.Class<? extends java.lang.Enum> targetType, java.util.Locale locale) throws Converter.ConversionException
Converter
A converter can optionally use locale to do the conversion.
A converter should in most cases be symmetric so chainingConverter.convertToPresentation(Object, Class, Locale)
and
Converter.convertToModel(Object, Class, Locale)
should return the original
value.
convertToModel
in interface Converter<java.lang.String,java.lang.Enum>
value
- The value to convert, compatible with the target type. Can be
nulltargetType
- The requested type of the return valuelocale
- The locale to use for conversion. Can be null.
Converter.ConversionException
- If the value could not be convertedpublic static <T extends java.lang.Enum<T>> T stringToEnum(java.lang.String value, java.lang.Class<T> enumType, java.util.Locale locale) throws Converter.ConversionException
Compatible with enumToString(Enum, Locale)
value
- The string value to convertenumType
- The type of enum to createlocale
- The locale to use for conversion. If null, the JVM default
locale will be used
ConversionException
- if the conversion fails
Converter.ConversionException
public static java.lang.String enumToString(java.lang.Enum<?> value, java.util.Locale locale)
Compatible with stringToEnum(String, Class, Locale)
value
- The enum value to convertlocale
- The locale to use for conversion. If null, the JVM default
locale will be used
ConversionException
- if the conversion failspublic java.lang.String convertToPresentation(java.lang.Enum value, java.lang.Class<? extends java.lang.String> targetType, java.util.Locale locale) throws Converter.ConversionException
Converter
A converter can optionally use locale to do the conversion.
A converter should in most cases be symmetric so chainingConverter.convertToPresentation(Object, Class, Locale)
and
Converter.convertToModel(Object, Class, Locale)
should return the original
value.
convertToPresentation
in interface Converter<java.lang.String,java.lang.Enum>
value
- The value to convert, compatible with the target type. Can be
nulltargetType
- The requested type of the return valuelocale
- The locale to use for conversion. Can be null.
Converter.ConversionException
- If the value could not be convertedpublic java.lang.Class<java.lang.Enum> getModelType()
Converter
Converter.convertToPresentation(Object, Class, Locale)
.
getModelType
in interface Converter<java.lang.String,java.lang.Enum>
public java.lang.Class<java.lang.String> getPresentationType()
Converter
Converter.convertToModel(Object, Class, Locale)
.
getPresentationType
in interface Converter<java.lang.String,java.lang.Enum>
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |