Oracle Coherence for C++ API
Release 3.6.0.0
E15728-01

- Main Page
- Namespaces
- Classes
- Files

# coherence/util/extractor/ComparisonValueExtractor.hpp

    00001 /*
    00002 * ComparisonValueExtractor.hpp
    00003 *
    00004 * Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
    00005 *
    00006 * Oracle is a registered trademarks of Oracle Corporation and/or its
    00007 * affiliates.
    00008 *
    00009 * This software is the confidential and proprietary information of Oracle
    00010 * Corporation. You shall not disclose such confidential and proprietary
    00011 * information and shall use it only in accordance with the terms of the
    00012 * license agreement you entered into with Oracle.
    00013 *
    00014 * This notice may not be removed or altered.
    00015 */
    00016 #ifndef COH_COMPARISON_EXTRACTOR_HPP
    00017 #define COH_COMPARISON_EXTRACTOR_HPP
    00018
    00019 #include "coherence/lang.ns"
    00020
    00021 #include "coherence/io/pof/PofReader.hpp"
    00022 #include "coherence/io/pof/PofWriter.hpp"
    00023 #include "coherence/util/Comparator.hpp"
    00024 #include "coherence/util/extractor/AbstractCompositeExtractor.hpp"
    00025
    00026 COH_OPEN_NAMESPACE3(coherence,util,extractor)
    00027
    00028 using coherence::io::pof::PofReader;
    00029 using coherence::io::pof::PofWriter;
    00030
    00031
    00032 /**
    00033 * A synthetic ValueExtractor that returns a result of comparison between two
    00034 * values extracted from the same target. In a most general case, the extracted
    00035 * value represents an Integer value calculated accordingly to the contract of
    00036 * Comparable#compareTo or Comparator#compare methods. However, in more
    00037 * specific cases, when the compared values are of common numeric type, the
    00038 * ComparisonValueExtractor will return a numeric difference between those
    00039 * values. The type of the comparing values will dictate the type of
    00040 * the result.
    00041 *
    00042 * For example, lets assume that a cache contains business objects that have two
    00043 * properties: SellPrice and BuyPrice (both double). Then, to query for all
    00044 * objects that have SellPrice less than BuyPrice we would use the following:
    00045 * <pre>
    00046 * ValueExtractor::View extractDiff = ComparisonValueExtractor::create(
    00047 *   ReflectionExtractor::create(String::create("getSellPrice")),
    00048 *   ReflectionExtractor::create(String::create("getBuyPrice")));
    00049 * Filter::View vfilter = LessFilter::create(extractDiff, Double::create(0.0));
    00050 * Set::View entries = cache->entrySet(vfilter);
    00051 * </pre>
    00052 *
    00053 * @author djl 2008.04.11
    00054 *
    00055 * @see ChainedExtractor
    00056 */
    00057 class COH_EXPORT ComparisonValueExtractor
    00058     : public class_spec<ComparisonValueExtractor,
    00059         extends<AbstractCompositeExtractor> >
    00060     {
    00061     friend class factory<ComparisonValueExtractor>;
    00062
    00063     // ----- constructors ---------------------------------------------------
    00064
    00065     protected:
    00066         /**
    00067         * Construct an empty ComparisonValueExtractor
    00068         * (necessary for the PortableObject interface).
    00069         */
    00070         ComparisonValueExtractor();
    00071
    00072         /**
    00073         * Constuct a ComparisonValueExtractor based on two specified extractors and
    00074         * a Comparator object.
    00075         *
    00076         * @param vE1    the ValueExtractor for the first value
    00077         * @param vE2    the ValueExtractor for the second value
    00078         * @param vComp  the comparator used to compare the extracted values
    00079         *               (optional); if NULL, the values returned by both
    00080         *               extractors must be Comparable
    00081         */
    00082         ComparisonValueExtractor(ValueExtractor::View vE1,
    00083                 ValueExtractor::View vE2,
    00084                 Comparator::View vComp = NULL);
    00085
    00086
    00087    // ----- ValueExtractor interface ---------------------------------------
    00088
    00089     public:
    00090         /**
    00091         * {@inheritDoc}
    00092         *
    00093         * @throws UnsupportedOperationException always
    00094         */
    00095         virtual Object::Holder extract(Object::Holder ohTarget) const;
    00096
    00097
    00098     // ----- PortableObject interface ---------------------------------------
    00099
    00100     public:
    00101         /**
    00102         * {@inheritDoc}
    00103         */
    00104         virtual void readExternal(PofReader::Handle hIn);
    00105
    00106         /**
    00107         * {@inheritDoc}
    00108         */
    00109         virtual void writeExternal(PofWriter::Handle hOut) const;
    00110
    00111
    00112     // ----- data member accessors ------------------------------------------
    00113
    00114     public:
    00115        /**
    00116       * Return a Comparator used by this extractor.
    00117       *
    00118       * @return a Comparator used by this extractor; null if the natural value
    00119       *         comparison should be used
    00120       */
    00121         virtual Comparator::View getComparator() const;
    00122
    00123
    00124     // ----- data members ---------------------------------------------------
    00125
    00126     protected:
    00127         /**
    00128         * An underlying Comparator object (optional).
    00129         */
    00130        MemberView<Comparator> m_vComparator;
    00131     };
    00132
    00133 COH_CLOSE_NAMESPACE3
    00134
    00135 #endif // #ifndef COH_COMPARISON_EXTRACTOR_HPP

Copyright © 2000, 2010, Oracle and/or its affiliates. All rights reserved.