Package com.tangosol.util
Class Extractors
- java.lang.Object
-
- com.tangosol.util.Extractors
-
public class Extractors extends Object
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 ofExtractor
classes.- Author:
- lh, hr, as, mf 2018.06.14
-
-
Constructor Summary
Constructors Constructor Description Extractors()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <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>chained(String... fields)
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>extract(String from)
Returns an extractor that extracts the value of the specified field.static <T,E>
ValueExtractor<T,E>extract(String from, Object... aoParam)
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>fromPof(Class<E> cls, 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>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>fromPof(Class<E> cls, String sPath)
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>identityCast()
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<?>>
multi(String... fields)
Returns an extractor that extracts the specified fields and returns the extracted values in aList
.static <T,E>
ValueExtractor<T,E>script(String sLanguage, String sScriptPath, Object... aoArgs)
Instantiate aValueExtractor
that is implemented using the specified language.
-
-
-
Method Detail
-
identity
public 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
-
extract
public static <T,E> ValueExtractor<T,E> extract(String from)
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:
UniversalExtractor
-
extract
public static <T,E> ValueExtractor<T,E> extract(String from, Object... aoParam)
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:
UniversalExtractor
-
multi
public static <T> ValueExtractor<T,List<?>> multi(String... fields)
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:
UniversalExtractor
-
multi
public 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
.- 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:
UniversalExtractor
-
chained
public static <T,R> ValueExtractor<T,R> chained(String... fields)
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:
UniversalExtractor
-
chained
public static <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. 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:
UniversalExtractor
-
identityCast
public 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
-
fromPof
public 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.- 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
public static <T,E> ValueExtractor<T,E> fromPof(Class<E> cls, int... indexes)
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
public static <T,E> ValueExtractor<T,E> fromPof(Class<E> cls, String sPath)
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
-
fromPof
public 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.- Type Parameters:
T
- the type of the POF serialized object to extract fromE
- the type of the extracted value- Parameters:
navigator
- thePofNavigator
to use to determine the POF path to extract- Returns:
- an extractor that extracts the value of the specified field
- Throws:
NullPointerException
- if the indexes parameter is null
-
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
-
-