Class AbstractStringToNumberConverter<T>
java.lang.Object
com.vaadin.featurepack.data.converter.AbstractStringToNumberConverter<T>
- All Implemented Interfaces:
Converter<String,,T> com.vaadin.flow.data.converter.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 and NumberFormat 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.
- Author:
- Vaadin Ltd
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from interface com.vaadin.featurepack.data.converter.Converter
Converter.ConversionException -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected NumberconvertToNumber(String value, Class<? extends Number> targetType, Locale locale) Convert the value to a Number using the given locale andgetFormat(Locale).convertToPresentation(T value, Class<? extends String> targetType, Locale locale) Converts the given value from source type to target type.protected NumberFormatReturns the format used byandinvalid reference
#convertToPresentation(Object, Locale).invalid reference
#convertToModel(Object, Locale)The target type of the converter.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.vaadin.featurepack.data.converter.Converter
convertToModel, convertToModel, convertToPresentation, getModelTypeMethods inherited from interface com.vaadin.flow.data.converter.Converter
chain
-
Constructor Details
-
AbstractStringToNumberConverter
public AbstractStringToNumberConverter()
-
-
Method Details
-
getFormat
Returns the format used byandinvalid reference
#convertToPresentation(Object, Locale).invalid reference
#convertToModel(Object, Locale)- Parameters:
locale- The locale to use- Returns:
- A NumberFormat instance
-
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
-
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
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
-