Package com.tangosol.util
Class Extractors
java.lang.Object
com.tangosol.util.Extractors
Simple Extractor DSL.
The methods in this class are for the most part simple factory methods for
various ValueExtractor
classes, but in some cases provide additional type
safety. They also tend to make the code more readable, especially if imported
statically, so their use is strongly encouraged in lieu of direct construction
of Extractor
classes.
- Author:
- lh, hr, as, mf 2018.06.14
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T,
R> ValueExtractor <T, R> chained
(ValueExtractor<?, ?>... extractors) Returns an extractor that extracts the specified fields where extraction occurs in a chain where the result of each field extraction is the input to the next extractor.static <T,
R> ValueExtractor <T, R> Returns an extractor that extracts the specified fields where extraction occurs in a chain where the result of each field extraction is the input to the next extractor.static <T,
E> ValueExtractor <T, E> Returns an extractor that extracts the value of the specified field.static <T,
E> ValueExtractor <T, E> Returns an extractor that extracts the value of the specified field.static <T> ValueExtractor
<T, Fragment<T>> fragment
(ValueExtractor<? super T, ?>... aExtractors) Return aValueExtractor
that extracts aFragment
from a target object.static <T,
E> ValueExtractor <T, Fragment<E>> fragment
(ValueExtractor<? super T, E> from, ValueExtractor<? super E, ?>... aExtractors) Return aValueExtractor
that extracts a nestedFragment
from a property of the target object.static <T> ValueExtractor
<T, ?> fromPof
(int... indexes) Returns an extractor that extracts the value of the specified index(es) from a POF encoded binary value.static <T,
E> ValueExtractor <T, E> Returns an extractor that extracts the value of the specified index(es) from a POF encoded binary value.static <T,
E> ValueExtractor <T, E> fromPof
(Class<E> cls, PofNavigator navigator) Returns an extractor that extracts the value of the specified index(es) from a POF encoded binary value.static <T,
E> ValueExtractor <T, E> Returns an extractor that extracts the value of the specified index(es) from a POF encoded@PortableType
.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> ValueExtractor
<T, List<?>> multi
(ValueExtractor<T, ?>... extractors) Returns an extractor that extracts values using the specifiedValueExtractor
s and returns the extracted values in aList
.static <T> ValueExtractor
<T, List<?>> Returns an extractor that extracts the specified fields and returns the extracted values in aList
.static <T,
E> ValueExtractor <T, E> Instantiate aValueExtractor
that is implemented using the specified language.
-
Constructor Details
-
Extractors
public Extractors()
-
-
Method Details
-
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
-
extract
Returns an extractor that extracts the value of the specified field.- Type Parameters:
T
- the type of the object to extract fromE
- the type of the extracted value- Parameters:
from
- the name of the field or method to extract the value from- Returns:
- an extractor that extracts the value of the specified field
- See Also:
-
extract
Returns an extractor that extracts the value of the specified field.- Type Parameters:
T
- the type of the object to extract fromE
- the type of the extracted value- Parameters:
from
- the name of the method to extract the value from (which must be the full method name)aoParam
- the parameters to pass to the method- Returns:
- an extractor that extracts the value of the specified field
- See Also:
-
multi
Returns an extractor that extracts the specified fields and returns the extracted values in aList
.- Type Parameters:
T
- the type of the object to extract from- Parameters:
fields
- the field names to extract- Returns:
- an extractor that extracts the value(s) of the specified field(s)
- Throws:
IllegalArgumentException
- if the fields parameter is null or an empty array- See Also:
-
multi
Returns an extractor that extracts values using the specifiedValueExtractor
s and returns the extracted values in aList
.- Type Parameters:
T
- the type of the object to extract from- Parameters:
extractors
- theValueExtractor
s to use to extract the list of values- Returns:
- an extractor that extracts the value(s) of the specified field(s)
- Throws:
IllegalArgumentException
- if the fields parameter is null or an empty array- See Also:
-
chained
Returns an extractor that extracts the specified fields where extraction occurs in a chain where the result of each field extraction is the input to the next extractor. The result returned is the result of the final extractor in the chain.- Type Parameters:
T
- the type of the object to extract from- Parameters:
fields
- the field names to extract (if any field name contains a dot '.' that field name is split into multiple field names delimiting on the dots.- Returns:
- an extractor that extracts the value(s) of the specified field(s)
- Throws:
IllegalArgumentException
- if the fields parameter is null or an empty array- See Also:
-
chained
Returns an extractor that extracts the specified fields where extraction occurs in a chain where the result of each field extraction is the input to the next extractor. The result returned is the result of the final extractor in the chain.- Type Parameters:
T
- the type of the object to extract from- Parameters:
extractors
- theValueExtractor
s to use to extract the list of values- Returns:
- an extractor that extracts the value(s) of the specified field(s)
- Throws:
IllegalArgumentException
- if the extractors parameter is null or an empty array- See Also:
-
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
-
fromPof
Returns an extractor that extracts the value of the specified index(es) from a POF encoded binary value.- Type Parameters:
T
- the type of the object to extract from- Parameters:
indexes
- the POF index(es) to extract- Returns:
- an extractor that extracts the value of the specified field
-
fromPof
Returns an extractor that extracts the value of the specified index(es) from a POF encoded binary value.- Type Parameters:
T
- the type of the POF serialized object to extract fromE
- the type of the extracted value- Parameters:
indexes
- the POF index(es) to extract- Returns:
- an extractor that extracts the value of the specified field
- Throws:
NullPointerException
- if the indexes parameter is null
-
fromPof
Returns an extractor that extracts the value of the specified index(es) from a POF encoded@PortableType
.The specified class *must* be marked with
@PortableType
annotation and instrumented usingPortableTypeGenerator
in order for this method to work. Otherwise, anIllegalArgumentException
will be thrown.- Type Parameters:
T
- the type of the POF serialized object to extract fromE
- the type of the extracted value- Parameters:
sPath
- the path of the property to extract- Returns:
- an extractor that extracts the value of the specified field
- Throws:
NullPointerException
- if the indexes parameter is nullIllegalArgumentException
- if the specified class isn't a portable type, or the specified property path doesn't exist
-
script
public static <T,E> ValueExtractor<T,E> script(String sLanguage, String sScriptPath, Object... aoArgs) Instantiate aValueExtractor
that is implemented using the specified language.- Type Parameters:
T
- the type of object to extract fromE
- the type of the extracted value- Parameters:
sLanguage
- the string specifying one of the supported languagessScriptPath
- the path where the script reside, relative to rootaoArgs
- the arguments to be passed to the script- Returns:
- An instance of
ValueExtractor
- Throws:
ScriptException
- if thescript
cannot be loaded or any errors occur during its executionIllegalArgumentException
- if the specified language is not supported- Since:
- 14.1.1.0
-
fragment
@SafeVarargs public static <T> ValueExtractor<T,Fragment<T>> fragment(ValueExtractor<? super T, ?>... aExtractors) Return aValueExtractor
that extracts aFragment
from a target object.- Type Parameters:
T
- the type of object to extract from- Parameters:
aExtractors
- an array of extractors to pass toFragmentExtractor
- Returns:
- a
ValueExtractor
that extracts aFragment
from a target object
-
fragment
@SafeVarargs public static <T,E> ValueExtractor<T,Fragment<E>> fragment(ValueExtractor<? super T, E> from, ValueExtractor<? super E, ?>... aExtractors) Return aValueExtractor
that extracts a nestedFragment
from a property of the target object.- Type Parameters:
T
- the type of the root object to extract from- Parameters:
from
- an extractor for the nested property to extract the fragment fromaExtractors
- an array of extractors to pass toFragmentExtractor
- Returns:
- a
ValueExtractor
that extracts aFragment
from a target object's property
-