T
- the type of the value to extract fromE
- the type of value that will be extracted@FunctionalInterface public interface ValueExtractor<T,E> extends Remote.Function<T,E>, Remote.ToIntFunction<T>, Remote.ToLongFunction<T>, Remote.ToDoubleFunction<T>, com.oracle.coherence.common.base.CanonicallyNamed
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.
Modifier and Type | Method and 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 the
after 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 the
before
extractor to its input, and then applies this extractor to the result. |
boolean |
equals(Object o)
This instance is considered equal to parameter
o when
both have same non-null getCanonicalName() . |
E |
extract(T target)
Extract the value from the passed object.
|
default ValueExtractor<T,E> |
fromKey()
Obtain a version of this
ValueExtractor that targets an entry's key. |
default String |
getCanonicalName()
Return the canonical name for this extractor.
|
default int |
getTarget()
Return
AbstractExtractor.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.
|
andThen, compose
E extract(T target)
target
- the object to extract the value fromClassCastException
- 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 messagedefault int getTarget()
AbstractExtractor.VALUE
.AbstractExtractor.VALUE
default String getCanonicalName()
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 named fooBar
,
and would have fooBar
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
or
PofExtractor(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
.
getCanonicalName
in interface com.oracle.coherence.common.base.CanonicallyNamed
null
default int applyAsInt(T value)
applyAsInt
in interface ToIntFunction<T>
default long applyAsLong(T value)
applyAsLong
in interface ToLongFunction<T>
default double applyAsDouble(T value)
applyAsDouble
in interface ToDoubleFunction<T>
boolean equals(Object o)
o
when
both have same non-null getCanonicalName()
.
Note: Fall back to implementation specific equals/hashCode when
both canonical names are null
.
int hashCode()
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
.
static <T> ValueExtractor<T,T> identity()
static <T,E> ValueExtractor<T,E> identityCast()
T
- the type of the input objects to the functionE
- the type of the output objects to the functionstatic <T,E> ValueExtractor<T,E> of(ValueExtractor<T,E> extractor)
This method is helpful whenever a lambda-based extractors need to be
composed using compose
or
andThen
method, as it eliminates the
need for casting or intermediate variables.
For example, instead of writing
((ValueExtractor<Person, Address>) Person::getAddress).andThen(Address::getState)or
ValueExtractor<Person, Address> addressExtractor = Person::getAddress; addressExtractor.andThen(Address::getState)it allows you to achieve the same goal by simply calling
ValueExtractor.of(Person::getAddress).andThen(Address::getState)
T
- the type of the value to extract fromE
- the type of value that will be extractedextractor
- the extractor to returnextractor
default <V> ValueExtractor<V,E> compose(ValueExtractor<? super V,? extends T> before)
before
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.V
- the type of input to the before
extractor, and
to the composed extractorbefore
- the extractor to apply before this extractor is appliedbefore
extractor and then applies this extractorNullPointerException
- if the passed extractor is nullandThen(ValueExtractor)
default <V> ValueExtractor<T,V> andThen(ValueExtractor<? super E,? extends V> after)
after
extractor to the result. If
evaluation of either extractor throws an exception, it is relayed to
the caller of the composed extractor.V
- the type of output of the after
extractor, and of
the composed extractorafter
- the extractor to apply after this extractor is appliedafter
extractorNullPointerException
- if the passed extractor is nullcompose(ValueExtractor)
default ValueExtractor<T,E> fromKey()
ValueExtractor
that targets an entry's key.ValueExtractor
that targets an entry's key