Overview | Package | Class | Tree | Index | Help

Oracle® Coherence Java API Reference
v3.5.3
E15583-01
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## com.tangosol.util.extractor
Class ComparisonValueExtractor

    java.lang.Object
      com.tangosol.util.Base
          com.tangosol.util.BitHelper
              com.tangosol.util.ExternalizableHelper
                  com.tangosol.util.extractor.AbstractExtractor
                      com.tangosol.util.extractor.AbstractCompositeExtractor
                          com.tangosol.util.extractor.ComparisonValueExtractor

All Implemented Interfaces:
  ExternalizableLite, PortableObject, QueryMapComparator, ValueExtractor, java.io.Serializable, java.util.Comparator

    public class ComparisonValueExtractor

extends AbstractCompositeExtractor

A synthetic ValueExtractor that returns a result of comparison between two values extracted from the same target. In a most general case, the extracted value represents an Integer value calculated accordingly to the contract of `Comparable.compareTo(java.lang.Object)` or `Comparator.compare(java.lang.Object, java.lang.Object)` methods. However, in more specific cases, when the compared values are of common numeric type, the ComparisonValueExtractor will return a numeric difference between those values. The Java type of the comparing values will dictate the Java type of the result.

For example, lets assume that a cache contains business objects that have two properties: SellPrice and BuyPrice (both double). Then, to query for all objects that have SellPrice less than BuyPrice we would use the following:

     ValueExtractor extractDiff = new ComparisonValueExtractor(
       new ReflectionExtractor("getSellPrice"),
       new ReflectionExtractor("getBuyPrice"));
     Filter filter = new LessFilter(extractDiff, new Double(0.0));
     Set entries = cache.entrySet(filter);

Since:
  Coherence 3.4
Author:
  gg 2008.02.15

Field Summary
`protected java.util.Comparator` | `m_comparator` An underlying Comparator object (optional).

Fields inherited from class com.tangosol.util.extractor.AbstractCompositeExtractor
`m_aExtractor`

Fields inherited from class com.tangosol.util.extractor.AbstractExtractor
`KEY, m_nTarget, VALUE`

Constructor Summary
`ComparisonValueExtractor()` Default constructor (necessary for the ExternalizableLite interface).
`ComparisonValueExtractor(java.lang.String sMethod1, java.lang.String sMethod2)` Constuct a ComparisonValueExtractor based on two method names.
`ComparisonValueExtractor(java.lang.String sMethod1, java.lang.String sMethod2, java.util.Comparator comp)` Constuct a ComparisonValueExtractor based on two method names and a Comparator object.
`ComparisonValueExtractor(ValueExtractor ve1, ValueExtractor ve2)` Constuct a ComparisonValueExtractor based on two specified extractors.
`ComparisonValueExtractor(ValueExtractor ve1, ValueExtractor ve2, java.util.Comparator comp)` Constuct a ComparisonValueExtractor based on two specified extractors and a Comparator object.

Method Summary
`java.lang.Object` | `extract(java.lang.Object oTarget)` 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`.
`java.util.Comparator` | `getComparator()` Return a Comparator used by this extractor.
`void` | `readExternal(java.io.DataInput in)` Restore the contents of this object by loading the object's state from the passed DataInput object.
`void` | `readExternal(PofReader in)` Restore the contents of a user type instance by reading its state using the specified PofReader object.
`void` | `writeExternal(java.io.DataOutput out)` Save the contents of this object by storing the object's state into the passed DataOutput object.
`void` | `writeExternal(PofWriter out)` Save the contents of a POF user type instance by writing its state using the specified PofWriter object.

Methods inherited from class com.tangosol.util.extractor.AbstractCompositeExtractor
`equals, getExtractors, hashCode, toString`

Methods inherited from class com.tangosol.util.extractor.AbstractExtractor
`compare, compareEntries, extractFromEntry`

Methods inherited from class com.tangosol.util.BitHelper
`countBits, countBits, countBits, indexOfLSB, indexOfLSB, indexOfLSB, indexOfMSB, indexOfMSB, indexOfMSB, rotateLeft, rotateLeft, rotateLeft, rotateRight, rotateRight, rotateRight, toBitString, toBitString, toBitString`

Field Detail

### m_comparator

    protected java.util.Comparator m_comparator

  An underlying Comparator object (optional).

Constructor Detail

### ComparisonValueExtractor

    public ComparisonValueExtractor()

  Default constructor (necessary for the ExternalizableLite interface).

### ComparisonValueExtractor

    public ComparisonValueExtractor(java.lang.String sMethod1,
                                    java.lang.String sMethod2)

  Constuct a ComparisonValueExtractor based on two method names. Note: values returned by both methods must be `Comparable`.

  Parameters:
    `sMethod1` - the name of the first method to invoke via reflection
    `sMethod2` - the name of the second method to invoke via reflection

### ComparisonValueExtractor

    public ComparisonValueExtractor(java.lang.String sMethod1,
                                    java.lang.String sMethod2,
                                    java.util.Comparator comp)

  Constuct a ComparisonValueExtractor based on two method names and a Comparator object.

  Parameters:
    `sMethod1` - the name of the first method to invoke via reflection
    `sMethod2` - the name of the second method to invoke via reflection
    `comp` - the comparator used to compare the extracted values (optional)

### ComparisonValueExtractor

    public ComparisonValueExtractor(ValueExtractor ve1,
                                    ValueExtractor ve2)

  Constuct a ComparisonValueExtractor based on two specified extractors. Note: values returned by both extractors must be `Comparable`.

  Parameters:
    `ve1` - the ValueExtractor for the first value
    `ve2` - the ValueExtractor for the second value

### ComparisonValueExtractor

    public ComparisonValueExtractor(ValueExtractor ve1,
                                    ValueExtractor ve2,
                                    java.util.Comparator comp)

  Constuct a ComparisonValueExtractor based on two specified extractors and a Comparator object.

  Parameters:
    `ve1` - the ValueExtractor for the first value
    `ve2` - the ValueExtractor for the second value
    `comp` - the comparator used to compare the extracted values (optional)

Method Detail

### getComparator

    public java.util.Comparator getComparator()

  Return a Comparator used by this extractor.

  Returns:
    a Comparator used by this extractor; null if the natural value comparison should be used

### extract

    public java.lang.Object extract(java.lang.Object oTarget)

  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`
  Overrides:
    `extract` in class `AbstractExtractor`
  Parameters:
    `oTarget` - an Object to retrieve the value from
  Returns:
    the extracted value as an Object; null is an acceptable value

### readExternal

    public void readExternal(java.io.DataInput in)
                      throws java.io.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`
  Parameters:
    `in` - the DataInput stream to read data from in order to restore the state of this object
  Throws:
    `java.io.IOException` - if an I/O exception occurs
    `java.io.NotActiveException` - if the object is not in its initial state, and therefore cannot be deserialized into

### writeExternal

    public void writeExternal(java.io.DataOutput out)
                       throws java.io.IOException

  Save the contents of this object by storing the object's state into the passed DataOutput object.

  Specified by:
    `writeExternal` in interface `ExternalizableLite`
  Overrides:
    `writeExternal` in class `AbstractCompositeExtractor`
  Parameters:
    `out` - the DataOutput stream to write the state of this object to
  Throws:
    `java.io.IOException` - if an I/O exception occurs

### readExternal

    public void readExternal(PofReader in)
                      throws java.io.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`
  Parameters:
    `in` - the PofReader from which to read the object's state
  Throws:
    `java.io.IOException` - if an I/O error occurs

### writeExternal

    public void writeExternal(PofWriter out)
                       throws java.io.IOException

  Save the contents of a POF user type instance by writing its state using the specified PofWriter object.

  Specified by:
    `writeExternal` in interface `PortableObject`
  Overrides:
    `writeExternal` in class `AbstractCompositeExtractor`
  Parameters:
    `out` - the PofWriter to which to write the object's state
  Throws:
    `java.io.IOException` - if an I/O error occurs

Overview | Package | Class | Tree | Index | Help

Oracle® Coherence Java API Reference
v3.5.3
E15583-01
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2000, 2010, Oracle. All rights reserved.