Class StringToCollectionConverter
- java.lang.Object
-
- com.vaadin.data.util.converter.StringToCollectionConverter
-
- All Implemented Interfaces:
Converter<String,Collection>,Serializable
public class StringToCollectionConverter extends Object implements Converter<String,Collection>
A converter that converts fromStringtoCollectionof 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 andStringfor token types. Other constructors allow to configure delimiter and token types.- Since:
- 7.5.0
- Author:
- Vaadin Ltd
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceStringToCollectionConverter.CollectionFactoryCollection factory.static classStringToCollectionConverter.DefaultCollectionFactoryDefault collection factory implementation.-
Nested classes/interfaces inherited from interface com.vaadin.data.util.converter.Converter
Converter.ConversionException
-
-
Constructor Summary
Constructors Constructor Description StringToCollectionConverter()Creates 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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description CollectionconvertToModel(String value, Class<? extends Collection> targetType, Locale locale)Converts the given value from target type to source type.StringconvertToPresentation(Collection value, Class<? extends String> targetType, Locale locale)Converts the given value from source type to target type.Class<Collection>getModelType()The source type of the converter.Class<String>getPresentationType()The target type of the converter.
-
-
-
Constructor Detail
-
StringToCollectionConverter
public StringToCollectionConverter()
Creates converter with", "as delimiter andStringas token model type in collection.
-
StringToCollectionConverter
public StringToCollectionConverter(String delimiter)
Creates converter with givendelimiterandStringas token model type in collection.- Parameters:
delimiter- custom delimiter
-
StringToCollectionConverter
public StringToCollectionConverter(Converter<String,?> tokenConverter, Class<?> tokenType)
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:
tokenConverter- converter for tokentokenType- expected token model typedelimiter- delimiter in presentation string
-
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:
tokenConverter- converter for tokentokenType- expected token model typedelimiter- delimiter in presentation stringfactory- factory to create resulting collection
-
-
Method Detail
-
getModelType
public Class<Collection> 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
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,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
-
-