public interface ListDelimiterHandler
Definition of an interface that controls the handling of list delimiters in configuration properties.
AbstractConfiguration
supports list delimiters in property values. If such a
delimiter is found, the value actually contains multiple values and has to be
split. This is useful for instance for
PropertiesConfiguration
: properties files that have to be compatible with
the java.util.Properties
class cannot have multiple occurrences of a
single property key, therefore a different storage scheme for multi-valued
properties is needed. A possible storage scheme could look as follows:
myProperty=value1,value2,value3
Here a comma is used as list delimiter. When parsing this property (and using
a corresponding ListDelimiterHandler
implementation) the string value
is split, and three values are added for the property key.
A ListDelimiterHandler
knows how to parse and to escape property
values. It is called by concrete Configuration
implementations when
they have to deal with properties with multiple values.
Modifier and Type | Field and Description |
---|---|
static ValueTransformer |
NOOP_TRANSFORMER
A specialized
ValueTransformer implementation which does no
transformation. |
Modifier and Type | Method and Description |
---|---|
Object |
escape(Object value,
ValueTransformer transformer)
Escapes the specified single value object.
|
Object |
escapeList(List<?> values,
ValueTransformer transformer)
Escapes all values in the given list and concatenates them to a single
string.
|
Iterable<?> |
parse(Object value)
Parses the specified value for list delimiters and splits it if
necessary.
|
Collection<String> |
split(String s,
boolean trim)
Splits the specified string at the list delimiter and returns a
collection with all extracted components.
|
static final ValueTransformer NOOP_TRANSFORMER
ValueTransformer
implementation which does no
transformation. The transformValue()
method just returns the
passed in object without changes. This instance can be used by
configurations which do not require additional encoding.Iterable<?> parse(Object value)
Iterable
. It is the
responsibility of this method to return an Iterable
which
contains all extracted values.value
- the value to be parsedIterable
allowing access to all extracted valuesCollection<String> split(String s, boolean trim)
trim
flag determines
whether each extracted component should be trimmed. This typically makes
sense as the list delimiter may be surrounded by whitespace. However,
there may be specific use cases in which automatic trimming is not
desired.s
- the string to be splittrim
- a flag whether each component of the string is to be trimmedObject escape(Object value, ValueTransformer transformer)
value
- the value to be escapedtransformer
- a ValueTransformer
for an additional encoding
(must not be null)Object escapeList(List<?> values, ValueTransformer transformer)
values
- the list with all the values to be converted to a single
valuetransformer
- a ValueTransformer
for an additional encoding
(must not be null)Copyright © 2001–2020 The Apache Software Foundation. All rights reserved.