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