com.vaadin.data.util.converter.
Class AbstractStringToNumberConverter<T>
- java.lang.Object
-
- com.vaadin.data.util.converter.AbstractStringToNumberConverter<T>
-
All Implemented Interfaces:
Converter<String,T>
,Serializable
Direct Known Subclasses:
StringToBigDecimalConverter
,StringToBigIntegerConverter
,StringToByteConverter
,StringToDoubleConverter
,StringToFloatConverter
,StringToIntegerConverter
,StringToLongConverter
,StringToShortConverter
public abstract class AbstractStringToNumberConverter<T> extends Object implements Converter<String,T>
A converter that converts from the number type T to
String
and back. Uses the given locale andNumberFormat
for formatting and parsing. Automatically trims the input string, removing any leading and trailing white space.Override and overwrite
getFormat(Locale)
to use a different format.Since:
7.1
Author:
Vaadin Ltd
See Also:
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface com.vaadin.data.util.converter.Converter
Converter.ConversionException
-
-
Constructor Summary
Constructors Constructor Description AbstractStringToNumberConverter()
-
Method Summary
All Methods Modifier and Type Method Description protected Number
convertToNumber(String value, Class<? extends Number> targetType, Locale locale)
Convert the value to a Number using the given locale and
getFormat(Locale)
.String
convertToPresentation(T value, Class<? extends String> targetType, Locale locale)
Converts the given value from source type to target type.
protected NumberFormat
getFormat(Locale locale)
Returns the format used by
#convertToPresentation(Object, Locale)
and#convertToModel(Object, Locale)
.Class<String>
getPresentationType()
The target type of the converter.
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.vaadin.data.util.converter.Converter
convertToModel, getModelType
-
-
-
-
Method Detail
-
getFormat
protected NumberFormat getFormat(Locale locale)
Returns the format used by
#convertToPresentation(Object, Locale)
and#convertToModel(Object, Locale)
.Parameters:
locale
- The locale to useReturns:
A NumberFormat instance
Since:
7.1
-
convertToNumber
protected Number convertToNumber(String value, Class<? extends Number> targetType, Locale locale) throws Converter.ConversionException
Convert the value to a Number using the given locale and
getFormat(Locale)
.Parameters:
value
- The value to convertlocale
- The locale to use for conversionReturns:
The converted value
Throws:
Converter.ConversionException
- If there was a problem converting the valueSince:
7.1
-
convertToPresentation
public String convertToPresentation(T value, Class<? extends String> targetType, Locale locale) throws Converter.ConversionException
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,T>
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
-
getPresentationType
public Class<String> getPresentationType()
Description copied from interface:
Converter
The target type of the converter. Values of this type can be passed to
Converter.convertToModel(Object, Class, Locale)
.Specified by:
getPresentationType
in interfaceConverter<String,T>
Returns:
The target type
-
-