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
,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.
Important Note: all classes that implement ValueExtractor interface
must explicitly implement the hashCode()
and equals()
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. Both hashCode()
, equals()
and CanonicallyNamed.getCanonicalName()
should
consistently be symmetric between implementations.
- Author:
- cp/gg 2002.10.31, as 2014.06.22
-
Method Summary
Modifier and TypeMethodDescriptiondefault <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
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
This instance is considered equal to parametero
when both have same non-nullgetCanonicalName()
.Extract the value from the passed object.static <T,
E> ValueExtractor <T, E> Return aValueExtractor
for the specifiedMethod
.default ValueExtractor
<T, E> fromKey()
Obtain a version of thisValueExtractor
that targets an entry's key.default String
Return the canonical name for this extractor.default int
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> 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 Details
-
extract
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
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
-
apply
-
applyAsInt
- Specified by:
applyAsInt
in interfaceToIntFunction<T>
-
applyAsLong
- Specified by:
applyAsLong
in interfaceToLongFunction<T>
-
applyAsDouble
- Specified by:
applyAsDouble
in interfaceToDoubleFunction<T>
-
equals
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
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
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
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
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
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
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:
-
fromKey
Obtain a version of thisValueExtractor
that targets an entry's key.- Returns:
- a version of this
ValueExtractor
that targets an entry's key
-