Class AbstractExtractor<T,E>

All Implemented Interfaces:
CanonicallyNamed, 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>
Direct Known Subclasses:
AbstractCompositeExtractor, ChainedFragmentExtractor, ConditionalExtractor, DeserializationAccelerator, EntryExtractor, FragmentExtractor, IdentityExtractor, KeyExtractor, PartitionedJCacheStatistics.CacheStatisticsExtractor, PofExtractor, ReflectionExtractor, ScriptValueExtractor, UniversalExtractor

public abstract class AbstractExtractor<T,E> extends ExternalizableHelper implements ValueExtractor<T,E>, QueryMapComparator, Serializable
Abstract base for ValueExtractor implementations. It provides common functionality that allows any extending extractor to be used as a value Comparator.

Starting with Coherence 3.5, when used to extract information that is coming from a Map, subclasses have the additional ability to operate against the Map.Entry instead of just the value. In other words, like the EntryExtractor class, this allows an extractor implementation to extract a desired value using all available information on the corresponding Map.Entry object and is intended to be used in advanced custom scenarios, when application code needs to look at both key and value at the same time or can make some very specific assumptions regarding to the implementation details of the underlying Entry object. To maintain full backwards compatibility, the default behavior remains to extract from the Value property of the Map.Entry.

Note: subclasses are responsible for initialization and POF and/or Lite serialization of the m_nTarget field.

Author:
gg 2003.09.22
See Also:
  • Field Details

    • VALUE

      public static final int VALUE
      Indicates that the extractFromEntry(java.util.Map.Entry) operation should use the Entry's value.
      Since:
      Coherence 3.5
      See Also:
    • KEY

      public static final int KEY
      Indicates that the extractFromEntry(java.util.Map.Entry) operation should use the Entry's key.
      Since:
      Coherence 3.5
      See Also:
    • m_nTarget

      protected int m_nTarget
      Specifies which part of the entry should be used by the extractFromEntry(java.util.Map.Entry) operation. Legal values are VALUE (default) or KEY.

      Note: subclasses are responsible for initialization and POF and/or Lite serialization of this field.

      Since:
      Coherence 3.5
    • m_sNameCanon

      protected transient String m_sNameCanon
      Canonical name for this extractor.

      Note: subclasses are responsible for initialization and POF and/or Lite serialization of this field.

      Since:
      12.2.1.4
  • Constructor Details

    • AbstractExtractor

      public AbstractExtractor()
  • Method Details

    • extract

      public E extract(T oTarget)
      Description copied from interface: ValueExtractor
      Extract the value from the passed object. The returned value may be null. 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>
      Parameters:
      oTarget - the object to extract the value from
      Returns:
      the extracted value; null is an acceptable value
    • getTarget

      public int getTarget()
      Description copied from interface: ValueExtractor
      Return VALUE.
      Specified by:
      getTarget in interface ValueExtractor<T,E>
      Returns:
      VALUE
    • getCanonicalName

      public String getCanonicalName()
      Description copied from interface: ValueExtractor
      Return the canonical name for this extractor.

      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.

      Specified by:
      getCanonicalName in interface CanonicallyNamed
      Specified by:
      getCanonicalName in interface ValueExtractor<T,E>
      Returns:
      the extractor's canonical name, or null
    • equals

      public boolean equals(Object o)
      Equivalence by canonical name and target.

      When precondition isCanonicallyEquatable(Object) is false, fall back to implementation specific equals implementation.

      Specified by:
      equals in interface Comparator<T>
      Specified by:
      equals in interface ValueExtractor<T,E>
      Overrides:
      equals in class Object
      Parameters:
      o - the reference object with which to compare
      Returns:
      true if canonical name match and no target mismatch
    • hashCode

      public int hashCode()
      HashCode value is hashCode of non-null canonical name; otherwise, it is the identity hashCode value.

      Subclass computes hashCode when canonical name is null.

      Specified by:
      hashCode in interface ValueExtractor<T,E>
      Overrides:
      hashCode in class Object
      Returns:
      hashCode when canonical name set.
    • compare

      public int compare(Object o1, Object o2)
      Compares its two arguments for order. Returns a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.
      Specified by:
      compare in interface Comparator<T>
      Parameters:
      o1 - the first object to be compared
      o2 - the second object to be compared
      Returns:
      a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second
      Throws:
      ClassCastException - if the arguments' types prevent them from being compared by this Comparator.
    • compareEntries

      public int compareEntries(QueryMap.Entry entry1, QueryMap.Entry entry2)
      Compare two entries based on the rules specified by Comparator.

      If possible, use the extract method to optimize the value extraction process.

      This method is expected to be implemented by Comparator wrappers, such as ChainedComparator and InverseComparator, which simply pass on this invocation to the wrapped Comparator objects if they too implement this interface, or to invoke their default compare method passing the actual objects (not the extracted values) obtained from the extractor using the passed entries.

      This interface is also expected to be implemented by ValueExtractor implementations that implement the Comparator interface. It is expected that in most cases, the Comparator wrappers will eventually terminate at (i.e. delegate to) ValueExtractors that also implement this interface.

      Specified by:
      compareEntries in interface QueryMapComparator<T>
      Parameters:
      entry1 - the first entry to compare values from; read-only
      entry2 - the second entry to compare values from; read-only
      Returns:
      a negative integer, zero, or a positive integer as the first entry denotes a value that is is less than, equal to, or greater than the value denoted by the second entry
    • extractFromEntry

      public E extractFromEntry(Map.Entry entry)
      Extract the value from the passed Entry object. The returned value should follow the conventions outlined in the extract(T) method. By overriding this method, an extractor implementation is able to extract a desired value using all available information on the corresponding Map.Entry object and is intended to be used in advanced custom scenarios, when application code needs to look at both key and value at the same time or can make some very specific assumptions regarding to the implementation details of the underlying Entry object.
      Parameters:
      entry - an Entry object to extract a desired value from
      Returns:
      the extracted value
      Since:
      Coherence 3.5
    • extractOriginalFromEntry

      public E extractOriginalFromEntry(MapTrigger.Entry entry)
      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 extractFromEntry(java.util.Map.Entry) method.
      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
      Since:
      Coherence 3.6
    • isCanonicallyEquatable

      protected boolean isCanonicallyEquatable(Object oValue)
      Return true if either this or oValue have a non-null canonical name.

      This is a precondition for solely relying on equals(Object) to compute equivalence in subclass implementations. Since hashCode() is computed differently when canonical name exists, implementation specific equivalence can only be used when both instances have a null canonical name; otherwise, the object equals(Object)/hashCode() contract would be violated.

      Parameters:
      oValue - an object
      Returns:
      Return true if either this or oValue have a non-null canonical name.
      Since:
      12.2.1.4