00001 /* 00002 * ArrayFilter.hpp 00003 * 00004 * Copyright (c) 2000, 2013, 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_ARRAY_FILTER_HPP 00017 #define COH_ARRAY_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/io/pof/PortableObject.hpp" 00024 #include "coherence/util/filter/EntryFilter.hpp" 00025 #include "coherence/util/filter/IndexAwareFilter.hpp" 00026 00027 COH_OPEN_NAMESPACE3(coherence,util,filter) 00028 00029 using coherence::io::pof::PofReader; 00030 using coherence::io::pof::PofWriter; 00031 using coherence::io::pof::PortableObject; 00032 00033 00034 /** 00035 * Filter which is a logical operator of a filter array. 00036 * 00037 * @author djl 2008.03.23 00038 */ 00039 class COH_EXPORT ArrayFilter 00040 : public abstract_spec<ArrayFilter, 00041 extends<Object>, 00042 implements<IndexAwareFilter, PortableObject> > 00043 { 00044 // ----- constructors --------------------------------------------------- 00045 00046 protected: 00047 /** 00048 * Default constructor (necessary for the PortableObject interface). 00049 */ 00050 ArrayFilter(); 00051 00052 /** 00053 * Construct a logical filter that applies a binary operator to a 00054 * filter array. The result is defined as: 00055 * vaFilter[0] <op> vaFilter[1] ... <op> vaFilter[n] 00056 * 00057 * @param vaFilter the filter array 00058 */ 00059 ArrayFilter(ObjectArray::View vaFilter); 00060 00061 private: 00062 /** 00063 * Blocked copy constructor. 00064 */ 00065 ArrayFilter(const ArrayFilter&); 00066 00067 00068 // ----- PortableObject interface --------------------------------------- 00069 00070 public: 00071 /** 00072 * {@inheritDoc} 00073 */ 00074 virtual void readExternal(PofReader::Handle hIn); 00075 00076 /** 00077 * {@inheritDoc} 00078 */ 00079 virtual void writeExternal(PofWriter::Handle hOut) const; 00080 00081 00082 // ----- Object interface ----------------------------------------------- 00083 00084 public: 00085 /** 00086 * Compare the ArrayFilter with another object to determine 00087 * equality. Two ArrayFilter objects are considered equal 00088 * iff they belong to the same class and their underlying Filter 00089 * arrays are deep-equal. 00090 * 00091 * @return true iff this ArrayFilter and the passed object 00092 * are equivalent 00093 */ 00094 virtual bool equals(Object::View v) const; 00095 00096 /** 00097 * {@inheritDoc} 00098 */ 00099 virtual size32_t hashCode() const; 00100 00101 /** 00102 * {@inheritDoc} 00103 */ 00104 virtual void toStream(std::ostream& out) const; 00105 00106 00107 // ----- data member accessors ------------------------------------------ 00108 00109 public: 00110 /** 00111 * Obtain the Filter array. 00112 * 00113 * @return the Filter array 00114 */ 00115 virtual ObjectArray::View getFilters() const; 00116 00117 00118 // ----- internal helpers ----------------------------------------------- 00119 00120 protected: 00121 /** 00122 * Calculate the effectiveness and sort all the participating filters 00123 * according to their effectiveness. 00124 * 00125 * @param vMapIndexes the available MapIndex objects keyed by 00126 * the related ValueExtractor; read-only 00127 * @param vSetKeys the set of keys that will be filtered; read-only 00128 * 00129 * @return the array of WeightedFilter objects sorted by the 00130 * effectiveness (the most effective in the front) 00131 */ 00132 virtual ObjectArray::View calculateFilters(Map::View vMapIndexes, 00133 Set::View vSetKeys) const; 00134 00135 00136 /** 00137 * Apply the specified IndexAwareFilter to the specified keySet. 00138 * 00139 * @param vFilter the IndexAwareFilter to apply an index to 00140 * @param vMapIndexes the available MapIndex objects keyed by 00141 * the related ValueExtractor; read-only 00142 * @param hSetKeys the mutable set of keys that remain to be 00143 * filtered 00144 * 00145 * @return a Filter object that can be used to process the remaining 00146 * keys, or null if no additional filter processing is 00147 * necessary 00148 */ 00149 virtual Filter::View applyFilter(IndexAwareFilter::View vFilter, 00150 Map::View vMapIndexes, Set::Handle hSetKeys) const; 00151 00152 00153 // ----- inner class: WeightedFilter ------------------------------------ 00154 00155 public: 00156 /** 00157 * A thin wrapper around a Filter allowing for sorting the filters 00158 * according to their effectiveness. 00159 * 00160 * @author tb 2009.02.09 00161 */ 00162 class COH_EXPORT WeightedFilter 00163 : public class_spec<WeightedFilter, 00164 extends<Object>, 00165 implements<Comparable> > 00166 { 00167 friend class factory<WeightedFilter>; 00168 00169 // ----- constructors --------------------------------------- 00170 00171 protected: 00172 /** 00173 * Construct the WeightedFilter. 00174 * 00175 * @param vFilter the wrapped filter 00176 * @param nEffect the filter's effectiveness 00177 */ 00178 WeightedFilter(Filter::View vFilter, int32_t nEffect); 00179 00180 // ----- Comparable interface ------------------------------- 00181 00182 public: 00183 /** 00184 * Compares this WeightedFilter with the specified 00185 * WeightedFilter for order. Returns a negative integer, zero, 00186 * or a positive integer as this WeightedFilter's effectiveness 00187 * is less than, equal to, or greater than the effectiveness of 00188 * the specified WeightedFilter object. 00189 * 00190 * @param v the Object to be compared 00191 * 00192 * @return a negative integer, zero, or a positive integer as 00193 * this object is less than, equal to, or greater than 00194 * the specified object 00195 * 00196 * @throws ClassCastException if the specified object's type 00197 * prevents it from being compared to this 00198 * WeightedFilter 00199 */ 00200 int32_t compareTo(Object::View v) const; 00201 00202 // ----- accessors ------------------------------------------ 00203 00204 public: 00205 /** 00206 * Get the wrapped filter. 00207 * 00208 * @return the wrapped filter 00209 */ 00210 Filter::View getFilter() const; 00211 00212 /** 00213 * Get the effectiveness value of the wrapped filter. 00214 * 00215 * @return the effectiveness of the wrapped filter 00216 */ 00217 int32_t getEffectiveness() const; 00218 00219 // ----- data members --------------------------------------- 00220 00221 protected: 00222 /** 00223 * The wrapped filter. 00224 */ 00225 FinalView<Filter> f_vFilter; 00226 00227 /** 00228 * The effectiveness of the wrapped filter. 00229 */ 00230 int32_t m_nEffect; 00231 }; 00232 00233 00234 // ----- data members --------------------------------------------------- 00235 00236 protected: 00237 /** 00238 * The Filter array. 00239 */ 00240 FinalView<ObjectArray> f_vaFilter; 00241 }; 00242 00243 COH_CLOSE_NAMESPACE3 00244 00245 #endif // COH_EXTRACTOR_FILTER_HPP