Oracle Coherence for C++ API
Release 3.6.1.0

E18813-01

coherence/util/ConditionalIndex.hpp

00001 /*
00002 * ConditionalIndex.hpp
00003 *
00004 * Copyright (c) 2000, 2010, 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         Map::Handle instantiateForwardIndex() const;
00103 
00104 
00105     // ----- helpers --------------------------------------------------------
00106 
00107     public:
00108         /**
00109         * Get the associated filter.
00110         *
00111         * @return the filter
00112         */
00113         Filter::View getFilter() const;
00114 
00115         /**
00116         * Determine whether or not this ConditionalIndex supports a forward index.
00117         *
00118         * @return true if this ConditionalIndex supports a forward index;
00119         *         false otherwise
00120         */
00121         bool isForwardIndexSupported() const;
00122 
00123     protected:
00124         /**
00125         * Evaluate the given entry using this index's filter.  If the entry does
00126         * not pass the filter then it should be excluded from this index, making
00127         * this a partial index.
00128         *
00129         * @param vEntry  the entry to evaluate
00130         *
00131         * @return true if the entry passes the filter; false otherwise
00132         */
00133         bool evaluateEntry(Map::Entry::View vEntry);
00134 
00135         /**
00136         * {@inheritDoc}
00137         */
00138         virtual void insertInternal(Map::Entry::View vEntry);
00139 
00140         /**
00141         * {@inheritDoc}
00142         */
00143         virtual void updateInternal(Map::Entry::View vEntry);
00144 
00145         /**
00146         * {@inheritDoc}
00147         */
00148         virtual void removeInternal(Map::Entry::View vEntry);
00149 
00150 
00151     // ----- Object interface -----------------------------------------------
00152 
00153     public:
00154         /**
00155         * Writes a string representation of this ConditionalIndex to the stream.
00156         * The string representation consists of the SimpleMapIndex representaion
00157         * concatenated by the Filter and the ForwardIndexSupported flag.
00158         */
00159         virtual void toStream(std::ostream& out) const;
00160 
00161         /**
00162         * Compares the specified object with this index for equality. Returns
00163         * <tt>true</tt> if the given object is also a SimpleMapIndex and the two
00164         * represent the same index.
00165         *
00166         * @param o object to be compared for equality with this MapIndex
00167         *
00168         * @return <tt>true</tt> if the specified object is equal to this index
00169         */
00170         virtual bool equals(Object::View v) const;
00171 
00172 
00173     // ----- data members ---------------------------------------------------
00174 
00175     private:
00176         /**
00177         * Filter object that this index uses to evaluate entries.
00178         * An entry's extracted value is only added to the index if this filter
00179         * evaluates to true.
00180         */
00181         FinalView<Filter> m_vFilter;
00182 
00183         /**
00184         * Specifies whether or not this ConditionalIndex supports a forward index.
00185         */
00186         bool m_fForwardIndex;
00187 
00188         /**
00189         * Specifies whether or not this ConditionalIndex is a partial index.
00190         * The index is regarded as partial if any entry in the indexed map has
00191         * been excluded from this index.
00192         */
00193         bool m_fPartial;
00194     };
00195 
00196 COH_CLOSE_NAMESPACE2
00197 
00198 #endif // COH_CONDITIONAL_INDEX_HPP
Copyright © 2000, 2010, Oracle and/or its affiliates. All rights reserved.