Class AbstractExtractor<T,​E>

    • Field Detail

      • 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 Detail

      • AbstractExtractor

        public AbstractExtractor()
    • Method Detail

      • 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
      • 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