public final class ValueFormatters extends Object
ValueFormatters.ToStringConverter
Function
that convert objects to String
.
They can be applied to any Object
but will restrict the types they actually
convert by filtering and defaulting to String.valueOf(Object)
.
Also defines ValueFormatters.Extractor
BiFunction
that extract multiple elements from
containers and applies a Function
(most probably a ValueFormatters.ToStringConverter
)
to its elements, reforming a complete String
representation. Again, this matches
on at least a given Class
and potentially an additional Predicate
.
An additional static utility method convertVarArgs(ToStringConverter, Collection, Object...)
can
be used to apply such functions and to varargs.
Modifier and Type | Class and Description |
---|---|
static interface |
ValueFormatters.Extractor<CONTAINER>
An extractor of data wrapped in a
BiFunction aiming at producing a customized String
representation of a container type and its contained elements, each element being
potentially itself converted to String using a ValueFormatters.ToStringConverter :
it only considers specific container types, see ValueFormatters.Extractor.getTargetClass()
it can further filter these container instances using ValueFormatters.Extractor.matches(Object)
it can be applied to arbitrary objects, as it will default to String.valueOf(Object)
on non-matching containers
it can apply a ValueFormatters.ToStringConverter to the content, passed as the second
parameter of the BiFunction
it reconstructs the String representation of the container by
exploding it and then joining
it with {#code ", "} delimiter, as well as custom ValueFormatters.Extractor.prefix(Object) and ValueFormatters.Extractor.suffix(Object)
|
static interface |
ValueFormatters.ToStringConverter
|
Modifier and Type | Field and Description |
---|---|
static ValueFormatters.ToStringConverter |
DURATION_CONVERTER
Default
Duration ValueFormatters.ToStringConverter that removes the PT prefix and
switches to lower case . |
Modifier and Type | Method and Description |
---|---|
static <T> ValueFormatters.Extractor<T[]> |
arrayExtractor(Class<T[]> arrayClass)
Default array extractor that use the
[CONVERTED1, CONVERTED2]
representation. |
static ValueFormatters.ToStringConverter |
filtering(Predicate<Object> predicate,
Function<Object,String> anyToString)
|
static <T> ValueFormatters.ToStringConverter |
forClass(Class<T> tClass,
Function<T,String> tToString)
|
static <T> ValueFormatters.ToStringConverter |
forClassMatching(Class<T> tClass,
Predicate<T> tPredicate,
Function<T,String> tToString)
|
static ValueFormatters.Extractor<Iterable> |
iterableExtractor()
Default
Iterable extractor that use the [CONVERTED1, CONVERTED2]
representation. |
static ValueFormatters.Extractor<Signal> |
signalExtractor()
|
public static final ValueFormatters.ToStringConverter DURATION_CONVERTER
Duration
ValueFormatters.ToStringConverter
that removes the PT prefix and
switches to lower case
.public static <T> ValueFormatters.ToStringConverter forClass(Class<T> tClass, Function<T,String> tToString)
public static <T> ValueFormatters.ToStringConverter forClassMatching(Class<T> tClass, Predicate<T> tPredicate, Function<T,String> tToString)
Class
and filters
based on a provided Predicate
. All objects of said class that additionally
pass the Predicate
are converted to String
using the provided
conversion Function
.T
- the generic type of the matching objectstClass
- the Class
to converttPredicate
- the Predicate
to further filter what to convert to stringtToString
- the String
conversion Function
for objects of that class matching the predicatepublic static ValueFormatters.ToStringConverter filtering(Predicate<Object> predicate, Function<Object,String> anyToString)
public static ValueFormatters.Extractor<Signal> signalExtractor()
Signal
extractor that unwraps only onNext
.
These Signal
instances have a Signal representation like so: "onNext(CONVERTED)"
.Signal
extractorpublic static ValueFormatters.Extractor<Iterable> iterableExtractor()
Iterable
extractor that use the [CONVERTED1, CONVERTED2]
representation.Iterable
extractorpublic static <T> ValueFormatters.Extractor<T[]> arrayExtractor(Class<T[]> arrayClass)
[CONVERTED1, CONVERTED2]
representation.T
- the type of the arrayarrayClass
- the Class
representing the array type