Oracle Coherence for C++ API
Release 3.6.0.0

E15728-01

coherence/util/comparator/EntryComparator.hpp

00001 /*
00002 * EntryComparator.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_ENTRY_COMPARATOR_HPP
00017 #define COH_ENTRY_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/SafeComparator.hpp"
00025 
00026 COH_OPEN_NAMESPACE3(coherence,util,comparator)
00027 
00028 using coherence::io::pof::PofReader;
00029 using coherence::io::pof::PofWriter;
00030 using coherence::io::pof::PortableObject;
00031 
00032 
00033 /**
00034 * Comparator implementation used to compare map entries. Depending on the
00035 * comparison style this comparator will compare entries' values, entries'
00036 * keys or, when the provided comparator is an instance of
00037 * QueryMapComparator, the entries themselves.
00038 *
00039 * @author nsa 2008.05.30
00040 */
00041 class COH_EXPORT EntryComparator
00042     : public class_spec<EntryComparator,
00043         extends<SafeComparator> >
00044     {
00045     friend class factory<EntryComparator>;
00046 
00047     // ----- constants ------------------------------------------------------
00048 
00049     public:
00050         /**
00051         * Indicates that this EntryComparator should choose the comparison
00052         * style based on the underying comparator type.
00053         */
00054         static const int32_t CMP_AUTO = 0;
00055 
00056         /**
00057         * Indicates that this EntryComparator should compare the entries'
00058         * values.
00059         */
00060         static const int32_t CMP_VALUE = 1;
00061 
00062         /**
00063         * Indicates that this EntryComparator should compare the entries'
00064         * keys.
00065         */
00066         static const int32_t CMP_KEY   = 2;
00067 
00068         /**
00069         * Indicates that entries that implement
00070         * {@link com.tangosol.util.QueryMap.Entry} interface will be compared
00071         * using the QueryMapComparator#compareEntries
00072         * method.
00073         */
00074         static const int32_t CMP_ENTRY = 3;
00075 
00076 
00077     // ----- constructors ---------------------------------------------------
00078 
00079     protected:
00080         /**
00081         * Default constructor (necessary for the PortableObject interface).
00082         */
00083         EntryComparator();
00084 
00085         /**
00086         * Construct a SafeComparator delegating to the specified (wrapped)
00087         * comparator.
00088         *
00089         * @param vComparator  Comparator object to delegate comparison of
00090         *                    non-null values (optional)
00091         */
00092         EntryComparator(Comparator::View vComparator, int32_t nStyle = CMP_AUTO);
00093 
00094 
00095     // ----- Comparator interface -------------------------------------------
00096 
00097     public:
00098         /**
00099         * Compares two arguments for order. The arguments must be
00100         * coherence::util::Map::Entry objects. Depending on the comparison
00101         * style, this method will pass either the entries' values, keys or
00102         * the entries themselves to the underlying Comparator.
00103         *
00104         * @param vO1  the first object to be compared
00105         * @param vO2  the second object to be compared
00106         *
00107         * @return a negative integer, zero, or a positive integer as the first
00108         *          argument is less than, equal to, or greater than the second
00109         *
00110         * @throws ClassCastException if the arguments' types prevent them from
00111         *          being compared by this Comparator.
00112         */
00113         virtual int32_t compare(Object::View vO1, Object::View vO2) const;
00114 
00115 
00116     // ----- PortableObject interface ---------------------------------------
00117 
00118         public:
00119             /**
00120             * {@inheritDoc}
00121             */
00122             virtual void readExternal(PofReader::Handle hIn);
00123 
00124             /**
00125             * {@inheritDoc}
00126             */
00127             virtual void writeExternal(PofWriter::Handle hOut) const;
00128 
00129 
00130     // ----- Object interface -----------------------------------------------
00131 
00132     public:
00133         /**
00134         * {@inheritDoc}
00135         */
00136         virtual bool equals(Object::View v) const;
00137 
00138 
00139     // ----- accessors ------------------------------------------------------
00140 
00141     public:
00142         /**
00143         * Obtain the comparison style value utilized by this EntryComparator. The
00144         * returned value should be one of the CMP_* constants.
00145         *
00146         * @return  the comparison style value
00147         */
00148         int32_t getComparisonStyle();
00149 
00150         /**
00151         * Check whether or not this EntryComparator uses entries' values to pass
00152         * for comparison to the underlying Comparator.
00153         *
00154         * @return true iff entries' values are used for comparison
00155         */
00156         bool isCompareValue();
00157 
00158         /**
00159         * Check whether or not this EntryComparator uses entries' keys to pass
00160         * for comparison to the underlying Comparator.
00161         *
00162         * @return true iff entries' keys are used for comparison
00163         */
00164         bool isCompareKey();
00165 
00166         /**
00167         * Check whether or not this EntryComparator pass entries themselves for
00168         * comparison to the underlying
00169         * QueryMapComparator#compareEntries method.
00170         *
00171         * @return true iff entries themselves are used for comparison
00172         */
00173         bool isCompareEntry();
00174 
00175 
00176     // ----- data members  --------------------------------------------------
00177 
00178     protected:
00179         /**
00180         * Comparison style utilized by this EntryComparator. Valid values are any
00181         * of the CMP_* constants.
00182         */
00183         int32_t m_nStyle;
00184     };
00185 
00186 
00187 COH_CLOSE_NAMESPACE3
00188 
00189 #endif /*COH_ENTRY_COMPARATOR_HPP*/
Copyright © 2000, 2010, Oracle and/or its affiliates. All rights reserved.