Class StringToCollectionConverter
- All Implemented Interfaces:
Converter<String,,Collection> com.vaadin.flow.data.converter.Converter<String,,Collection> Serializable
String to Collection of tokens
and back.
Allows to break a string into tokens using delimiter. Each token can be converted to its own model using provided converter.
Default constructor uses ", " as delimiter string and
String for token types. Other constructors allow to configure
delimiter and token types.
- Author:
- Vaadin Ltd
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceCollection factory.static classDefault collection factory implementation.Nested classes/interfaces inherited from interface com.vaadin.featurepack.data.converter.Converter
Converter.ConversionException -
Constructor Summary
ConstructorsConstructorDescriptionCreates converter with", "as delimiter andStringas token model type in collection.StringToCollectionConverter(Converter<String, ?> tokenConverter, Class<?> tokenType) Creates converter with giventokenConverterfor convert tokens and expectedtokenType.StringToCollectionConverter(String delimiter) Creates converter with givendelimiterandStringas token model type in collection.StringToCollectionConverter(String delimiter, Converter<String, ?> tokenConverter, Class<?> tokenClass) Creates converter with giventokenConverterfor convert tokens and expectedtokenType.StringToCollectionConverter(String delimiter, Converter<String, ?> tokenConverter, Class<?> tokenClass, StringToCollectionConverter.CollectionFactory factory) Creates converter with giventokenConverterfor convert tokens and expectedtokenType. -
Method Summary
Modifier and TypeMethodDescriptionconvertToModel(String value, Class<? extends Collection> targetType, Locale locale) Converts the given value from target type to source type.convertToPresentation(Collection value, Class<? extends String> targetType, Locale locale) Converts the given value from source type to target type.The source type of the converter.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, convertToPresentationMethods inherited from interface com.vaadin.flow.data.converter.Converter
chain
-
Constructor Details
-
StringToCollectionConverter
public StringToCollectionConverter()Creates converter with", "as delimiter andStringas token model type in collection. -
StringToCollectionConverter
Creates converter with givendelimiterandStringas token model type in collection.- Parameters:
delimiter- custom delimiter
-
StringToCollectionConverter
Creates converter with giventokenConverterfor convert tokens and expectedtokenType.If
tokenConverteris null then no conversation is done andStringis used as token type in resulting model collection.- Parameters:
tokenConverter- converter for tokentokenType- expected token model type
-
StringToCollectionConverter
public StringToCollectionConverter(String delimiter, Converter<String, ?> tokenConverter, Class<?> tokenClass) Creates converter with giventokenConverterfor convert tokens and expectedtokenType.If
tokenConverteris null then no conversation is done andStringis used as token type in resulting model collection.- Parameters:
delimiter- delimiter in presentation stringtokenConverter- converter for tokentokenType- expected token model type
-
StringToCollectionConverter
public StringToCollectionConverter(String delimiter, Converter<String, ?> tokenConverter, Class<?> tokenClass, StringToCollectionConverter.CollectionFactory factory) Creates converter with giventokenConverterfor convert tokens and expectedtokenType.If
tokenConverteris null then no conversation is done andStringis used as token type in resulting model collection.- Parameters:
delimiter- delimiter in presentation stringtokenConverter- converter for tokenfactory- factory to create resulting collectiontokenType- expected token model type
-
-
Method Details
-
getModelType
Description copied from interface:ConverterThe source type of the converter. Values of this type can be passed toConverter.convertToPresentation(Object, Class, Locale).- Specified by:
getModelTypein interfaceConverter<String,Collection> - Returns:
- The source type
-
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,Collection> - Returns:
- The target type
-
convertToModel
public Collection convertToModel(String value, Class<? extends Collection> targetType, Locale locale) throws Converter.ConversionException Description copied from interface:ConverterConverts the given value from target type to source 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:
convertToModelin interfaceConverter<String,Collection> - 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
-
convertToPresentation
public String convertToPresentation(Collection 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,Collection> - 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
-