Package com.vaadin.flow.data.converter
Class StringToLongConverter
- java.lang.Object
-
- com.vaadin.flow.data.converter.AbstractStringToNumberConverter<Long>
-
- com.vaadin.flow.data.converter.StringToLongConverter
-
- All Implemented Interfaces:
Converter<String,Long>
,Serializable
public class StringToLongConverter extends AbstractStringToNumberConverter<Long>
A converter that converts fromString
toLong
and back. Uses the given locale and aNumberFormat
instance for formatting and parsing.Override and overwrite
getFormat(Locale)
to use a different format.- Since:
- 1.0
- Author:
- Vaadin Ltd
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description StringToLongConverter(ErrorMessageProvider errorMessageProvider)
Creates a new converter instance with the given error message provider.StringToLongConverter(Long emptyValue, ErrorMessageProvider errorMessageProvider)
Creates a new converter instance with the given presentation value for empty string and error message provider.StringToLongConverter(Long emptyValue, String errorMessage)
Creates a new converter instance with the given presentation value for empty string and error message.StringToLongConverter(String errorMessage)
Creates a new converter instance with the given error message.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Result<Long>
convertToModel(String value, ValueContext context)
Converts the given value from presentation type to model type.protected NumberFormat
getFormat(Locale locale)
Returns the format used byConverter.convertToPresentation(Object, ValueContext)
andconvertToModel(String, ValueContext)
.-
Methods inherited from class com.vaadin.flow.data.converter.AbstractStringToNumberConverter
convertToNumber, convertToPresentation, getErrorMessage
-
-
-
-
Constructor Detail
-
StringToLongConverter
public StringToLongConverter(String errorMessage)
Creates a new converter instance with the given error message. Empty strings are converted tonull
.- Parameters:
errorMessage
- the error message to use if conversion fails
-
StringToLongConverter
public StringToLongConverter(Long emptyValue, String errorMessage)
Creates a new converter instance with the given presentation value for empty string and error message.- Parameters:
emptyValue
- the presentation value to return when converting an empty string, may benull
errorMessage
- the error message to use if conversion fails
-
StringToLongConverter
public StringToLongConverter(ErrorMessageProvider errorMessageProvider)
Creates a new converter instance with the given error message provider. Empty strings are converted tonull
.- Parameters:
errorMessageProvider
- the error message provider to use if conversion fails
-
StringToLongConverter
public StringToLongConverter(Long emptyValue, ErrorMessageProvider errorMessageProvider)
Creates a new converter instance with the given presentation value for empty string and error message provider.- Parameters:
emptyValue
- the presentation value to return when converting an empty string, may benull
errorMessageProvider
- the error message provider to use if conversion fails
-
-
Method Detail
-
getFormat
protected NumberFormat getFormat(Locale locale)
Returns the format used byConverter.convertToPresentation(Object, ValueContext)
andconvertToModel(String, ValueContext)
.- Overrides:
getFormat
in classAbstractStringToNumberConverter<Long>
- Parameters:
locale
- The locale to use- Returns:
- A NumberFormat instance
-
convertToModel
public Result<Long> convertToModel(String value, ValueContext context)
Description copied from interface:Converter
Converts the given value from presentation type to model type.A converter can optionally use locale to do the conversion.
- Parameters:
value
- The value to convert. Can be nullcontext
- The value context for the conversion.- Returns:
- The converted value compatible with the source type
-
-