Class 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 of Extractor classes.

    Author:
    lh, hr, as, mf 2018.06.14
    • Constructor Detail

      • Extractors

        public Extractors()
    • 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 from
        E - 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 from
        E - 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 a List.
        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 specified ValueExtractors and returns the extracted values in a List.
        Type Parameters:
        T - the type of the object to extract from
        Parameters:
        extractors - the ValueExtractors 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 - the ValueExtractors 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 function
        E - 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 from
        E - 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 using PortableTypeGenerator in order for this method to work. Otherwise, an IllegalArgumentException will be thrown.

        Type Parameters:
        T - the type of the POF serialized object to extract from
        E - 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 null
        IllegalArgumentException - 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 from
        E - the type of the extracted value
        Parameters:
        navigator - the PofNavigator 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 a ValueExtractor that is implemented using the specified language.
        Type Parameters:
        T - the type of object to extract from
        E - the type of the extracted value
        Parameters:
        sLanguage - the string specifying one of the supported languages
        sScriptPath - the path where the script reside, relative to root
        aoArgs - the arguments to be passed to the script
        Returns:
        An instance of ValueExtractor
        Throws:
        ScriptException - if the script cannot be loaded or any errors occur during its execution
        IllegalArgumentException - 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 a ValueExtractor that extracts a Fragment from a target object.
        Type Parameters:
        T - the type of object to extract from
        Parameters:
        aExtractors - an array of extractors to pass to FragmentExtractor
        Returns:
        a ValueExtractor that extracts a Fragment 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 a ValueExtractor that extracts a nested Fragment 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 from
        aExtractors - an array of extractors to pass to FragmentExtractor
        Returns:
        a ValueExtractor that extracts a Fragment from a target object's property