Class ChainedExtractor<T,E>

All Implemented Interfaces:
CanonicallyNamed, ExternalizableLite, PortableObject, QueryMapComparator, Remote.Function<T,E>, Remote.ToDoubleFunction<T>, Remote.ToIntFunction<T>, Remote.ToLongFunction<T>, ValueExtractor<T,E>, Serializable, Comparator, Function<T,E>, ToDoubleFunction<T>, ToIntFunction<T>, ToLongFunction<T>

public class ChainedExtractor<T,E> extends AbstractCompositeExtractor<T,E>
Composite ValueExtractor implementation based on an array of extractors. The extractors in the array are applied sequentially left-to-right, so a result of a previous extractor serves as a target object for a next one.
Author:
gg 2003.09.22
See Also:
  • Constructor Details

    • ChainedExtractor

      public ChainedExtractor()
      Default constructor (necessary for the ExternalizableLite interface).
    • ChainedExtractor

      public ChainedExtractor(ValueExtractor[] aExtractor)
      Construct a ChainedExtractor based on a specified ValueExtractor array.
      Parameters:
      aExtractor - the ValueExtractor array
    • ChainedExtractor

      public ChainedExtractor(ValueExtractor<? super T,? extends U> extractor1, ValueExtractor<? super U,? extends E> extractor2)
      Construct a ChainedExtractor based on two extractors.
      Type Parameters:
      U - the type of value that will be extracted in the first ValueExtractor
      Parameters:
      extractor1 - the first ValueExtractor
      extractor2 - the second ValueExtractor
    • ChainedExtractor

      public ChainedExtractor(String sName)
      Construct a ChainedExtractor for a specified method name sequence.
      Parameters:
      sName - a dot-delimited sequence of method names which results in a ChainedExtractor that is based on an array of corresponding ReflectionExtractor objects
  • Method Details

    • ensureTarget

      public void ensureTarget()
      Ensure that this target is correct after first extractor manually updated.
    • extract

      public E extract(Object oTarget)
      Extract the value from the passed object. The underlying extractors are applied sequentially, so a result of a previous extractor serves as a target object for a next one. A value of null prevents any further extractions and is returned immediately. 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.
      Specified by:
      extract in interface ValueExtractor<T,E>
      Overrides:
      extract in class AbstractExtractor<T,E>
      Parameters:
      oTarget - the object to extract the value from
      Returns:
      the extracted value; null is an acceptable value
    • extractFromEntry

      public E extractFromEntry(Map.Entry entry)
      Extract the value from the passed entry. The underlying extractors are applied sequentially, so a result of a previous extractor serves as a target object for a next one. A value of null prevents any further extractions and is returned immediately. 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.
      Overrides:
      extractFromEntry in class AbstractExtractor<T,E>
      Parameters:
      entry - an Entry object to extract a desired value from
      Returns:
      the extracted value
    • extractOriginalFromEntry

      public E extractOriginalFromEntry(MapTrigger.Entry entry)
      Description copied from class: AbstractExtractor
      Extract the value from the "original value" of the passed Entry object or the key (if targeted). This method's conventions are exactly the same as for the AbstractExtractor.extractFromEntry(java.util.Map.Entry) method.
      Overrides:
      extractOriginalFromEntry in class AbstractExtractor<T,E>
      Parameters:
      entry - an Entry object whose original value should be used to extract the desired value from
      Returns:
      the extracted value or null if the original value is not present
    • compose

      public <V> ValueExtractor<V,E> compose(ValueExtractor<? super V,? extends T> before)
      Description copied from interface: ValueExtractor
      Returns a composed extractor that first applies the 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.
      Type Parameters:
      V - the type of input to the before 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
      See Also:
    • andThen

      public <V> ValueExtractor<T,V> andThen(ValueExtractor<? super E,? extends V> after)
      Description copied from interface: ValueExtractor
      Returns a composed extractor that first applies this extractor to its input, and then applies the after 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 the after 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
      See Also:
    • getCanonicalName

      public String getCanonicalName()
      Compute a canonical name as a dot-separated concatenation of the canonical name of each ValueExtractor array element, starting from lowest index array element.
      Specified by:
      getCanonicalName in interface CanonicallyNamed
      Specified by:
      getCanonicalName in interface ValueExtractor<T,E>
      Overrides:
      getCanonicalName in class AbstractExtractor<T,E>
      Returns:
      canonical name reflecting this instance's array of ValueExtractors.
    • readExternal

      public void readExternal(DataInput in) throws IOException
      Restore the contents of this object by loading the object's state from the passed DataInput object.
      Specified by:
      readExternal in interface ExternalizableLite
      Overrides:
      readExternal in class AbstractCompositeExtractor<T,E>
      Parameters:
      in - the DataInput stream to read data from in order to restore the state of this object
      Throws:
      IOException - if an I/O exception occurs
    • readExternal

      public void readExternal(PofReader in) throws IOException
      Restore the contents of a user type instance by reading its state using the specified PofReader object.
      Specified by:
      readExternal in interface PortableObject
      Overrides:
      readExternal in class AbstractCompositeExtractor<T,E>
      Parameters:
      in - the PofReader from which to read the object's state
      Throws:
      IOException - if an I/O error occurs
    • createExtractors

      public static ValueExtractor[] createExtractors(String sName)
      Parse a dot-delimited sequence of method names and instantiate a corresponding array of ReflectionExtractor objects.
      Parameters:
      sName - a dot-delimited sequence of method names
      Returns:
      an array of ReflectionExtractor objects
    • merge

      protected static ValueExtractor[] merge(ValueExtractor[] aHead, ValueExtractor[] aTail)
      Return a ValueExtractor array with the provided arrays merged into a single array.
      Parameters:
      aHead - the first group of elements in the returned array
      aTail - the second group of elements in the returned array
      Returns:
      a ValueExtractor array with the provided arrays merged into a single array
    • computeTarget

      protected int computeTarget()
      Return the target of the first extractor in composite extractor.

      Enables equivalence between KeyExtractor("foo.bar") and ChainExtractor(ReflectionExtractor("foo", null, KEY), ReflectionExtractor("bar")).

      Returns:
      the target of the first extractor in CompositeExtractor.
      Since:
      12.2.1.4