coherence/util/MapIndex.hpp

00001 /*
00002 * MapIndex.hpp
00003 *
00004 * Copyright (c) 2000, 2009, 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_MAP_INDEX_HPP
00017 #define COH_MAP_INDEX_HPP
00018 
00019 #include "coherence/lang.ns"
00020 
00021 #include "coherence/util/Comparator.hpp"
00022 #include "coherence/util/Map.hpp"
00023 #include "coherence/util/ValueExtractor.hpp"
00024 
00025 COH_OPEN_NAMESPACE2(coherence,util)
00026 
00027 
00028 /**
00029 * MapIndex is used to correlate values stored in an <i>indexed Map</i> (or
00030 * attributes of those values) to the corresponding keys in the indexed Map.
00031 *
00032 * @author tb  2009.02.09
00033 */
00034 class COH_EXPORT MapIndex
00035     : public interface_spec<MapIndex>
00036     {
00037     // ----- MapIndex interface ---------------------------------------------
00038 
00039     public:
00040         /**
00041         * Obtain the ValueExtractor object that the MapIndex uses to extract
00042         * an indexable Object from a value stored in the indexed Map. This
00043         * property is never null.
00044         *
00045         * @return a ValueExtractor object, never null
00046         */
00047         virtual ValueExtractor::View getValueExtractor() const = 0;
00048 
00049         /**
00050         * Determine if the MapIndex orders the contents of the indexed
00051         * information. To determine in which way the contents are ordered,
00052         * get the Comparator from the <i>index contents</i> SortedMap object.
00053         *
00054         * @return true if the index contents are ordered, false otherwise
00055         */
00056         virtual bool isOrdered() const = 0;
00057 
00058         /**
00059         * Get the Map that contains the <i>index contents</i>.
00060         * <p>
00061         * The keys of the Map are the return values from the ValueExtractor
00062         * operating against the indexed Map's values, and for each key, the
00063         * corresponding value stored in the Map is a Set of keys to the
00064         * indexed Map.
00065         * <p>
00066         * If the MapIndex is known to be ordered, then the returned Map object
00067         * will be an instance of SortedMap. The SortedMap may or may
00068         * not have a Comparator object associated with it.
00069         * <p>
00070         * A client should assume that the returned Map object is read-only and
00071         * must not attempt to modify it.
00072         *
00073         * @return a Map (or a SortedMap) of the index contents
00074         */
00075         virtual Map::View getIndexContents() const = 0;
00076 
00077         /**
00078         * Using the index information if possible, get the value associated
00079         * with the specified key. This is expected to be more efficient than
00080         * using the ValueExtractor against an object containing the value,
00081         * because the index should already have the necessary information at
00082         * hand.
00083         *
00084         * @param oKey  the key that specifies the object to extract the value
00085         *              from
00086         *
00087         * @return  the value that would be extracted by this MapIndex's
00088         *          ValueExtractor from the object specified by the passed key
00089         */
00090         virtual Object::Holder get(Object::View oKey) const = 0;
00091 
00092         /**
00093         * Using the index information if possible, get the value associated
00094         * with the specified key. This is expected to be more efficient than
00095         * using the ValueExtractor against an object containing the value,
00096         * because the index should already have the necessary information at
00097         * hand.
00098         *
00099         * @param oKey  the key that specifies the object to extract the value
00100         *              from
00101         *
00102         * @return  the value that would be extracted by this MapIndex's
00103         *          ValueExtractor from the object specified by the passed key
00104         */
00105         virtual Object::Holder get(Object::View oKey) = 0;
00106 
00107         /**
00108         * Get the Comparator used to sort the index.
00109         *
00110         * @return the comparator
00111         *
00112         * @since Coherence 3.5
00113         */
00114         virtual Comparator::View getComparator() const = 0;
00115 
00116         /**
00117         * Update the index in response to a insert operation on a cache.
00118         *
00119         * @param vEntry  the entry representing the object being inserted
00120         *
00121         * @since Coherence 3.5
00122         */
00123         virtual void insert(Map::Entry::View vEntry) = 0;
00124 
00125         /**
00126         * Update the index in response to an update operation on a cache.
00127         *
00128         * @param vEntry the entry representing the object being updated
00129         *
00130         * @since Coherence 3.5
00131         */
00132         virtual void update(Map::Entry::View hEntry) = 0;
00133 
00134         /**
00135         * Update the index in response to a remove operation on a cache.
00136         *
00137         * @param vEntry the entry representing the object being deleted
00138         *
00139         * @since Coherence 3.5
00140         */
00141         virtual void remove(Map::Entry::View hEntry) = 0;
00142 };
00143 
00144 COH_CLOSE_NAMESPACE2
00145 
00146 #endif // COH_MAP_INDEX_HPP
Copyright (c) 2000, 2009, Oracle and/or its affiliates. All rights reserved.