public final class ValueFormatters
extends java.lang.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.
限定符和类型 | 类和说明 |
---|---|
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
A generic
Object to String conversion Function which is
also a Predicate , and which only applies a custom conversion to targets that
match said Predicate . |
限定符和类型 | 字段和说明 |
---|---|
static ValueFormatters.ToStringConverter |
DURATION_CONVERTER
Default
Duration ValueFormatters.ToStringConverter that removes the PT prefix and
switches to lower case . |
限定符和类型 | 方法和说明 |
---|---|
static <T> ValueFormatters.Extractor<T[]> |
arrayExtractor(java.lang.Class<T[]> arrayClass)
Default array extractor that use the
[CONVERTED1, CONVERTED2]
representation. |
static ValueFormatters.ToStringConverter |
filtering(java.util.function.Predicate<java.lang.Object> predicate,
java.util.function.Function<java.lang.Object,java.lang.String> anyToString)
Create a value formatter that applies the given String conversion
Function
only to objects matching a given Predicate |
static <T> ValueFormatters.ToStringConverter |
forClass(java.lang.Class<T> tClass,
java.util.function.Function<T,java.lang.String> tToString)
Create a value formatter that is specific to a particular
Class , applying
the given String conversion Function provided the object is an instance of
that Class. |
static <T> ValueFormatters.ToStringConverter |
forClassMatching(java.lang.Class<T> tClass,
java.util.function.Predicate<T> tPredicate,
java.util.function.Function<T,java.lang.String> tToString)
Create a value formatter that is specific to a particular
Class and filters
based on a provided Predicate . |
static ValueFormatters.Extractor<java.lang.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(java.lang.Class<T> tClass, java.util.function.Function<T,java.lang.String> tToString)
Class
, applying
the given String conversion Function
provided the object is an instance of
that Class.T
- the generic type of the matching objectstClass
- the Class
to converttToString
- the String
conversion Function
for objects of that classpublic static <T> ValueFormatters.ToStringConverter forClassMatching(java.lang.Class<T> tClass, java.util.function.Predicate<T> tPredicate, java.util.function.Function<T,java.lang.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(java.util.function.Predicate<java.lang.Object> predicate, java.util.function.Function<java.lang.Object,java.lang.String> anyToString)
Function
only to objects matching a given Predicate
predicate
- the Predicate
used to filter objects to formatanyToString
- the String
conversion Function
(without input typing)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<java.lang.Iterable> iterableExtractor()
Iterable
extractor that use the [CONVERTED1, CONVERTED2]
representation.Iterable
extractorpublic static <T> ValueFormatters.Extractor<T[]> arrayExtractor(java.lang.Class<T[]> arrayClass)
[CONVERTED1, CONVERTED2]
representation.T
- the type of the arrayarrayClass
- the Class
representing the array type