C++ Client API Reference for Oracle Coherence
14c (14.1.2.0.0)

F79659-03

coherence/util/ConditionalIndex.hpp

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