00001 /* 00002 * ConditionalIndex.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_CONDITIONAL_INDEX_HPP 00017 #define COH_CONDITIONAL_INDEX_HPP 00018 00019 #include "coherence/lang.ns" 00020 00021 #include "coherence/util/Comparator.hpp" 00022 #include "coherence/util/Filter.hpp" 00023 #include "coherence/util/Map.hpp" 00024 #include "coherence/util/SimpleMapIndex.hpp" 00025 #include "coherence/util/ValueExtractor.hpp" 00026 00027 COH_OPEN_NAMESPACE2(coherence,util) 00028 00029 00030 /** 00031 * ConditionalIndex is a conherence::util::MapIndex implementation that uses an associated 00032 * filter to evaluate whether or not an entry should be indexed. An entry's 00033 * extracted value is only added to the index if the filter evaluates to true. 00034 * 00035 * @author tb/lh 2010.08.31 00036 * @since Coherence 3.6.1 00037 */ 00038 class COH_EXPORT ConditionalIndex 00039 : public class_spec<ConditionalIndex, 00040 extends<SimpleMapIndex> > 00041 { 00042 friend class factory<ConditionalIndex>; 00043 00044 // ----- constructors --------------------------------------------------- 00045 00046 protected: 00047 /** 00048 * Construct a ConditionalIndex. 00049 * 00050 * @param vFilter the filter that is used to evaluate the entries of 00051 * the resource map that is being indexed 00052 * @param vExtractor the coherence::util::ValueExtractor that is used to extract 00053 * an indexed value from a resource map entry 00054 * @param fOrdered true iff the contents of the indexed information 00055 * should be ordered; false otherwise 00056 * @param vComparator the Comparator object which imposes an ordering on 00057 * entries in the index map; or <tt>null</tt> if the 00058 * entries' values natural ordering should be used 00059 * @param fForwardIndex specifies whether or not this index supports a 00060 * forward map 00061 */ 00062 ConditionalIndex(Filter::View vFilter, 00063 ValueExtractor::View vExtractor, 00064 bool fOrdered, 00065 Comparator::View vComparator, 00066 bool fForwardIndex); 00067 00068 00069 // ----- SimpleMapIndex methods ----------------------------------------- 00070 00071 public: 00072 /** 00073 * {@inheritDoc} 00074 */ 00075 virtual Object::Holder get(Object::View vKey) const; 00076 00077 /** 00078 * {@inheritDoc} 00079 */ 00080 virtual Object::Holder get(Object::View vKey); 00081 00082 /** 00083 * {@inheritDoc} 00084 */ 00085 virtual bool isPartial() const; 00086 00087 00088 protected: 00089 /** 00090 * {@inheritDoc} 00091 */ 00092 virtual Map::Entry::View getForwardEntry(Object::View vKey) const; 00093 00094 /** 00095 * {@inheritDoc} 00096 */ 00097 virtual Map::Entry::Handle getForwardEntry(Object::View vKey); 00098 00099 /** 00100 * {@inheritDoc} 00101 */ 00102 virtual void removeForwardEntry(Object::View vKey); 00103 00104 /** 00105 * {@inheritDoc} 00106 */ 00107 Map::Handle instantiateForwardIndex() const; 00108 00109 00110 // ----- helpers -------------------------------------------------------- 00111 00112 public: 00113 /** 00114 * Get the associated filter. 00115 * 00116 * @return the filter 00117 */ 00118 Filter::View getFilter() const; 00119 00120 /** 00121 * Determine whether or not this ConditionalIndex supports a forward index. 00122 * 00123 * @return true if this ConditionalIndex supports a forward index; 00124 * false otherwise 00125 */ 00126 bool isForwardIndexSupported() const; 00127 00128 protected: 00129 /** 00130 * Evaluate the given entry using this index's filter. If the entry does 00131 * not pass the filter then it should be excluded from this index, making 00132 * this a partial index. 00133 * 00134 * @param vEntry the entry to evaluate 00135 * 00136 * @return true if the entry passes the filter; false otherwise 00137 */ 00138 bool evaluateEntry(Map::Entry::View vEntry); 00139 00140 /** 00141 * {@inheritDoc} 00142 */ 00143 virtual void insertInternal(Map::Entry::View vEntry); 00144 00145 /** 00146 * {@inheritDoc} 00147 */ 00148 virtual void updateInternal(Map::Entry::View vEntry); 00149 00150 /** 00151 * {@inheritDoc} 00152 */ 00153 virtual void removeInternal(Map::Entry::View vEntry); 00154 00155 00156 // ----- Object interface ----------------------------------------------- 00157 00158 public: 00159 /** 00160 * Writes a string representation of this ConditionalIndex to the stream. 00161 * The string representation consists of the SimpleMapIndex representaion 00162 * concatenated by the Filter and the ForwardIndexSupported flag. 00163 */ 00164 virtual void toStream(std::ostream& out) const; 00165 00166 /** 00167 * Compares the specified object with this index for equality. Returns 00168 * <tt>true</tt> if the given object is also a SimpleMapIndex and the two 00169 * represent the same index. 00170 * 00171 * @param o object to be compared for equality with this MapIndex 00172 * 00173 * @return <tt>true</tt> if the specified object is equal to this index 00174 */ 00175 virtual bool equals(Object::View v) const; 00176 00177 00178 // ----- data members --------------------------------------------------- 00179 00180 private: 00181 /** 00182 * Filter object that this index uses to evaluate entries. 00183 * An entry's extracted value is only added to the index if this filter 00184 * evaluates to true. 00185 */ 00186 FinalView<Filter> f_vFilter; 00187 00188 /** 00189 * Specifies whether or not this ConditionalIndex supports a forward index. 00190 */ 00191 bool m_fForwardIndex; 00192 00193 /** 00194 * Specifies whether or not this ConditionalIndex is a partial index. 00195 * The index is regarded as partial if any entry in the indexed map has 00196 * been excluded from this index. 00197 */ 00198 bool m_fPartial; 00199 }; 00200 00201 COH_CLOSE_NAMESPACE2 00202 00203 #endif // COH_CONDITIONAL_INDEX_HPP