Package reactor.test
Interface ValueFormatters.Extractor<CONTAINER>
- Type Parameters:
CONTAINER- the type of container
- Enclosing class:
- ValueFormatters
public static interface ValueFormatters.Extractor<CONTAINER>
extends Predicate<Object>, BiFunction<Object,Function<Object,String>,String>
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
getTargetClass() - it can further filter these container instances using
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.ToStringConverterto the content, passed as the second parameter of theBiFunction - it reconstructs the
Stringrepresentation of the container byexplodingit and thenjoiningit with {#code ", "} delimiter, as well as customprefix(Object)andsuffix(Object)
-
Method Summary
Modifier and TypeMethodDescriptionGiven an arbitrary object and aValueFormatters.ToStringConverter, if the object passes thetest(Object), extract elements from it and convert them using theValueFormatters.ToStringConverter, joining the result together to obtain a customizedStringrepresentation of both the container and its contents.Explode the container into aStreamofObject, each of which is a candidate for individualStringconversion by aValueFormatters.ToStringConverterwhen applied as aBiFunction.Return the targeted containerClass.default booleanAn additional test to perform on a matching container to further decide to convert it or not.default StringReturn the prefix to use in the container'sStringrepresentation, given the original container.default StringReturn the suffix to use in the container'sStringrepresentation, given the original container.default booleanTest if an object is a container that can be extracted and converted by thisValueFormatters.Extractor.Methods inherited from interface java.util.function.BiFunction
andThen
-
Method Details
-
getTargetClass
Return the targeted containerClass. TheBiFunctionshouldn't be applied to objects that are not of that class, although it will default to usingString.valueOf(Object)on them. This verification is included intest(Object).- Returns:
- the target container
Class
-
matches
An additional test to perform on a matching container to further decide to convert it or not. TheBiFunctionshouldn't be applied to container that do not match that predicate, although it will default to usingString.valueOf(Object)on them. This verification is included intest(Object).Defaults to always matching instances of the
target Class.- Parameters:
value- the candidate container- Returns:
- true if it can be extracted and converted, false otherwise
-
prefix
Return the prefix to use in the container'sStringrepresentation, given the original container.Defaults to
"[".- Parameters:
original- the original container- Returns:
- the prefix to use
-
suffix
Return the suffix to use in the container'sStringrepresentation, given the original container.Defaults to
"]".- Parameters:
original- the original container- Returns:
- the suffix to use
-
explode
Explode the container into aStreamofObject, each of which is a candidate for individualStringconversion by aValueFormatters.ToStringConverterwhen applied as aBiFunction.- Parameters:
original- the container to extract contents from- Returns:
- the
Streamof elements contained in the container
-
test
Test if an object is a container that can be extracted and converted by thisValueFormatters.Extractor. Defaults to testinggetTargetClass()andmatches(Object). TheBiFunctionshouldn't be applied to objects that do not match this test, although it will default to usingString.valueOf(Object)on them. -
apply
Given an arbitrary object and aValueFormatters.ToStringConverter, if the object passes thetest(Object), extract elements from it and convert them using theValueFormatters.ToStringConverter, joining the result together to obtain a customizedStringrepresentation of both the container and its contents. Any object that doesn't match thisValueFormatters.Extractoris naively transformed usingString.valueOf(Object), usetest(Object)to avoid that when choosing between multipleValueFormatters.Extractor.- Specified by:
applyin interfaceBiFunction<Object,Function<Object, String>, String> - Parameters:
target- the arbitrary object to potentially convert.contentFormatter- theValueFormatters.ToStringConverterto apply on each element contained in the target- Returns:
- the
Stringrepresentation of the target, customized as needed
-