Class StringToEnumConverter
- java.lang.Object
-
- com.vaadin.v7.data.util.converter.StringToEnumConverter
-
- All Implemented Interfaces:
Converter<String,Enum>
,Serializable
@Deprecated public class StringToEnumConverter extends Object implements Converter<String,Enum>
Deprecated.As of 8.0, a lightweight lambda-based converter can be build withBinder
.forField(...).withConverter(...)
methods.A converter that converts from
Designed to provide nice human readable strings forString
to anEnum
and back.Enum
classes conforming to one of these patterns:- The constants are named SOME_UPPERCASE_WORDS and there's no toString implementation.
- toString() always returns the same human readable string that is not the same as its name() value. Each constant in the enum type returns a distinct toString() value.
- Since:
- 7.4
- Author:
- Vaadin Ltd
- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface com.vaadin.v7.data.util.converter.Converter
Converter.ConversionException
-
-
Constructor Summary
Constructors Constructor Description StringToEnumConverter()
Deprecated.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description Enum
convertToModel(String value, Class<? extends Enum> targetType, Locale locale)
Deprecated.Converts the given value from target type to source type.String
convertToPresentation(Enum value, Class<? extends String> targetType, Locale locale)
Deprecated.Converts the given value from source type to target type.static String
enumToString(Enum<?> value, Locale locale)
Deprecated.Converts the given enum to a human readable string using the given locale.Class<Enum>
getModelType()
Deprecated.The source type of the converter.Class<String>
getPresentationType()
Deprecated.The target type of the converter.static <T extends Enum<T>>
TstringToEnum(String value, Class<T> enumType, Locale locale)
Deprecated.Converts the given string to the given enum type using the given locale.
-
-
-
Method Detail
-
convertToModel
public Enum convertToModel(String value, Class<? extends Enum> targetType, Locale locale) throws Converter.ConversionException
Deprecated.Description copied from interface:Converter
Converts the given value from target type to source type.A converter can optionally use locale to do the conversion.
A converter should in most cases be symmetric so chainingConverter.convertToPresentation(Object, Class, Locale)
andConverter.convertToModel(Object, Class, Locale)
should return the original value.- Specified by:
convertToModel
in interfaceConverter<String,Enum>
- Parameters:
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.- Returns:
- The converted value compatible with the source type
- Throws:
Converter.ConversionException
- If the value could not be converted
-
stringToEnum
public static <T extends Enum<T>> T stringToEnum(String value, Class<T> enumType, Locale locale) throws Converter.ConversionException
Deprecated.Converts the given string to the given enum type using the given locale.Compatible with
enumToString(Enum, Locale)
- Parameters:
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- Returns:
- The enum which matches the given string
- Throws:
Converter.ConversionException
- if the conversion fails
-
enumToString
public static String enumToString(Enum<?> value, Locale locale)
Deprecated.Converts the given enum to a human readable string using the given locale.Compatible with
stringToEnum(String, Class, Locale)
- Parameters:
value
- The enum value to convertlocale
- The locale to use for conversion. If null, the JVM default locale will be used- Returns:
- A human readable string based on the enum
- Throws:
Converter.ConversionException
- if the conversion fails
-
convertToPresentation
public String convertToPresentation(Enum value, Class<? extends String> targetType, Locale locale) throws Converter.ConversionException
Deprecated.Description copied from interface:Converter
Converts the given value from source type to target type.A converter can optionally use locale to do the conversion.
A converter should in most cases be symmetric so chainingConverter.convertToPresentation(Object, Class, Locale)
andConverter.convertToModel(Object, Class, Locale)
should return the original value.- Specified by:
convertToPresentation
in interfaceConverter<String,Enum>
- Parameters:
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.- Returns:
- The converted value compatible with the source type
- Throws:
Converter.ConversionException
- If the value could not be converted
-
getModelType
public Class<Enum> getModelType()
Deprecated.Description copied from interface:Converter
The source type of the converter. Values of this type can be passed toConverter.convertToPresentation(Object, Class, Locale)
.- Specified by:
getModelType
in interfaceConverter<String,Enum>
- Returns:
- The source type
-
getPresentationType
public Class<String> getPresentationType()
Deprecated.Description copied from interface:Converter
The target type of the converter. Values of this type can be passed toConverter.convertToModel(Object, Class, Locale)
.- Specified by:
getPresentationType
in interfaceConverter<String,Enum>
- Returns:
- The target type
-
-