public abstract class AbstractListDelimiterHandler extends Object implements ListDelimiterHandler
An abstract base class for concrete ListDelimiterHandler
implementations.
This base class provides a fully functional implementation for parsing a value object which can deal with different cases like collections, arrays, iterators, etc. This logic is typically needed by every concrete subclass. Other methods are partly implemented handling special corner cases like null values; concrete subclasses do not have do implement the corresponding checks.
NOOP_TRANSFORMER
Constructor and Description |
---|
AbstractListDelimiterHandler() |
Modifier and Type | Method and Description |
---|---|
Object |
escape(Object value,
ValueTransformer transformer)
Escapes the specified single value object.
|
protected abstract String |
escapeString(String s)
Escapes the specified 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.
|
protected abstract Collection<String> |
splitString(String s,
boolean trim)
Actually splits the passed in string which is guaranteed to be not null.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
escapeList
public AbstractListDelimiterHandler()
public Iterable<?> parse(Object value)
Iterable
. It is the responsibility of this
method to return an Iterable
which contains all extracted values. Depending on the type of the passed in object the following things happen:
split()
method.Iterable
interface, the corresponding Iterator
is obtained, and
contained elements are added to the resulting iteration.Iterable
objects.parse
in interface ListDelimiterHandler
value
- the value to be parsedIterable
allowing access to all extracted valuespublic Collection<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. This implementation handles the case that the passed in string is null. In this case, an empty
collection is returned. Otherwise, this method delegates to splitString(String, boolean)
.split
in interface ListDelimiterHandler
s
- the string to be splittrim
- a flag whether each component of the string is to be trimmedpublic Object escape(Object value, ValueTransformer transformer)
escapeString(String)
, otherwise no escaping is performed. Eventually, the passed in transformer is invoked
so that additional encoding can be performed.escape
in interface ListDelimiterHandler
value
- the value to be escapedtransformer
- a ValueTransformer
for an additional encoding (must not be null)protected abstract Collection<String> splitString(String s, boolean trim)
split()
method. Here the actual splitting logic has to be implemented.s
- the string to be split (not null)trim
- a flag whether the single components have to be trimmedprotected abstract String escapeString(String s)
escape()
if the passed in object is a string. Concrete
subclasses have to implement their specific escaping logic here, so that the list delimiters they support are
properly escaped.s
- the string to be escaped (not null)Copyright © 2001–2022 The Apache Software Foundation. All rights reserved.