00001 /* 00002 * MapKeySet.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_MAP_KEYSET_HPP 00017 #define COH_MAP_KEYSET_HPP 00018 00019 #include "coherence/lang.ns" 00020 00021 #include "coherence/util/ConverterCollections.hpp" 00022 00023 COH_OPEN_NAMESPACE2(coherence,util) 00024 00025 00026 /** 00027 * A wrapper class that provides the Set interface for the key set of a map. 00028 * It's returned by the default implementation of the AbstractMap::keySet() 00029 * method. MapKeySet is based on the ConverterCollections functionality which 00030 * will convert a map's entrySet into a KeySet 00031 * 00032 * Note that because this ConverterSet is based on the Map's entrySet, all 00033 * write operations on the set must be converted out to a method on the Map, 00034 * not the keyset. 00035 * 00036 * @author nsa 2008.01.31 00037 */ 00038 class COH_EXPORT MapKeySet 00039 : public class_spec<MapKeySet, 00040 extends<ConverterCollections::ConverterSet> > 00041 { 00042 friend class factory<MapKeySet>; 00043 00044 // ----- constructors --------------------------------------------------- 00045 00046 protected: 00047 /** 00048 * Create a KeySet which delegates to the specified Set or Map 00049 * depending on the operation. 00050 * 00051 * @param hMap the specfied Map. 00052 */ 00053 MapKeySet(Map::Handle hMapDelegate); 00054 00055 /** 00056 * Create a WrapperCollections#AbstractWrapperSet which 00057 * delegates to the specified Set. 00058 * 00059 * @param vMap the specified Map. 00060 */ 00061 MapKeySet(Map::View vMapDelegate); 00062 00063 00064 // ----- Set interface -------------------------------------------------- 00065 00066 public: 00067 /** 00068 * {@inheritDoc} 00069 */ 00070 virtual bool remove(Object::View v); 00071 00072 /** 00073 * @{inheritDoc} 00074 */ 00075 virtual bool removeAll(Collection::View vc); 00076 00077 /** 00078 * @{inheritDoc} 00079 */ 00080 virtual bool retainAll(Collection::View vc); 00081 00082 /** 00083 * @{inheritDoc} 00084 */ 00085 virtual bool contains(Object::View v) const; 00086 00087 /** 00088 * @{inheritDoc} 00089 */ 00090 virtual bool containsAll(Collection::View vc) const; 00091 00092 00093 // ----- accessors methods ---------------------------------------------- 00094 00095 protected: 00096 /** 00097 * Return the delegate Map instance. 00098 * 00099 * @return the delegate Map instance 00100 */ 00101 virtual Map::Handle getMapDelegate(); 00102 00103 /** 00104 * Return the delegate Map instance. 00105 * 00106 * @return the delegate Map instance 00107 */ 00108 virtual Map::View getMapDelegate() const; 00109 00110 00111 // ----- inner class: KeyConverter ------------------------------------ 00112 00113 public: 00114 /** 00115 * Convert a Map::Entry into a Map::Entry::Key 00116 */ 00117 class KeyConverter 00118 : public class_spec<KeyConverter, 00119 extends<Object>, 00120 implements<Converter> > 00121 { 00122 friend class factory<KeyConverter>; 00123 00124 // ----- constructor ---------------------------------------- 00125 00126 protected: 00127 /** 00128 * Create a new KeyConverter 00129 */ 00130 KeyConverter(); 00131 00132 // ----- Converter interface -------------------------------- 00133 00134 public: 00135 /** 00136 * Convert an {@link coherence::lang::Object Object} referenced 00137 * by the supplied holder. 00138 * 00139 * @param oh the holder to the Object to convert 00140 * 00141 * @return the holder to the converted Object 00142 */ 00143 virtual Object::Holder convert(Object::Holder oh) const; 00144 00145 /** 00146 * Return a singleton instance of the ValueConverter. 00147 */ 00148 static KeyConverter::View getInstance(); 00149 }; 00150 00151 00152 // ----- data members --------------------------------------------------- 00153 00154 protected: 00155 /** 00156 * The underlying map 00157 */ 00158 FinalHolder<Map> f_thMapDelegate; 00159 }; 00160 00161 COH_CLOSE_NAMESPACE2 00162 00163 #endif // COH_MAP_KEYSET_HPP