00001 /* 00002 * EntryComparator.hpp 00003 * 00004 * Copyright (c) 2000, 2019, 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 private: 00095 /** 00096 * Blocked copy constructor. 00097 */ 00098 EntryComparator(const EntryComparator&); 00099 00100 00101 // ----- Comparator interface ------------------------------------------- 00102 00103 public: 00104 /** 00105 * Compares two arguments for order. The arguments must be 00106 * coherence::util::Map::Entry objects. Depending on the comparison 00107 * style, this method will pass either the entries' values, keys or 00108 * the entries themselves to the underlying Comparator. 00109 * 00110 * @param vO1 the first object to be compared 00111 * @param vO2 the second object to be compared 00112 * 00113 * @return a negative integer, zero, or a positive integer as the first 00114 * argument is less than, equal to, or greater than the second 00115 * 00116 * @throws ClassCastException if the arguments' types prevent them from 00117 * being compared by this Comparator. 00118 */ 00119 virtual int32_t compare(Object::View vO1, Object::View vO2) const; 00120 00121 00122 // ----- PortableObject interface --------------------------------------- 00123 00124 public: 00125 /** 00126 * {@inheritDoc} 00127 */ 00128 virtual void readExternal(PofReader::Handle hIn); 00129 00130 /** 00131 * {@inheritDoc} 00132 */ 00133 virtual void writeExternal(PofWriter::Handle hOut) const; 00134 00135 00136 // ----- Object interface ----------------------------------------------- 00137 00138 public: 00139 /** 00140 * {@inheritDoc} 00141 */ 00142 virtual bool equals(Object::View v) const; 00143 00144 00145 // ----- accessors ------------------------------------------------------ 00146 00147 public: 00148 /** 00149 * Obtain the comparison style value utilized by this EntryComparator. The 00150 * returned value should be one of the CMP_* constants. 00151 * 00152 * @return the comparison style value 00153 */ 00154 int32_t getComparisonStyle(); 00155 00156 /** 00157 * Check whether or not this EntryComparator uses entries' values to pass 00158 * for comparison to the underlying Comparator. 00159 * 00160 * @return true iff entries' values are used for comparison 00161 */ 00162 bool isCompareValue(); 00163 00164 /** 00165 * Check whether or not this EntryComparator uses entries' keys to pass 00166 * for comparison to the underlying Comparator. 00167 * 00168 * @return true iff entries' keys are used for comparison 00169 */ 00170 bool isCompareKey(); 00171 00172 /** 00173 * Check whether or not this EntryComparator pass entries themselves for 00174 * comparison to the underlying 00175 * QueryMapComparator#compareEntries method. 00176 * 00177 * @return true iff entries themselves are used for comparison 00178 */ 00179 bool isCompareEntry(); 00180 00181 00182 // ----- data members -------------------------------------------------- 00183 00184 protected: 00185 /** 00186 * Comparison style utilized by this EntryComparator. Valid values are any 00187 * of the CMP_* constants. 00188 */ 00189 int32_t m_nStyle; 00190 }; 00191 00192 00193 COH_CLOSE_NAMESPACE3 00194 00195 #endif /*COH_ENTRY_COMPARATOR_HPP*/