CONTAINER
- the type of containerpublic static interface ValueFormatters.Extractor<CONTAINER> extends Predicate<Object>, BiFunction<Object,Function<Object,String>,String>
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
:
getTargetClass()
matches(Object)
String.valueOf(Object)
on non-matching containersValueFormatters.ToStringConverter
to the content, passed as the second
parameter of the BiFunction
String
representation of the container by
exploding
it and then joining
it with {#code ", "} delimiter, as well as custom prefix(Object)
and suffix(Object)
Modifier and Type | Method and Description |
---|---|
default String |
apply(Object target,
Function<Object,String> contentFormatter)
Given an arbitrary object and a
ValueFormatters.ToStringConverter , if the object passes
the test(Object) , extract elements from it and convert them using the
ValueFormatters.ToStringConverter , joining the result together to obtain a customized
String representation of both the container and its contents. |
Stream<Object> |
explode(CONTAINER original)
Explode the container into a
Stream of Object , each of which
is a candidate for individual String conversion by a ValueFormatters.ToStringConverter
when applied as a BiFunction . |
Class<CONTAINER> |
getTargetClass()
Return the targeted container
Class . |
default boolean |
matches(CONTAINER value)
An additional test to perform on a matching container to further decide to convert
it or not.
|
default String |
prefix(CONTAINER original)
Return the prefix to use in the container's
String representation, given
the original container. |
default String |
suffix(CONTAINER original)
Return the suffix to use in the container's
String representation, given
the original container. |
default boolean |
test(Object o)
Test if an object is a container that can be extracted and converted by this
ValueFormatters.Extractor . |
andThen
Class<CONTAINER> getTargetClass()
Class
. The BiFunction
shouldn't be
applied to objects that are not of that class, although it will default to using
String.valueOf(Object)
on them. This verification is included in test(Object)
.Class
default boolean matches(CONTAINER value)
BiFunction
shouldn't be applied to container that do not
match that predicate, although it will default to using String.valueOf(Object)
on them. This verification is included in test(Object)
.
Defaults to always matching instances of the target Class
.
value
- the candidate containerdefault String prefix(CONTAINER original)
String
representation, given
the original container.
Defaults to "["
.
original
- the original containerdefault String suffix(CONTAINER original)
String
representation, given
the original container.
Defaults to "]"
.
original
- the original containerStream<Object> explode(CONTAINER original)
Stream
of Object
, each of which
is a candidate for individual String
conversion by a ValueFormatters.ToStringConverter
when applied as a BiFunction
.original
- the container to extract contents fromStream
of elements contained in the containerdefault boolean test(Object o)
ValueFormatters.Extractor
. Defaults to testing getTargetClass()
and matches(Object)
.
The BiFunction
shouldn't be applied to objects that do not match this
test, although it will default to using String.valueOf(Object)
on them.@Nullable default String apply(Object target, Function<Object,String> contentFormatter)
ValueFormatters.ToStringConverter
, if the object passes
the test(Object)
, extract elements from it and convert them using the
ValueFormatters.ToStringConverter
, joining the result together to obtain a customized
String
representation of both the container and its contents.
Any object that doesn't match this ValueFormatters.Extractor
is naively transformed
using String.valueOf(Object)
, use test(Object)
to avoid that
when choosing between multiple ValueFormatters.Extractor
.apply
in interface BiFunction<Object,Function<Object,String>,String>
target
- the arbitrary object to potentially convert.contentFormatter
- the ValueFormatters.ToStringConverter
to apply on each element
contained in the targetString
representation of the target, customized as needed