Interface ValueExtractor<T,E>
-
- Type Parameters:
T
- the type of the value to extract fromE
- the type of value that will be extracted
- All Superinterfaces:
CanonicallyNamed
,Function<T,E>
,Remote.Function<T,E>
,Remote.ToDoubleFunction<T>
,Remote.ToIntFunction<T>
,Remote.ToLongFunction<T>
,Serializable
,ToDoubleFunction<T>
,ToIntFunction<T>
,ToLongFunction<T>
- All Known Subinterfaces:
IndexAwareExtractor<T,E>
- All Known Implementing Classes:
AbstractCompositeExtractor
,AbstractExtractor
,ChainedExtractor
,ChainedFragmentExtractor
,ComparisonValueExtractor
,ConditionalExtractor
,DeserializationAccelerator
,EntryExtractor
,FragmentExtractor
,IdentityExtractor
,KeyExtractor
,MultiExtractor
,MvelExtractor
,NullImplementation.NullValueExtractor
,PartitionedJCacheStatistics.CacheStatisticsExtractor
,PofExtractor
,PropertySet
,ReflectionExtractor
,ScriptValueExtractor
,UniversalExtractor
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
@FunctionalInterface public interface ValueExtractor<T,E> extends Remote.Function<T,E>, Remote.ToIntFunction<T>, Remote.ToLongFunction<T>, Remote.ToDoubleFunction<T>, CanonicallyNamed
ValueExtractor is used to both extract values (for example, for sorting or filtering) from an object, and to provide an identity for that extraction.Important Note: all classes that implement ValueExtractor interface must explicitly implement the
hashCode()
andequals()
methods in a way that is based solely on the object's serializable state. Additionally,CanonicallyNamed
provides a means for ValueExtractor implementations to suggest two implementations extract the same logical value with different implementations. BothhashCode()
,equals()
andCanonicallyNamed.getCanonicalName()
should consistently be symmetric between implementations.- Author:
- cp/gg 2002.10.31, as 2014.06.22
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default <V> ValueExtractor<T,V>
andThen(ValueExtractor<? super E,? extends V> after)
Returns a composed extractor that first applies this extractor to its input, and then applies theafter
extractor to the result.default E
apply(T value)
default double
applyAsDouble(T value)
default int
applyAsInt(T value)
default long
applyAsLong(T value)
default <V> ValueExtractor<V,E>
compose(ValueExtractor<? super V,? extends T> before)
Returns a composed extractor that first applies thebefore
extractor to its input, and then applies this extractor to the result.boolean
equals(Object o)
This instance is considered equal to parametero
when both have same non-nullgetCanonicalName()
.E
extract(T target)
Extract the value from the passed object.static <T,E>
ValueExtractor<T,E>forMethod(Method method)
Return aValueExtractor
for the specifiedMethod
.default ValueExtractor<T,E>
fromKey()
Obtain a version of thisValueExtractor
that targets an entry's key.default String
getCanonicalName()
Return the canonical name for this extractor.default int
getTarget()
ReturnAbstractExtractor.VALUE
.int
hashCode()
Return the hashCode for this extractor.static <T> ValueExtractor<T,T>
identity()
Returns an extractor that always returns its input argument.static <T,E>
ValueExtractor<T,E>identityCast()
Returns an extractor that casts its input argument.static <T,E>
ValueExtractor<T,E>of(ValueExtractor<T,E> extractor)
Helper method to allow composition/chaining of extractors.-
Methods inherited from interface com.tangosol.util.function.Remote.Function
andThen, compose
-
-
-
-
Method Detail
-
extract
E extract(T target)
Extract the value from the passed object. The returned value may be null. For intrinsic types, the returned value is expected to be a standard wrapper type in the same manner that reflection works; for example, int would be returned as a java.lang.Integer.- Parameters:
target
- the object to extract the value from- Returns:
- the extracted value; null is an acceptable value
- Throws:
ClassCastException
- if this ValueExtractor is incompatible with the passed object to extract a value from and the implementation requires the passed object to be of a certain typeWrapperException
- if this ValueExtractor encounters an exception in the course of extracting the valueIllegalArgumentException
- if this ValueExtractor cannot handle the passed object for any other reason; an implementor should include a descriptive message
-
getTarget
default int getTarget()
ReturnAbstractExtractor.VALUE
.- Returns:
AbstractExtractor.VALUE
- Since:
- 12.2.1.4
-
getCanonicalName
default String getCanonicalName()
Return the canonical name for this extractor.A canonical name uniquely identifies what is to be extracted, but not how it is to be extracted. Thus two different extractor implementations with the same non-null canonical name are considered to be equal, and should reflect this in their implementations of hashCode and equals.
Canonical names for properties are designated by their property name in camel case, for instance a Java Bean with method
getFooBar
would have a property namedfooBar
, and would havefooBar
as its canonical name.Canonical names for zero-arg method invocations are the method name followed by ().
Dots in a canonical name delimit one or more property/method accesses represented by a chaining ValueExtractor such as
ChainedExtractor
orPofExtractor(Class, PofNavigator, String)
.There is currently no canonical name format for methods which take parameters and as such they must return a canonical name of
null
.- Specified by:
getCanonicalName
in interfaceCanonicallyNamed
- Returns:
- the extractor's canonical name, or
null
-
applyAsInt
default int applyAsInt(T value)
- Specified by:
applyAsInt
in interfaceToIntFunction<T>
-
applyAsLong
default long applyAsLong(T value)
- Specified by:
applyAsLong
in interfaceToLongFunction<T>
-
applyAsDouble
default double applyAsDouble(T value)
- Specified by:
applyAsDouble
in interfaceToDoubleFunction<T>
-
equals
boolean equals(Object o)
This instance is considered equal to parametero
when both have same non-nullgetCanonicalName()
.Note: Fall back to implementation specific equals/hashCode when both canonical names are
null
.
-
hashCode
int hashCode()
Return the hashCode for this extractor.Note two extractors with the same non-null
canonical name
are expected to also have the same hashCode.Note: Fall back to implementation specific equals/hashCode when canonical name is
null
.
-
identity
static <T> ValueExtractor<T,T> identity()
Returns an extractor that always returns its input argument.- Type Parameters:
T
- the type of the input and output objects to the function- Returns:
- an extractor that always returns its input argument
-
identityCast
static <T,E> ValueExtractor<T,E> identityCast()
Returns an extractor that casts its input argument.- Type Parameters:
T
- the type of the input objects to the functionE
- the type of the output objects to the function- Returns:
- an extractor that always returns its input argument
-
of
static <T,E> ValueExtractor<T,E> of(ValueExtractor<T,E> extractor)
Helper method to allow composition/chaining of extractors.This method is helpful whenever a lambda-based extractors need to be composed using
compose
orandThen
method, as it eliminates the need for casting or intermediate variables.For example, instead of writing
((ValueExtractor<Person, Address>) Person::getAddress).andThen(Address::getState)
orValueExtractor<Person, Address> addressExtractor = Person::getAddress; addressExtractor.andThen(Address::getState)
it allows you to achieve the same goal by simply callingValueExtractor.of(Person::getAddress).andThen(Address::getState)
- Type Parameters:
T
- the type of the value to extract fromE
- the type of value that will be extracted- Parameters:
extractor
- the extractor to return- Returns:
- the specified
extractor
-
forMethod
static <T,E> ValueExtractor<T,E> forMethod(Method method)
Return aValueExtractor
for the specifiedMethod
. Themethod
specified must have a non-void return type and no parameters.- Type Parameters:
T
- the type of the value to extract fromE
- the type of value that will be extracted- Parameters:
method
- the method to create aValueExtractor
for- Returns:
- a
ValueExtractor
instance for the specified method - Throws:
IllegalArgumentException
- if themethod
has one or more arguments orvoid
return type- Since:
- 21.06
-
compose
default <V> ValueExtractor<V,E> compose(ValueExtractor<? super V,? extends T> before)
Returns a composed extractor that first applies thebefore
extractor to its input, and then applies this extractor to the result. If evaluation of either extractor throws an exception, it is relayed to the caller of the composed extractor.- Type Parameters:
V
- the type of input to thebefore
extractor, and to the composed extractor- Parameters:
before
- the extractor to apply before this extractor is applied- Returns:
- a composed extractor that first applies the
before
extractor and then applies this extractor - Throws:
NullPointerException
- if the passed extractor is null- See Also:
andThen(ValueExtractor)
-
andThen
default <V> ValueExtractor<T,V> andThen(ValueExtractor<? super E,? extends V> after)
Returns a composed extractor that first applies this extractor to its input, and then applies theafter
extractor to the result. If evaluation of either extractor throws an exception, it is relayed to the caller of the composed extractor.- Type Parameters:
V
- the type of output of theafter
extractor, and of the composed extractor- Parameters:
after
- the extractor to apply after this extractor is applied- Returns:
- a composed extractor that first applies this extractor and then
applies the
after
extractor - Throws:
NullPointerException
- if the passed extractor is null- See Also:
compose(ValueExtractor)
-
fromKey
default ValueExtractor<T,E> fromKey()
Obtain a version of thisValueExtractor
that targets an entry's key.- Returns:
- a version of this
ValueExtractor
that targets an entry's key
-
-