Class AbstractCollectionConverter<T extends Collection>

  • Type Parameters:
    T - the type in which the provided value has to be converted
    All Implemented Interfaces:
    Converter<T>
    Direct Known Subclasses:
    AbstractSetConverter

    public abstract class AbstractCollectionConverter<T extends Collection>
    extends AbstractConverter<T>
    Base class for all Collection converters.
    Since:
    5.2M1
    Version:
    $Id: 7612d78572c144e5bfcc74d5fee6d93c0a6409ee $
    • Constructor Detail

      • AbstractCollectionConverter

        public AbstractCollectionConverter()
    • Method Detail

      • getConverterManager

        public ConverterManager getConverterManager()
        Returns:
        the converter manager.
      • setDelimiters

        public void setDelimiters​(String delimiter)
        Set the delimiter to be used for parsing a delimited String.
        Parameters:
        delimiter - The delimiter [default ", "] since 3.2M3
      • getDelimiters

        public String getDelimiters()
        Returns:
        the delimiters
      • convertToType

        protected <G extends T> G convertToType​(Type targetType,
                                                Object value)
        Description copied from class: AbstractConverter
        Convert the input object into an output object of the specified type.

        Typical implementations will provide a minimum of String --> type conversion.

        Overrides:
        convertToType in class AbstractConverter<T extends Collection>
        Type Parameters:
        G - the type in which the provided value has o be converted
        Parameters:
        targetType - Data type to which this value should be converted.
        value - The input value to be converted.
        Returns:
        The converted value.
      • fromIterable

        protected <G extends T> G fromIterable​(Type targetType,
                                               Iterable<?> values,
                                               Type elementType)
        Type Parameters:
        G - the type in which the provided value has to be converted
        Parameters:
        targetType - Data type to which this value should be converted.
        values - the values to be converted (or not) to the target element type
        elementType - the generic type
        Returns:
        List of parsed elements.
        Throws:
        ConversionException - if the syntax of value is not syntactically valid
        NullPointerException - if value is null
        Since:
        7.4.6, 8.4.1, 9.0RC1
      • fromArray

        protected <G extends T> G fromArray​(Type targetType,
                                            Object values,
                                            Type elementType)
        Type Parameters:
        G - the type in which the provided value has to be converted
        Parameters:
        targetType - Data type to which this value should be converted.
        values - the values to be converted (or not) to the target element type
        elementType - the generic type
        Returns:
        List of parsed elements.
        Throws:
        ConversionException - if the syntax of value is not syntactically valid
        NullPointerException - if value is null
        Since:
        7.4.6, 8.4.1, 9.0RC1
      • parseElements

        protected <G extends T> G parseElements​(Type targetType,
                                                String value,
                                                Type elementType)

        Parse an incoming String of the form similar to an array initializer in the Java language into a List individual Strings for each element, according to the following rules.

        • The string is expected to be a comma-separated list of values.
        • The string may optionally have matching '{' and '}' delimiters around the list.
        • Whitespace before and after each element is stripped.
        • Elements in the list may be delimited by single or double quotes. Within a quoted elements, the normal Java escape sequences are valid.
        Type Parameters:
        G - the type in which the provided value has to be converted
        Parameters:
        targetType - Data type to which this value should be converted.
        value - String value to be parsed
        elementType - the generic type
        Returns:
        List of parsed elements.
        Throws:
        ConversionException - if the syntax of value is not syntactically valid
        NullPointerException - if value is null
      • newCollection

        protected <G extends TT newCollection​(Type targetType)
        Type Parameters:
        G - the type of the collection to create
        Parameters:
        targetType - the type of the collection to create
        Returns:
        the modifiable Collection to fill
      • convertToString

        protected String convertToString​(T value)
        Description copied from class: AbstractConverter
        Convert the input object into a String.

        N.B.This implementation simply uses the value's toString() method and should be overridden if a more sophisticated mechanism for conversion to a String is required.

        Overrides:
        convertToString in class AbstractConverter<T extends Collection>
        Parameters:
        value - The input value to be converted.
        Returns:
        the converted String value.