activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject svn commit: r1362694 - in /activemq/activemq-cpp/trunk/activemq-cpp/src: main/decaf/util/ main/decaf/util/concurrent/ test/decaf/util/
Date Tue, 17 Jul 2012 22:40:04 GMT
Author: tabish
Date: Tue Jul 17 22:40:04 2012
New Revision: 1362694

URL: http://svn.apache.org/viewvc?rev=1362694&view=rev
Log:
Clean up the Map API a bit and start some initial work on HashMap

Added:
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/MapEntry.cpp   (with props)
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/MapEntry.h   (with props)
Modified:
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/AbstractMap.h
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/HashMap.h
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/LRUCache.h
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/Map.h
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/StlMap.h
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/concurrent/ConcurrentMap.h
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/concurrent/ConcurrentStlMap.h
    activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/StlMapTest.cpp

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/AbstractMap.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/AbstractMap.h?rev=1362694&r1=1362693&r2=1362694&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/AbstractMap.h (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/AbstractMap.h Tue Jul 17
22:40:04 2012
@@ -53,8 +53,8 @@ namespace util {
      *
      * @since 1.0
      */
-    template< typename K, typename V, typename COMPARATOR>
-    class AbstractMap : public decaf::util::Map<K, V, COMPARATOR> {
+    template< typename K, typename V>
+    class AbstractMap : public decaf::util::Map<K, V> {
     public:
 
         virtual ~AbstractMap() {}

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/HashMap.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/HashMap.h?rev=1362694&r1=1362693&r2=1362694&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/HashMap.h (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/HashMap.h Tue Jul 17 22:40:04
2012
@@ -20,15 +20,282 @@
 
 #include <decaf/util/Config.h>
 
+#include <decaf/util/AbstractMap.h>
+#include <decaf/util/HashCode.h>
+#include <decaf/lang/ArrayPointer.h>
+
 namespace decaf {
 namespace util {
 
-    class HashMap {
+    /**
+     * Hash table based implementation of the Map interface. This implementation provides
all
+     * of the optional map operations, and permits null values and the null key.  This class
+     * makes no guarantees as to the order of the map; in particular, it does not guarantee
+     * that the order will remain constant over time.
+     *
+     * This implementation provides constant-time performance for the basic operations (get
+     * and put), assuming the hash function disperses the elements properly among the buckets.
+     * Iteration over collection views requires time proportional to the "capacity" of the
+     * HashMap instance (the number of buckets) plus its size (the number of key-value mappings).
+     * Thus, it's very important not to set the initial capacity too high (or the load factor
too
+     * low) if iteration performance is important.
+     *
+     * An instance of HashMap has two parameters that affect its performance: initial capacity
+     * and load factor. The capacity is the number of buckets in the hash table, and the
initial
+     * capacity is simply the capacity at the time the hash table is created. The load factor
is
+     * a measure of how full the hash table is allowed to get before its capacity is automatically
+     * increased. When the number of entries in the hash table exceeds the product of the
load
+     * factor and the current capacity, the hash table is rehashed (that is, internal data
+     * structures are rebuilt) so that the hash table has approximately twice the number
of buckets.
+     *
+     * As a general rule, the default load factor (.75) offers a good tradeoff between time
and
+     * space costs. Higher values decrease the space overhead but increase the lookup cost
+     * (reflected in most of the operations of the HashMap class, including get and put).
The
+     * expected number of entries in the map and its load factor should be taken into account
+     * when setting its initial capacity, so as to minimize the number of rehash operations.
If
+     * the initial capacity is greater than the maximum number of entries divided by the
load
+     * factor, no rehash operations will ever occur.
+     *
+     * If many mappings are to be stored in a HashMap instance, creating it with a sufficiently
+     * large capacity will allow the mappings to be stored more efficiently than letting
it
+     * perform automatic rehashing as needed to grow the table.
+     *
+     * Note that this implementation is not synchronized. If multiple threads access a hash
map
+     * concurrently, and at least one of the threads modifies the map structurally, it must
be
+     * synchronized externally. (A structural modification is any operation that adds or
deletes
+     * one or more mappings; merely changing the value associated with a key that an instance
+     * already contains is not a structural modification.) This is typically accomplished
by
+     * synchronizing on some object that naturally encapsulates the map. If no such object
+     * exists, the map should be "wrapped" using the Collections::synchronizedMap method.
+     * This is best done at creation time, to prevent accidental unsynchronized access to
the map:
+     *
+     *   Map<K, V>* map = Collections::synchronizedMap(new HashMap<K, V>());
+     *
+     * The iterators returned by all of this class's "collection view methods" are fail-fast:
+     * if the map is structurally modified at any time after the iterator is created, in
any
+     * way except through the iterator's own remove method, the iterator will throw a
+     * ConcurrentModificationException. Thus, in the face of concurrent modification, the
+     * iterator fails quickly and cleanly, rather than risking arbitrary, non-deterministic
+     * behavior at an undetermined time in the future.
+     *
+     * Note that the fail-fast behavior of an iterator cannot be guaranteed as it is, generally
+     * speaking, impossible to make any hard guarantees in the presence of unsynchronized
+     * concurrent modification. Fail-fast iterators throw ConcurrentModificationException
on a
+     * best-effort basis. Therefore, it would be wrong to write a program that depended on
this
+     * exception for its correctness: the fail-fast behavior of iterators should be used
only
+     * to detect bugs.
+     *
+     * @since 1.0
+     */
+    template<typename K, typename V, typename HASHCODE = HashCode<K> >
+    class HashMap : public AbstractMap<K, V> {
+    private:
+
+        class HashMapEntry : public MapEntry<K, V> {
+        public:
+
+            int origKeyHash;
+
+            HashMapEntry* next;
+
+            HashMapEntry(const K& key, int hash) : MapEntry<K, V>(), origKeyHash(hash),
next(NULL) {
+                this->setKey(key);
+                this->origKeyHash = hash;
+            }
+
+            HashMapEntry(const K& key, const V& value) : MapEntry<K, V>(key,
value), origKeyHash(0), next(NULL){
+                this->origKeyHash = HASHCODE()(key);
+            }
+
+        };
+
+    private:
+
+        /**
+         * The Hash Code generator for this map's keys.
+         */
+        HASHCODE hashFunc;
+
+        /*
+         * Actual count of entries
+         */
+        int elementCount;
+
+        /*
+         * The internal data structure to hold Entries, Array of MapEntry pointers.
+         */
+        decaf::lang::ArrayPointer<HashMapEntry*> elementData;
+
+        /*
+         * modification count, to keep track of structural modifications between the
+         * HashMap and the iterator
+         */
+        int modCount;
+
+        /*
+         * maximum ratio of (stored elements)/(storage size) which does not lead to rehash
+         */
+        float loadFactor;
+
+        /*
+         * maximum number of elements that can be put in this map before having to rehash
+         */
+        int threshold;
+
+    private:
+
+        void computeThreshold() {
+            threshold = (int) (elementData.length() * loadFactor);
+        }
+
+        static int calculateCapacity(int x) {
+            if (x >= 1 << 30) {
+                return 1 << 30;
+            }
+
+            if (x == 0) {
+                return 16;
+            }
+            x = x -1;
+            x |= x >> 1;
+            x |= x >> 2;
+            x |= x >> 4;
+            x |= x >> 8;
+            x |= x >> 16;
+            return x + 1;
+        }
+
     public:
 
-        HashMap() {}
+        /**
+         * Creates a new empty HashMap with default configuration settings.
+         */
+        HashMap() : AbstractMap<K,V>(), hashFunc(), elementCount(0), elementData(),
modCount(0), loadFactor(0.75), threshold(0) {
+            int capacity = calculateCapacity(12);
+            elementCount = 0;
+            elementData.reset(NULL, capacity);
+            computeThreshold();
+        }
+
+        /**
+         * Constructs a new HashMap instance with the specified capacity.
+         *
+         * @param capacity
+         * 		The initial capacity of this hash map.
+         *
+         * @throws IllegalArgumentException when the capacity is less than zero.
+         */
+        HashMap(int capacity) : AbstractMap<K,V>(), hashFunc(), elementCount(0), elementData(),
modCount(0), loadFactor(0.75), threshold(0) {
+            if (capacity >= 0) {
+                capacity = calculateCapacity(capacity);
+                elementCount = 0;
+                elementData.reset(NULL, capacity);
+                computeThreshold();
+            } else {
+                throw decaf::lang::exceptions::IllegalArgumentException(
+                        __FILE__, __LINE__, "Invalid capacity configuration");
+            }
+        }
+
+        /**
+         * Constructs a new HashMap instance with the specified capacity.
+         *
+         * @param capacity
+         * 		The initial capacity of this hash map.
+         * @param loadFactor
+         * 		The load factor to use for this hash map.
+         *
+         * @throws IllegalArgumentException when the capacity is less than zero.
+         */
+        HashMap(int capacity, float loadFactor) : AbstractMap<K,V>(), hashFunc(), elementCount(0),
elementData(), modCount(0), loadFactor(0.75), threshold(0) {
+            if (capacity >= 0 && loadFactor > 0) {
+                capacity = calculateCapacity(capacity);
+                elementCount = 0;
+                elementData.reset(NULL, capacity);
+                this->loadFactor = loadFactor;
+                computeThreshold();
+            } else {
+                throw decaf::lang::exceptions::IllegalArgumentException(
+                        __FILE__, __LINE__, "Invalid configuration");
+            }
+        }
+
+        /**
+         * Creates a new HashMap with default configuration settings and fills it with the
contents
+         * of the given source Map instance.
+         *
+         * @param map
+         * 		The Map instance whose elements are copied into this HashMap instance.
+         */
+        HashMap(const Map<K,V>& map) : AbstractMap<K,V>(), hashFunc(), elementCount(0),
elementData(), modCount(0), loadFactor(0.75), threshold(0) {
+            int capacity = calculateCapacity(map.size());
+            elementCount = 0;
+            elementData.reset(NULL, capacity);
+            computeThreshold();
+            putAll(map);
+        }
 
         virtual ~HashMap() {}
+
+    public:
+
+        virtual void clear() {
+            if (elementCount > 0) {
+                elementCount = 0;
+                for (int i = 0; i < elementData.length(); ++i) {
+                    delete elementData[i];
+                    elementData[i] = NULL;
+                }
+                modCount++;
+            }
+        }
+
+        virtual bool isEmpty() const {
+            return elementCount == 0;
+        }
+
+        virtual int size() const {
+            return elementCount;
+        }
+
+        virtual bool containsValue(const V& value) const {
+            for (int i = 0; i < elementData.length(); i++) {
+                HashMapEntry* entry = elementData[i];
+                while (entry != NULL) {
+                    if (value == entry->getValue()) {
+                        return true;
+                    }
+                    entry = entry->next;
+                }
+            }
+            return false;
+        }
+
+    protected:
+
+        void rehash(int capacity) {
+            int length = calculateCapacity((capacity == 0 ? 1 : capacity << 1));
+
+            decaf::lang::ArrayPointer<HashMapEntry*> newData(length);
+            for (int i = 0; i < elementData.length(); i++) {
+                HashMapEntry* entry = elementData[i];
+                elementData[i] = NULL;
+                while (entry != NULL) {
+                    int index = entry->origKeyHash & (length - 1);
+                    HashMapEntry* next = entry->next;
+                    entry->next = newData[index];
+                    newData[index] = entry;
+                    entry = next;
+                }
+            }
+            elementData = newData;
+            computeThreshold();
+        }
+
+        void rehash() {
+            rehash(elementData.length());
+        }
+
     };
 
 }}

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/LRUCache.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/LRUCache.h?rev=1362694&r1=1362693&r2=1362694&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/LRUCache.h (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/LRUCache.h Tue Jul 17 22:40:04
2012
@@ -32,7 +32,7 @@ namespace util {
      * @since 1.0
      */
     template<typename K, typename V, typename COMPARATOR = std::less<K> >
-    class LRUCache : decaf::util::AbstractMap<K, V, COMPARATOR> {
+    class LRUCache : decaf::util::AbstractMap<K, V> {
     protected:
 
         int maxCacheSize;

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/Map.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/Map.h?rev=1362694&r1=1362693&r2=1362694&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/Map.h (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/Map.h Tue Jul 17 22:40:04
2012
@@ -24,40 +24,70 @@
 #include <decaf/util/NoSuchElementException.h>
 #include <decaf/util/concurrent/Synchronizable.h>
 #include <decaf/util/concurrent/Mutex.h>
+#include <decaf/util/Set.h>
+#include <decaf/util/MapEntry.h>
 
 namespace decaf{
 namespace util{
 
     /**
-     * Map template that wraps around a std::map to provide
-     * a more user-friendly interface and to provide common
-     * functions that do not exist in std::map.
+     * An object that maps keys to values. A map cannot contain duplicate keys; each key
can map
+     * to at most one value.
+     *
+     * The Map interface provides three collection views, which allow a map's contents to
be viewed
+     * as a set of keys, collection of values, or set of key-value mappings. The order of
a map is
+     * defined as the order in which the iterators on the map's collection views return their
+     * elements. Some map implementations, like the TreeMap class, make specific guarantees
as to
+     * their order; others, like the HashMap class, do not.
+     *
+     * Note: great care must be exercised if mutable objects are used as map keys. The behavior
+     * of a map is not specified if the value of an object is changed in a manner that affects
+     * equals comparisons while the object is a key in the map. A special case of this prohibition
+     * is that it is not permissible for a map to contain itself as a key. While it is permissible
+     * for a map to contain itself as a value, extreme caution is advised: the equals and
hashCode
+     * methods are no longer well defined on such a map.
+     *
+     * All general-purpose map implementation classes should provide two "standard" constructors:
+     * a void (no arguments) constructor which creates an empty map, and a constructor with
a
+     * single argument of type Map, which creates a new map with the same key-value mappings
as
+     * its argument. In effect, the latter constructor allows the user to copy any map, producing
+     * an equivalent map of the desired class.
+     *
+     * The "destructive" methods contained in this interface, that is, the methods that modify
the
+     * map on which they operate, are specified to throw UnsupportedOperationException if
this map
+     * does not support the operation. If this is the case, these methods may, but are not
required
+     * to, throw an UnsupportedOperationException if the invocation would have no effect
on the map.
+     * For example, invoking the putAll(Map) method on an unmodifiable map may, but is not
required
+     * to, throw the exception if the map whose mappings are to be "superimposed" is empty.
+     *
+     * Some map implementations have restrictions on the keys and values they may contain.
For
+     * example, some implementations prohibit NULL keys and values, and some have restrictions
on
+     * the types of their keys. Attempting to insert an ineligible key or value throws an
exception,
+     * typically NullPointerException or ClassCastException. Attempting to query the presence
of an
+     * ineligible key or value may throw an exception, or it may simply return false; some
+     * implementations will exhibit the former behavior and some will exhibit the latter.
More
+     * generally, attempting an operation on an ineligible key or value whose completion
would not
+     * result in the insertion of an ineligible element into the map may throw an exception
or it
+     * may succeed, at the option of the implementation. Such exceptions are marked as "optional"
+     * in the specification for this interface.
+     *
+     * Many methods in Collections Framework interfaces are defined in terms of the equals
method.
+     * For example, the specification for the containsKey(Object key) method says: "returns
true if
+     * and only if this map contains a mapping for a key k such that (key == k)." This specification
+     * should not be construed to imply that invoking Map.containsKey with a non-null argument
key
+     * will cause (key == k) to be invoked for any key k. Implementations are free to implement
+     * optimizations whereby the equals invocation is avoided, for example, by first comparing
the
+     * hash codes of the two keys. (The Object.hashCode() specification guarantees that two
objects
+     * with unequal hash codes cannot be equal.) More generally, implementations of the various
+     * Collections Framework interfaces are free to take advantage of the specified behavior
of
+     * underlying Object methods wherever the implementor deems it appropriate.
+     *
+     * @since 1.0
      */
-    template <typename K, typename V, typename COMPARATOR = std::less<K> >
+    template <typename K, typename V>
     class Map : public concurrent::Synchronizable {
     public:
 
-        class Entry {
-        private:
-
-            K key;
-            V value;
-
-        public:
-
-            Entry() {}
-            virtual ~Entry() {}
-
-            virtual const K& getKey() const = 0;
-
-            virtual const V& getValue() const = 0;
-
-            virtual void setValue( const V& value ) = 0;
-
-        };
-
-    public:
-
         /**
          * Default constructor - does nothing.
          */
@@ -71,14 +101,14 @@ namespace util{
          * @param source - Map to compare to this one.
          * @returns true if the Map passed is equal in value to this one.
          */
-        virtual bool equals( const Map& source ) const = 0;
+        virtual bool equals(const Map& source) const = 0;
 
         /**
          * Copies the content of the source map into this map.  Erases
          * all existing data in this map.
          * @param source The source object to copy from.
          */
-        virtual void copy( const Map& source ) = 0;
+        virtual void copy(const Map& source) = 0;
 
         /**
          * Removes all keys and values from this map.
@@ -92,7 +122,7 @@ namespace util{
          * @param key The key to look up.
          * @return true if this map contains the value, otherwise false.
          */
-        virtual bool containsKey( const K& key ) const = 0;
+        virtual bool containsKey(const K& key) const = 0;
 
         /**
          * Indicates whether or this map contains a value for the
@@ -123,7 +153,7 @@ namespace util{
          *
          * @throws NoSuchElementException if the key requests doesn't exist in the Map.
          */
-        virtual V& get( const K& key ) = 0;
+        virtual V& get(const K& key) = 0;
 
         /**
          * Gets the value mapped to the specified key in the Map.  If there is no
@@ -135,7 +165,7 @@ namespace util{
          *
          * @throws NoSuchElementException if the key requests doesn't exist in the Map.
          */
-        virtual const V& get( const K& key ) const = 0;
+        virtual const V& get(const K& key) const = 0;
 
         /**
          * Sets the value for the specified key.
@@ -144,7 +174,7 @@ namespace util{
          *
          * @throw UnsupportedOperationException if this map is unmodifiable.
          */
-        virtual void put( const K& key, const V& value ) = 0;
+        virtual void put(const K& key, const V& value) = 0;
 
         /**
          * Stores a copy of the Mappings contained in the other Map in this one.
@@ -155,7 +185,7 @@ namespace util{
          * @throws UnsupportedOperationException
          *      If the implementing class does not support the putAll operation.
          */
-        virtual void putAll( const Map<K,V,COMPARATOR>& other ) = 0;
+        virtual void putAll(const Map<K, V>& other) = 0;
 
         /**
          * Removes the value (key/value pair) for the specified key from
@@ -167,7 +197,7 @@ namespace util{
          * @throw NoSuchElementException if this key is not in the Map.
          * @throw UnsupportedOperationException if this map is unmodifiable.
          */
-        virtual V remove( const K& key ) = 0;
+        virtual V remove(const K& key) = 0;
 
         /**
          * Returns a Set view of the mappings contained in this map. The set is backed by
the
@@ -178,8 +208,11 @@ namespace util{
          * removal, which removes the corresponding mapping from the map, via the
          * Iterator.remove, Set.remove, removeAll, retainAll and clear operations. It does
not
          * support the add or addAll operations.
+         *
+         * @returns a new pointer to a Set<MapEntry<K,V>> that is backed by this
Map, the returned
+         *          pointer is owned by the caller.
          */
-        // TODO
+        virtual Set< MapEntry<K,V> >* entrySet() = 0;
 
         /**
          * @return the entire set of keys in this map as a std::vector.

Added: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/MapEntry.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/MapEntry.cpp?rev=1362694&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/MapEntry.cpp (added)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/MapEntry.cpp Tue Jul 17 22:40:04
2012
@@ -0,0 +1,18 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "MapEntry.h"

Propchange: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/MapEntry.cpp
------------------------------------------------------------------------------
    svn:eol-style = native

Added: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/MapEntry.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/MapEntry.h?rev=1362694&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/MapEntry.h (added)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/MapEntry.h Tue Jul 17 22:40:04
2012
@@ -0,0 +1,75 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef _DECAF_UTIL_MAPENTRY_H_
+#define _DECAF_UTIL_MAPENTRY_H_
+
+#include <decaf/util/Config.h>
+
+namespace decaf {
+namespace util {
+
+    template<typename K, typename V>
+    class MapEntry {
+    private:
+
+        K key;
+        V value;
+
+    public:
+
+        MapEntry();
+
+        virtual ~MapEntry();
+
+        virtual void setKey(K key) {
+            this->key = key;
+        }
+
+        virtual K getKey() const {
+            return this->key;
+        }
+
+        virtual void setValue(V value) {
+            this->value = value;
+        }
+
+        virtual V getValue() const {
+            return this->value;
+        }
+
+        virtual bool equals(const MapEntry<K, V>& entry) const {
+            if (this == &entry) {
+                return true;
+            }
+
+            if (this->key != entry.getKey()) {
+                return false;
+            }
+
+            if (this->value != entry.getValue()) {
+                return false;
+            }
+
+            return true;
+        }
+
+    };
+
+}}
+
+#endif /* _DECAF_UTIL_MAPENTRY_H_ */

Propchange: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/MapEntry.h
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/StlMap.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/StlMap.h?rev=1362694&r1=1362693&r2=1362694&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/StlMap.h (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/StlMap.h Tue Jul 17 22:40:04
2012
@@ -36,7 +36,7 @@ namespace util{
      * @since 1.0
      */
     template <typename K, typename V, typename COMPARATOR = std::less<K> >
-    class StlMap : public Map<K, V, COMPARATOR> {
+    class StlMap : public Map<K, V> {
     private:
 
         std::map<K,V,COMPARATOR> valueMap;
@@ -47,14 +47,14 @@ namespace util{
         /**
          * Default constructor - does nothing.
          */
-        StlMap() : Map<K,V,COMPARATOR>(), valueMap(), mutex() {}
+        StlMap() : Map<K,V>(), valueMap(), mutex() {}
 
         /**
          * Copy constructor - copies the content of the given map into this
          * one.
          * @param source The source map.
          */
-        StlMap( const StlMap& source ) : Map<K,V,COMPARATOR>(), valueMap(), mutex()
{
+        StlMap( const StlMap& source ) : Map<K,V>(), valueMap(), mutex() {
             copy( source );
         }
 
@@ -63,7 +63,7 @@ namespace util{
          * one.
          * @param source The source map.
          */
-        StlMap( const Map<K,V,COMPARATOR>& source ) : Map<K,V,COMPARATOR>(),
valueMap(), mutex() {
+        StlMap( const Map<K,V>& source ) : Map<K,V>(), valueMap(), mutex()
{
             copy( source );
         }
 
@@ -79,7 +79,7 @@ namespace util{
         /**
          * {@inheritDoc}
          */
-        virtual bool equals( const Map<K,V,COMPARATOR>& source ) const {
+        virtual bool equals( const Map<K,V>& source ) const {
             std::vector<K> keys = source.keySet();
 
             typename std::vector<K>::const_iterator iter = keys.begin();
@@ -107,7 +107,7 @@ namespace util{
         /**
          * {@inheritDoc}
          */
-        virtual void copy( const Map<K,V,COMPARATOR>& source ) {
+        virtual void copy( const Map<K,V>& source ) {
             this->clear();
             this->putAll( source );
         }
@@ -208,7 +208,7 @@ namespace util{
         /**
          * {@inheritDoc}
          */
-        virtual void putAll( const Map<K,V,COMPARATOR>& other ) {
+        virtual void putAll( const Map<K,V>& other ) {
 
             std::vector<K> keys = other.keySet();
 
@@ -265,6 +265,10 @@ namespace util{
             return values;
         }
 
+        virtual Set< MapEntry<K, V> >* entrySet() {
+            throw decaf::lang::exceptions::UnsupportedOperationException();
+        }
+
     public:
 
         virtual void lock() {

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/concurrent/ConcurrentMap.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/concurrent/ConcurrentMap.h?rev=1362694&r1=1362693&r2=1362694&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/concurrent/ConcurrentMap.h
(original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/concurrent/ConcurrentMap.h
Tue Jul 17 22:40:04 2012
@@ -35,8 +35,8 @@ namespace concurrent {
      *
      * @since 1.0
      */
-    template<typename K, typename V, typename COMPARATOR>
-    class ConcurrentMap : public Map<K, V, COMPARATOR>{
+    template<typename K, typename V>
+    class ConcurrentMap : public Map<K, V>{
     public:
 
         virtual ~ConcurrentMap() {}

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/concurrent/ConcurrentStlMap.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/concurrent/ConcurrentStlMap.h?rev=1362694&r1=1362693&r2=1362694&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/concurrent/ConcurrentStlMap.h
(original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/concurrent/ConcurrentStlMap.h
Tue Jul 17 22:40:04 2012
@@ -43,7 +43,7 @@ namespace concurrent{
      * @since 1.0
      */
     template <typename K, typename V, typename COMPARATOR = std::less<K> >
-    class ConcurrentStlMap : public ConcurrentMap<K, V, COMPARATOR> {
+    class ConcurrentStlMap : public ConcurrentMap<K, V> {
     private:
 
         std::map<K,V,COMPARATOR> valueMap;
@@ -54,7 +54,7 @@ namespace concurrent{
         /**
          * Default constructor - does nothing.
          */
-        ConcurrentStlMap() : ConcurrentMap<K,V,COMPARATOR>(), valueMap(), mutex() {}
+        ConcurrentStlMap() : ConcurrentMap<K,V>(), valueMap(), mutex() {}
 
         /**
          * Copy constructor - copies the content of the given map into this
@@ -62,7 +62,7 @@ namespace concurrent{
          * @param source The source map.
          */
         ConcurrentStlMap( const ConcurrentStlMap& source ) :
-            ConcurrentMap<K,V,COMPARATOR>(), valueMap(), mutex() {
+            ConcurrentMap<K,V>(), valueMap(), mutex() {
 
             copy( source );
         }
@@ -72,8 +72,8 @@ namespace concurrent{
          * one.
          * @param source The source map.
          */
-        ConcurrentStlMap( const Map<K,V,COMPARATOR>& source ) :
-            ConcurrentMap<K,V,COMPARATOR>(), valueMap(), mutex() {
+        ConcurrentStlMap( const Map<K,V>& source ) :
+            ConcurrentMap<K,V>(), valueMap(), mutex() {
 
             copy( source );
         }
@@ -91,7 +91,7 @@ namespace concurrent{
             return false;
         }
 
-        virtual bool equals( const Map<K,V,COMPARATOR>& source ) const {
+        virtual bool equals( const Map<K,V>& source ) const {
 
             synchronized( &mutex ) {
                 std::vector<K> keys = source.keySet();
@@ -121,7 +121,7 @@ namespace concurrent{
             }
         }
 
-        virtual void copy( const Map<K,V,COMPARATOR>& source ) {
+        virtual void copy( const Map<K,V>& source ) {
             synchronized( &mutex ) {
                 this->clear();
                 this->putAll( source );
@@ -254,7 +254,7 @@ namespace concurrent{
         /**
          * {@inheritDoc}
          */
-        virtual void putAll( const Map<K,V,COMPARATOR>& other ) {
+        virtual void putAll( const Map<K,V>& other ) {
 
             synchronized( &mutex ) {
                 std::vector<K> keys = other.keySet();
@@ -449,6 +449,10 @@ namespace concurrent{
                 __FILE__, __LINE__, "Value to Replace was not in the Map." );
         }
 
+        virtual Set< MapEntry<K, V> >* entrySet() {
+            throw decaf::lang::exceptions::UnsupportedOperationException();
+        }
+
     public:
 
         virtual void lock() {

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/StlMapTest.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/StlMapTest.cpp?rev=1362694&r1=1362693&r2=1362694&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/StlMapTest.cpp (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/StlMapTest.cpp Tue Jul 17
22:40:04 2012
@@ -25,7 +25,7 @@ using namespace decaf;
 using namespace decaf::util;
 
 template <typename K, typename V, typename COMPARATOR = std::less<K> >
-class StlTestMap : public Map<K, V, COMPARATOR> {
+class StlTestMap : public Map<K, V> {
 private:
 
     std::map<K,V,COMPARATOR> valueMap;
@@ -36,14 +36,14 @@ public:
     /**
      * Default constructor - does nothing.
      */
-    StlTestMap() : Map<K,V,COMPARATOR>() {}
+    StlTestMap() : Map<K,V>() {}
 
     /**
      * Copy constructor - copies the content of the given map into this
      * one.
      * @param source The source map.
      */
-    StlTestMap( const StlTestMap& source ) : Map<K,V,COMPARATOR>() {
+    StlTestMap( const StlTestMap& source ) : Map<K,V>() {
         copy( source );
     }
 
@@ -52,7 +52,7 @@ public:
      * one.
      * @param source The source map.
      */
-    StlTestMap( const Map<K,V,COMPARATOR>& source ) : Map<K,V,COMPARATOR>()
{
+    StlTestMap( const Map<K,V>& source ) : Map<K,V>() {
         copy( source );
     }
 
@@ -65,7 +65,7 @@ public:
         return this->valueMap == source.valueMap;
     }
 
-    virtual bool equals( const Map<K,V,COMPARATOR>& source ) const {
+    virtual bool equals( const Map<K,V>& source ) const {
         std::vector<K> keys = source.keySet();
 
         typename std::vector<K>::const_iterator iter = keys.begin();
@@ -90,7 +90,7 @@ public:
         this->valueMap.insert( source.valueMap.begin(), source.valueMap.end() );
     }
 
-    virtual void copy( const Map<K,V,COMPARATOR>& source ) {
+    virtual void copy( const Map<K,V>& source ) {
         this->clear();
         this->putAll( source );
     }
@@ -185,7 +185,7 @@ public:
 
         this->valueMap.insert( other.valueMap.begin(), other.valueMap.end() );
     }
-    virtual void putAll( const Map<K,V,COMPARATOR>& other ) {
+    virtual void putAll( const Map<K,V>& other ) {
 
         std::vector<K> keys = other.keySet();
 
@@ -242,6 +242,10 @@ public:
         return values;
     }
 
+    virtual Set< MapEntry<K, V> >* entrySet() {
+        throw decaf::lang::exceptions::UnsupportedOperationException();
+    }
+
 public:
 
     virtual void lock() {



Mime
View raw message