public abstract class AbstractStringToNumberConverter<T> extends Object implements Converter<String,T>
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.
Converter.ConversionException
Constructor and Description |
---|
AbstractStringToNumberConverter() |
Modifier and Type | Method and 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.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
convertToModel, getModelType
protected NumberFormat getFormat(Locale locale)
#convertToPresentation(Object, Locale)
and #convertToModel(Object, Locale)
.locale
- The locale to useprotected Number convertToNumber(String value, Class<? extends Number> targetType, Locale locale) throws Converter.ConversionException
getFormat(Locale)
.value
- The value to convertlocale
- The locale to use for conversionConversionException
- If there was a problem converting the valueConverter.ConversionException
public String convertToPresentation(T value, Class<? extends String> targetType, 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<String,T>
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 Class<String> getPresentationType()
Converter
Converter.convertToModel(Object, Class, Locale)
.getPresentationType
in interface Converter<String,T>
Copyright © 2021 Vaadin Ltd. All rights reserved.