Oracle® Fusion Middleware C++ API Reference for Oracle Coherence
12c (12.2.1.2.0)

E77779-01

coherence/util/comparator/ChainedComparator.hpp

00001 /*
00002 * ChainedComparator.hpp
00003 *
00004 * Copyright (c) 2000, 2016, 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_CHAINED_COMPARATOR_HPP
00017 #define COH_CHAINED_COMPARATOR_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/io/pof/PortableObject.hpp"
00024 #include "coherence/util/Comparator.hpp"
00025 #include "coherence/util/QueryMap.hpp"
00026 #include "coherence/util/comparator/EntryAwareComparator.hpp"
00027 #include "coherence/util/comparator/QueryMapComparator.hpp"
00028 
00029 COH_OPEN_NAMESPACE3(coherence,util,comparator)
00030 
00031 using coherence::io::pof::PofReader;
00032 using coherence::io::pof::PofWriter;
00033 using coherence::io::pof::PortableObject;
00034 
00035 /**
00036 * Composite comparator implementation based on a collection of comparators.
00037 * The comparators in the array assumed to be sorted according to their
00038 * priorities; only in a case when the n-th comparator cannot determine the
00039 * order of the passed objects:
00040 * <pre>
00041 *   vaComparator[n]->compare(o1, o2) == 0
00042 * </pre>
00043 * the (n+1)-th comparator will be applied to calculate the value.
00044 *
00045 * @author gm  2008.08.04
00046 */
00047 class COH_EXPORT ChainedComparator
00048     : public class_spec<ChainedComparator,
00049         extends<Object>,
00050         implements<Comparator,
00051                    QueryMapComparator,
00052                    EntryAwareComparator,
00053                    PortableObject> >
00054     {
00055     friend class factory<ChainedComparator>;
00056 
00057     // ----- constructors/destructor ----------------------------------------
00058 
00059     protected:
00060         /**
00061         * Default constructor (necessary for the PortableObject interface).
00062         */
00063         ChainedComparator();
00064 
00065         /**
00066         * Construct a ChainedComparator.
00067         *
00068         * @param vaComparator  the comparator array
00069         */
00070         ChainedComparator(ObjectArray::View vaComparator);
00071 
00072 
00073     // ----- Comparator interface -------------------------------------------
00074 
00075     public:
00076         /**
00077         * Compares its two arguments for order.  Returns a negative integer,
00078         * zero, or a positive integer as the first argument is less than, equal
00079         * to, or greater than the second.
00080         *
00081         * @param vO1  the first object to be compared
00082         * @param vO2  the second object to be compared
00083         *
00084         * @return a negative integer, zero, or a positive integer as the first
00085         *         argument is less than, equal to, or greater than the second
00086         *
00087         * @throws ClassCastException if the arguments' types prevent them from
00088         *          being compared by this Comparator.
00089         */
00090         virtual int32_t compare(Object::View vO1, Object::View vO2) const;
00091 
00092 
00093     // ----- QueryMap interface ---------------------------------------------
00094 
00095     public:
00096         /**
00097         * Compare two entries using the underlying comparator.This implementation 
00098         * simply passes on this invocation to the wrapped
00099         * Comparator objects if they too implement this interface, or invokes
00100         * their default compare method passing the values extracted from the
00101         * passed entries.
00102         */
00103         virtual int32_t compareEntries(QueryMap::Entry::View vEntry1,
00104                     QueryMap::Entry::View vEntry2) const;
00105 
00106 
00107     // ----- EntryAwareComparator interface ---------------------------------
00108 
00109     public:
00110         /**
00111         * {@inheritDoc}
00112         */
00113         virtual bool isKeyComparator() const;
00114 
00115         /**
00116         * Check whether the specified comparator expects to compare keys
00117         * or values.
00118         *
00119         * @param vComparator  a Comparator to check
00120         *
00121         * @return true if the comparator expects keys; false otherwise
00122         */
00123         static bool isKeyComparator(Comparator::View vComparator);
00124 
00125 
00126     // ----- PortableObject interface ---------------------------------------
00127 
00128     public:
00129         /**
00130         * {@inheritDoc}
00131         */
00132         virtual void readExternal(PofReader::Handle hIn);
00133 
00134         /**
00135         * {@inheritDoc}
00136         */
00137         virtual void writeExternal(PofWriter::Handle hOut) const;
00138 
00139     // ----- Object interface -----------------------------------------------
00140 
00141     public:
00142         /**
00143         * {@inheritDoc}
00144         */
00145         virtual bool equals(Object::View v) const;
00146 
00147     // ----- data member accessors ------------------------------------------
00148 
00149     public:
00150         /**
00151         * Obtain the underlying Comparator array.
00152         *
00153         * @return the Comparator array
00154         */
00155         virtual ObjectArray::View getComparators() const;
00156 
00157     // ----- constants ------------------------------------------------------
00158 
00159     public:
00160         /**
00161         * An instance of the ChainedComparator.
00162         */
00163         static ChainedComparator::Handle getInstance();
00164 
00165 
00166     // ----- data members ---------------------------------------------------
00167 
00168     protected:
00169         /**
00170         * The wrapped Comparator array. Could be null.
00171         */
00172         FinalView<ObjectArray> f_vaComparator;
00173     };
00174 
00175 COH_CLOSE_NAMESPACE3
00176 
00177 #endif // COH_CHAINED_COMPARATOR_HPP
Copyright © 2000, 2016, Oracle and/or its affiliates. All rights reserved.