Class AbstractCollectionConverter<T extends Collection>
- java.lang.Object
-
- org.xwiki.properties.converter.AbstractConverter<T>
-
- org.xwiki.properties.converter.collection.AbstractCollectionConverter<T>
-
- 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 allCollection
converters.- Since:
- 5.2M1
- Version:
- $Id: 7612d78572c144e5bfcc74d5fee6d93c0a6409ee $
-
-
Field Summary
Fields Modifier and Type Field Description protected static char
QUOTECHAR
Quote char.protected static String
QUOTESTRING
Quote string.
-
Constructor Summary
Constructors Constructor Description AbstractCollectionConverter()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected String
convertToString(T value)
Convert the input object into a String.protected <G extends T>
GconvertToType(Type targetType, Object value)
Convert the input object into an output object of the specified type.protected StreamTokenizer
createStreamTokenizer(String value)
Create and initialize aStreamTokenizer
to parse the value.protected <G extends T>
GfromArray(Type targetType, Object values, Type elementType)
protected <G extends T>
GfromIterable(Type targetType, Iterable<?> values, Type elementType)
ConverterManager
getConverterManager()
String
getDelimiters()
protected <G extends T>
TnewCollection(Type targetType)
protected <G extends T>
GparseElements(Type targetType, String value, Type elementType)
Parse an incoming String of the form similar to an array initializer in the Java language into aList
individual Strings for each element, according to the following rules.void
setDelimiters(String delimiter)
Set the delimiter to be used for parsing a delimited String.-
Methods inherited from class org.xwiki.properties.converter.AbstractConverter
convert, convertToType
-
-
-
-
Field Detail
-
QUOTECHAR
protected static final char QUOTECHAR
Quote char.- See Also:
- Constant Field Values
-
QUOTESTRING
protected static final String QUOTESTRING
Quote string.- See Also:
- Constant Field Values
-
-
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 classAbstractConverter<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 typeelementType
- the generic type- Returns:
- List of parsed elements.
- Throws:
ConversionException
- if the syntax ofvalue
is not syntactically validNullPointerException
- ifvalue
isnull
- 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 typeelementType
- the generic type- Returns:
- List of parsed elements.
- Throws:
ConversionException
- if the syntax ofvalue
is not syntactically validNullPointerException
- ifvalue
isnull
- 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 parsedelementType
- the generic type- Returns:
- List of parsed elements.
- Throws:
ConversionException
- if the syntax ofvalue
is not syntactically validNullPointerException
- ifvalue
isnull
-
newCollection
protected <G extends T> T 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
-
createStreamTokenizer
protected StreamTokenizer createStreamTokenizer(String value)
Create and initialize aStreamTokenizer
to parse the value.- Parameters:
value
- the string to parse- Returns:
- the
StreamTokenizer
used to parse the string
-
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 classAbstractConverter<T extends Collection>
- Parameters:
value
- The input value to be converted.- Returns:
- the converted String value.
-
-