00001 /* 00002 * ComparisonFilter.hpp 00003 * 00004 * Copyright (c) 2000, 2014, 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_COMPARISON_FILTER_HPP 00017 #define COH_COMPARISON_FILTER_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/util/ValueExtractor.hpp" 00024 #include "coherence/util/filter/ExtractorFilter.hpp" 00025 00026 COH_OPEN_NAMESPACE3(coherence,util,filter) 00027 00028 using coherence::io::pof::PofReader; 00029 using coherence::io::pof::PofWriter; 00030 00031 00032 /** 00033 * Filter which compares the result of a method invocation with a value. 00034 * 00035 * @author djl 2008.03.02 00036 */ 00037 class COH_EXPORT ComparisonFilter 00038 : public abstract_spec<ComparisonFilter, 00039 extends<ExtractorFilter> > 00040 { 00041 // ----- constructors --------------------------------------------------- 00042 00043 protected: 00044 /** 00045 * Default constructor (necessary for the ExternalizableLite interface). 00046 */ 00047 ComparisonFilter(); 00048 00049 /** 00050 * Construct a ComparisonFilter. 00051 * 00052 * @param vExtractor the ComparisonFilter to use by this filter 00053 * @param vObject the object to compare the result with 00054 */ 00055 ComparisonFilter(ValueExtractor::View vValueExtractor, 00056 Object::View vObject); 00057 00058 private: 00059 /** 00060 * Blocked copy constructor. 00061 */ 00062 ComparisonFilter(const ComparisonFilter&); 00063 00064 00065 // ----- PortableObject interface --------------------------------------- 00066 00067 public: 00068 /** 00069 * {@inheritDoc} 00070 */ 00071 virtual void readExternal(PofReader::Handle hIn); 00072 00073 /** 00074 * {@inheritDoc} 00075 */ 00076 virtual void writeExternal(PofWriter::Handle hOut) const; 00077 00078 00079 // ----- helpers -------------------------------------------------------- 00080 00081 protected: 00082 /** 00083 * Helper method to calculate effectiveness for ComparisonFilters that 00084 * need no more than a single index match in order to retrieve all 00085 * necessary keys to perform the applyIndex() operation. 00086 * Such filters are: Contains, Equals, NotEquals. 00087 * 00088 * @param vMapIndexes the available MapIndex objects keyed by the 00089 * related ValueExtractor; read-only 00090 * @param vSetKeys the set of keys that will be filtered; read-only 00091 * 00092 * @return an effectiveness estimate of how well this filter can use 00093 * the specified indexes to filter the specified keys 00094 */ 00095 virtual int32_t calculateMatchEffectiveness(Map::View vMapIndexes, 00096 Set::View vSetKeys) const; 00097 00098 /** 00099 * Helper method to calculate effectiveness for ComparisonFilters that 00100 * need a range of values from an index in order to retrieve all 00101 * necessary keys to perform the applyIndex() operation. 00102 * Such filters are: Less, LessEquals, Greater, GreaterEquals. 00103 * 00104 * @param vMapIndexes the available MapIndex objects keyed by the 00105 * related ValueExtractor; read-only 00106 * @param vSetKeys the set of keys that will be filtered; read-only 00107 * 00108 * @return an effectiveness estimate of how well this filter can use 00109 * the specified indexes to filter the specified keys 00110 */ 00111 virtual int32_t calculateRangeEffectiveness(Map::View vMapIndexes, 00112 Set::View vSetKeys) const; 00113 00114 public: 00115 /** 00116 * Helper method to calculate effectiveness (or rather ineffectiveness) 00117 * of a simple iteration against a key set that has to be performed due 00118 * to an absence of corresponding index. 00119 * 00120 * @param cKeys the number of keys to iterate through 00121 */ 00122 static int32_t calculateIteratorEffectiveness(int32_t cKeys); 00123 00124 00125 // ----- Object interface ----------------------------------------------- 00126 00127 public: 00128 /** 00129 * {@inheritDoc} 00130 */ 00131 virtual bool equals(Object::View v) const; 00132 00133 /** 00134 * {@inheritDoc} 00135 */ 00136 virtual size32_t hashCode() const; 00137 00138 /** 00139 * {@inheritDoc} 00140 */ 00141 virtual void toStream(std::ostream& out) const; 00142 00143 00144 // ----- data member accessors ------------------------------------------ 00145 00146 public: 00147 /** 00148 * Get the object to compare the reflection result with. 00149 * 00150 * @return the object to compare the reflection result with 00151 */ 00152 virtual Object::View getValue() const; 00153 00154 00155 // ----- data members --------------------------------------------------- 00156 00157 protected: 00158 /** 00159 * The value to compare to. 00160 */ 00161 FinalView<Object> f_vValue; 00162 }; 00163 00164 COH_CLOSE_NAMESPACE3 00165 00166 #endif // COH_COMPARISON_FILTER_HPP