Package 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 toStringand back. Uses the given locale andNumberFormatfor 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:
- Serialized Form
-
-
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 Instance Methods Concrete Methods Modifier and Type Method Description protected NumberconvertToNumber(String value, Class<? extends Number> targetType, Locale locale)Convert the value to a Number using the given locale andgetFormat(Locale).StringconvertToPresentation(T value, Class<? extends String> targetType, Locale locale)Converts the given value from source type to target type.protected NumberFormatgetFormat(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 use- Returns:
- 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 andgetFormat(Locale).- Parameters:
value- The value to convertlocale- The locale to use for conversion- Returns:
- The converted value
- Throws:
Converter.ConversionException- If there was a problem converting the value- Since:
- 7.1
-
convertToPresentation
public String convertToPresentation(T value, Class<? extends String> targetType, Locale locale) throws Converter.ConversionException
Description copied from interface:ConverterConverts 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:
convertToPresentationin 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:ConverterThe target type of the converter. Values of this type can be passed toConverter.convertToModel(Object, Class, Locale).- Specified by:
getPresentationTypein interfaceConverter<String,T>- Returns:
- The target type
-
-