C++ Client API Reference for Oracle Coherence
14c (14.1.2.0.0)

F79659-03

coherence/util/extractor/ComparisonValueExtractor.hpp

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