You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by ta...@apache.org on 2012/07/26 00:57:12 UTC

svn commit: r1365834 [1/2] - in /activemq/activemq-cpp/trunk/activemq-cpp/src: main/ main/activemq/cmsutil/ main/activemq/commands/ main/activemq/core/ main/activemq/state/ main/activemq/transport/ main/activemq/transport/failover/ main/activemq/util/ ...

Author: tabish
Date: Wed Jul 25 22:57:11 2012
New Revision: 1365834

URL: http://svn.apache.org/viewvc?rev=1365834&view=rev
Log:
Refactoring of the Map interface to reduce the amount of copying that's done when elements are accessed via entrySet, values, and keySet.  Also makes the Map overall more robust and usable.  HashMap is fairly complete now and perform better than the StlMap wrapper in a lot of cases. 

Added:
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/Collections.cpp   (with props)
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/Collections.h   (with props)
Modified:
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/Makefile.am
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/cmsutil/DynamicDestinationResolver.cpp
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/cmsutil/PooledSession.cpp
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/commands/ActiveMQMapMessage.cpp
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/commands/ActiveMQMessageTemplate.h
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/core/ActiveMQConnection.cpp
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/state/ConnectionState.cpp
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/state/ConnectionState.h
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/state/ConnectionStateTracker.cpp
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/state/SessionState.h
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/state/TransactionState.cpp
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/state/TransactionState.h
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/transport/TransportRegistry.cpp
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/transport/failover/FailoverTransport.cpp
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/util/PrimitiveMap.cpp
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/wireformat/WireFormatRegistry.cpp
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/wireformat/openwire/marshal/PrimitiveTypesMarshaller.cpp
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/wireformat/stomp/StompHelper.cpp
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/HashMap.h
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/Map.h
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/MapEntry.h
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/Properties.cpp
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/StlMap.h
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/concurrent/ConcurrentStlMap.h
    activemq/activemq-cpp/trunk/activemq-cpp/src/test-benchmarks/decaf/util/MapBenchmark.cpp
    activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/commands/BrokerIdTest.cpp
    activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/util/PrimitiveMapTest.cpp
    activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/HashMapTest.cpp
    activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/StlMapTest.cpp
    activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/StlMapTest.h
    activemq/activemq-cpp/trunk/activemq-cpp/src/test/testRegistry.cpp

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/Makefile.am
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/Makefile.am?rev=1365834&r1=1365833&r2=1365834&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/Makefile.am (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/Makefile.am Wed Jul 25 22:57:11 2012
@@ -423,6 +423,7 @@ cc_sources = \
     decaf/util/Arrays.cpp \
     decaf/util/BitSet.cpp \
     decaf/util/Collection.cpp \
+    decaf/util/Collections.cpp \
     decaf/util/Comparator.cpp \
     decaf/util/ConcurrentModificationException.cpp \
     decaf/util/Date.cpp \
@@ -435,6 +436,7 @@ cc_sources = \
     decaf/util/List.cpp \
     decaf/util/ListIterator.cpp \
     decaf/util/Map.cpp \
+    decaf/util/MapEntry.cpp \
     decaf/util/NoSuchElementException.cpp \
     decaf/util/PriorityQueue.cpp \
     decaf/util/Properties.cpp \
@@ -1035,6 +1037,7 @@ h_sources = \
     decaf/util/Arrays.h \
     decaf/util/BitSet.h \
     decaf/util/Collection.h \
+    decaf/util/Collections.h \
     decaf/util/Comparator.h \
     decaf/util/ConcurrentModificationException.h \
     decaf/util/Config.h \
@@ -1048,6 +1051,7 @@ h_sources = \
     decaf/util/List.h \
     decaf/util/ListIterator.h \
     decaf/util/Map.h \
+    decaf/util/MapEntry.h \
     decaf/util/NoSuchElementException.h \
     decaf/util/PriorityQueue.h \
     decaf/util/Properties.h \

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/cmsutil/DynamicDestinationResolver.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/cmsutil/DynamicDestinationResolver.cpp?rev=1365834&r1=1365833&r2=1365834&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/cmsutil/DynamicDestinationResolver.cpp (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/cmsutil/DynamicDestinationResolver.cpp Wed Jul 25 22:57:11 2012
@@ -84,11 +84,10 @@ DynamicDestinationResolver::~DynamicDest
 void DynamicDestinationResolver::destroy() {
 
     // Destroy the session resolvers.
-    vector<SessionResolver*> r = sessionResolverMap.values();
-    for( size_t ix=0; ix<r.size(); ++ix ) {
-        delete r[ix];
+    std::auto_ptr< Iterator<SessionResolver*> > sessionResolvers(sessionResolverMap.values().iterator());
+    while (sessionResolvers->hasNext()) {
+        delete sessionResolvers->next();
     }
-    sessionResolverMap.clear();
 }
 
 ////////////////////////////////////////////////////////////////////////////////

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/cmsutil/PooledSession.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/cmsutil/PooledSession.cpp?rev=1365834&r1=1365833&r2=1365834&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/cmsutil/PooledSession.cpp (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/cmsutil/PooledSession.cpp Wed Jul 25 22:57:11 2012
@@ -20,7 +20,13 @@
 #include "ResourceLifecycleManager.h"
 #include <cms/CMSException.h>
 
+#include <decaf/util/Set.h>
+#include <decaf/util/Iterator.h>
+
+#include <memory>
+
 using namespace cms;
+using namespace decaf::util;
 using namespace activemq::cmsutil;
 
 /**
@@ -42,18 +48,16 @@ PooledSession::PooledSession( SessionPoo
 PooledSession::~PooledSession() {
 
     // Destroy cached producers.
-    std::vector<CachedProducer*> cachedProducers = producerCache.values();
-    for( std::size_t ix = 0; ix < cachedProducers.size(); ++ix ) {
-        delete cachedProducers[ix];
+    std::auto_ptr< Iterator<CachedProducer*> > producers(producerCache.values().iterator());
+    while (producers->hasNext()) {
+        delete producers->next();
     }
-    cachedProducers.clear();
 
     // Destroy cached consumers.
-    std::vector<CachedConsumer*> cachedConsumers = consumerCache.values();
-    for( std::size_t ix = 0; ix < cachedConsumers.size(); ++ix ) {
-        delete cachedConsumers[ix];
+    std::auto_ptr< Iterator<CachedConsumer*> > consumers(consumerCache.values().iterator());
+    while (consumers->hasNext()) {
+        delete consumers->next();
     }
-    cachedConsumers.clear();
 }
 
 ////////////////////////////////////////////////////////////////////////////////

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/commands/ActiveMQMapMessage.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/commands/ActiveMQMapMessage.cpp?rev=1365834&r1=1365833&r2=1365834&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/commands/ActiveMQMapMessage.cpp (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/commands/ActiveMQMapMessage.cpp Wed Jul 25 22:57:11 2012
@@ -25,6 +25,7 @@
 #include <decaf/io/BufferedInputStream.h>
 #include <decaf/io/DataInputStream.h>
 #include <decaf/io/DataOutputStream.h>
+#include <decaf/util/Collections.h>
 #include <decaf/util/zip/DeflaterOutputStream.h>
 #include <decaf/util/zip/InflaterInputStream.h>
 
@@ -204,7 +205,7 @@ bool ActiveMQMapMessage::isEmpty() const
 std::vector<std::string> ActiveMQMapMessage::getMapNames() const {
 
     try{
-        return getMap().keySet();
+        return decaf::util::Collections::toStlVector<std::string>(getMap().keySet());
     }
     AMQ_CATCH_ALL_THROW_CMSEXCEPTION()
 }

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/commands/ActiveMQMessageTemplate.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/commands/ActiveMQMessageTemplate.h?rev=1365834&r1=1365833&r2=1365834&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/commands/ActiveMQMessageTemplate.h (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/commands/ActiveMQMessageTemplate.h Wed Jul 25 22:57:11 2012
@@ -28,6 +28,7 @@
 #include <activemq/util/CMSExceptionSupport.h>
 
 #include <decaf/lang/exceptions/UnsupportedOperationException.h>
+#include <decaf/util/Collections.h>
 
 #include <cms/IllegalStateException.h>
 #include <cms/MessageFormatException.h>
@@ -106,7 +107,7 @@ namespace commands {
 
         virtual std::vector<std::string> getPropertyNames() const {
             try {
-                return getMessageProperties().keySet();
+                return decaf::util::Collections::toStlVector<std::string>(getMessageProperties().keySet());
             }
             AMQ_CATCH_ALL_THROW_CMSEXCEPTION()
         }

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/core/ActiveMQConnection.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/core/ActiveMQConnection.cpp?rev=1365834&r1=1365833&r2=1365834&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/core/ActiveMQConnection.cpp (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/core/ActiveMQConnection.cpp Wed Jul 25 22:57:11 2012
@@ -37,6 +37,8 @@
 #include <decaf/lang/Boolean.h>
 #include <decaf/lang/Integer.h>
 #include <decaf/util/Iterator.h>
+#include <decaf/util/Set.h>
+#include <decaf/util/Collection.h>
 #include <decaf/util/LinkedList.h>
 #include <decaf/util/UUID.h>
 #include <decaf/util/concurrent/Mutex.h>
@@ -565,11 +567,12 @@ void ActiveMQConnection::close() {
 
         // As TemporaryQueue and TemporaryTopic instances are bound to a connection
         // we should just delete them after the connection is closed to free up memory
-        std::vector< Pointer<ActiveMQTempDestination> > values = this->config->activeTempDestinations.values();
-        std::vector< Pointer<ActiveMQTempDestination> >::iterator iterator = values.begin();
+        Pointer< Iterator< Pointer< ActiveMQTempDestination> > > iterator(
+            this->config->activeTempDestinations.values().iterator());
+
         try {
-            for(; iterator != values.end(); ++iterator) {
-                Pointer<ActiveMQTempDestination> dest = *iterator;
+            while (iterator->hasNext()) {
+                Pointer<ActiveMQTempDestination> dest = iterator->next();
                 dest->close();
             }
         } catch (cms::CMSException& error) {
@@ -1520,10 +1523,10 @@ void ActiveMQConnection::cleanUpTempDest
         return;
     }
 
-    std::vector< Pointer<ActiveMQTempDestination> > values = this->config->activeTempDestinations.values();
-    std::vector< Pointer<ActiveMQTempDestination> >::iterator iterator = values.begin();
-    for(; iterator != values.end(); ++iterator) {
-        Pointer<ActiveMQTempDestination> dest = *iterator;
+    Pointer< Iterator< Pointer< ActiveMQTempDestination> > > iterator(
+        this->config->activeTempDestinations.values().iterator());
+    while (iterator->hasNext()) {
+        Pointer<ActiveMQTempDestination> dest = iterator->next();
 
         try {
 

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/state/ConnectionState.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/state/ConnectionState.cpp?rev=1365834&r1=1365833&r2=1365834&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/state/ConnectionState.cpp (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/state/ConnectionState.cpp Wed Jul 25 22:57:11 2012
@@ -69,12 +69,9 @@ void ConnectionState::reset(Pointer<Conn
 void ConnectionState::shutdown() {
 
     if (this->disposed.compareAndSet(false, true)) {
-
-        std::vector<Pointer<SessionState> > values = this->sessions.values();
-        std::vector<Pointer<SessionState> >::iterator iter = values.begin();
-
-        for (; iter != values.end(); ++iter) {
-            (*iter)->shutdown();
+        Pointer< Iterator< Pointer<SessionState> > > iterator(this->sessions.values().iterator());
+        while (iterator->hasNext()) {
+            iterator->next()->shutdown();
         }
     }
 }

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/state/ConnectionState.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/state/ConnectionState.h?rev=1365834&r1=1365833&r2=1365834&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/state/ConnectionState.h (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/state/ConnectionState.h Wed Jul 25 22:57:11 2012
@@ -38,7 +38,6 @@
 #include <decaf/lang/Pointer.h>
 
 #include <string>
-#include <memory>
 
 namespace activemq {
 namespace state {
@@ -99,7 +98,7 @@ namespace state {
             return transactions.get(id.dynamicCast<LocalTransactionId>());
         }
 
-        std::vector<Pointer<TransactionState> > getTransactionStates() const {
+        const decaf::util::Collection<Pointer<TransactionState> >& getTransactionStates() const {
             return transactions.values();
         }
 
@@ -124,7 +123,7 @@ namespace state {
             return tempDestinations;
         }
 
-        std::vector<Pointer<SessionState> > getSessionStates() const {
+        const decaf::util::Collection<Pointer<SessionState> >& getSessionStates() const {
             return sessions.values();
         }
 

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/state/ConnectionStateTracker.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/state/ConnectionStateTracker.cpp?rev=1365834&r1=1365833&r2=1365834&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/state/ConnectionStateTracker.cpp (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/state/ConnectionStateTracker.cpp Wed Jul 25 22:57:11 2012
@@ -137,11 +137,9 @@ void ConnectionStateTracker::restore(Poi
 
     try{
 
-        std::vector< Pointer<ConnectionState> > connectionStates = this->connectionStates.values();
-        std::vector< Pointer<ConnectionState> >::const_iterator iter = connectionStates.begin();
-
-        for (; iter != connectionStates.end(); ++iter) {
-            Pointer<ConnectionState> state = *iter;
+        Pointer< Iterator< Pointer<ConnectionState> > > iterator(this->connectionStates.values().iterator());
+        while (iterator->hasNext()) {
+            Pointer<ConnectionState> state = iterator->next();
 
             Pointer<ConnectionInfo> info = state->getInfo();
             info->setFailoverReconnect(true);
@@ -159,18 +157,14 @@ void ConnectionStateTracker::restore(Poi
         }
 
         // Now we flush messages
-        std::vector<Pointer<Command> > messages = messageCache.values();
-        std::vector<Pointer<Command> >::const_iterator messageIter = messages.begin();
-
-        for (; messageIter != messages.end(); ++messageIter) {
-            transport->oneway(*messageIter);
+        Pointer< Iterator< Pointer<Command> > > messages(this->messageCache.values().iterator());
+        while (messages->hasNext()) {
+            transport->oneway(messages->next());
         }
 
-        std::vector<Pointer<Command> > messagePulls = messagePullCache.values();
-        std::vector<Pointer<Command> >::const_iterator messagePullIter = messagePulls.begin();
-
-        for (; messagePullIter != messagePulls.end(); ++messagePullIter) {
-            transport->oneway(*messagePullIter);
+        Pointer< Iterator< Pointer<Command> > > messagePullIter(this->messagePullCache.values().iterator());
+        while (messagePullIter->hasNext()) {
+            transport->oneway(messagePullIter->next());
         }
     }
     AMQ_CATCH_RETHROW( IOException )
@@ -186,14 +180,13 @@ void ConnectionStateTracker::doRestoreTr
 
         std::vector<Pointer<TransactionInfo> > toRollback;
 
-        // Restore the session's transaction state
-        std::vector<Pointer<TransactionState> > transactionStates = connectionState->getTransactionStates();
-        std::vector<Pointer<TransactionState> >::const_iterator iter = transactionStates.begin();
-
         // For any completed transactions we don't know if the commit actually made it to the broker
         // or was lost along the way, so they need to be rolled back.
-        for (; iter != transactionStates.end(); ++iter) {
-            Pointer<Command> lastCommand = (*iter)->getCommands().getLast();
+        Pointer< Iterator< Pointer<TransactionState> > > iter(connectionState->getTransactionStates().iterator());
+        while (iter->hasNext()) {
+
+            Pointer<TransactionState> txState = iter->next();
+            Pointer<Command> lastCommand = txState->getCommands().getLast();
             if (lastCommand->isTransactionInfo()) {
                 Pointer<TransactionInfo> transactionInfo = lastCommand.dynamicCast<TransactionInfo>();
                 if (transactionInfo->getType() == ActiveMQConstants::TRANSACTION_STATE_COMMITONEPHASE) {
@@ -203,22 +196,20 @@ void ConnectionStateTracker::doRestoreTr
             }
 
             // replay short lived producers that may have been involved in the transaction
-            std::vector<Pointer<ProducerState> > producerStates = (*iter)->getProducerStates();
-            std::vector<Pointer<ProducerState> >::const_iterator state = producerStates.begin();
-
-            for (; state != producerStates.end(); ++state) {
-                transport->oneway((*state)->getInfo());
+            Pointer< Iterator< Pointer<ProducerState> > > state(txState->getProducerStates().iterator());
+            while (state->hasNext()) {
+                transport->oneway(state->next()->getInfo());
             }
 
-            std::auto_ptr<Iterator<Pointer<Command> > > commands((*iter)->getCommands().iterator());
+            std::auto_ptr<Iterator<Pointer<Command> > > commands(txState->getCommands().iterator());
 
             while (commands->hasNext()) {
                 transport->oneway(commands->next());
             }
 
-            state = producerStates.begin();
-            for (; state != producerStates.end(); ++state) {
-                transport->oneway((*state)->getInfo()->createRemoveCommand());
+            state.reset(txState->getProducerStates().iterator());
+            while (state->hasNext()) {
+                transport->oneway(state->next()->getInfo()->createRemoveCommand());
             }
         }
 
@@ -247,12 +238,9 @@ void ConnectionStateTracker::doRestoreSe
 
     try {
 
-        std::vector<Pointer<SessionState> > sessionStates = connectionState->getSessionStates();
-        std::vector<Pointer<SessionState> >::const_iterator iter = sessionStates.begin();
-
-        // Restore the Session State
-        for (; iter != sessionStates.end(); ++iter) {
-            Pointer<SessionState> state = *iter;
+        Pointer< Iterator< Pointer<SessionState> > > iter(connectionState->getSessionStates().iterator());
+        while (iter->hasNext()) {
+            Pointer<SessionState> state = iter->next();
             transport->oneway(state->getInfo());
 
             if (restoreProducers) {
@@ -280,20 +268,19 @@ void ConnectionStateTracker::doRestoreCo
         bool connectionInterruptionProcessingComplete =
             connectionState->isConnectionInterruptProcessingComplete();
 
-        std::vector<Pointer<ConsumerState> > consumerStates = sessionState->getConsumerStates();
-        std::vector<Pointer<ConsumerState> >::const_iterator state = consumerStates.begin();
-
-        for (; state != consumerStates.end(); ++state) {
+        Pointer< Iterator< Pointer<ConsumerState> > > state(sessionState->getConsumerStates().iterator());
+        while (state->hasNext()) {
 
-            Pointer<ConsumerInfo> infoToSend = (*state)->getInfo();
+            Pointer<ConsumerInfo> infoToSend = state->next()->getInfo();
             Pointer<wireformat::WireFormat> wireFormat = transport->getWireFormat();
 
             if (!connectionInterruptionProcessingComplete && infoToSend->getPrefetchSize() > 0 &&
                 wireFormat->getVersion() > 5) {
 
-                infoToSend.reset((*state)->getInfo()->cloneDataStructure());
+                Pointer<ConsumerInfo> oldInfoToSend = infoToSend;
+                infoToSend.reset(oldInfoToSend->cloneDataStructure());
                 connectionState->getRecoveringPullConsumers().put(
-                    infoToSend->getConsumerId(), (*state)->getInfo());
+                    infoToSend->getConsumerId(), oldInfoToSend);
                 infoToSend->setPrefetchSize(0);
             }
 
@@ -311,11 +298,9 @@ void ConnectionStateTracker::doRestorePr
     try {
 
         // Restore the session's producers
-        std::vector<Pointer<ProducerState> > producerStates = sessionState->getProducerStates();
-        std::vector<Pointer<ProducerState> >::const_iterator iter = producerStates.begin();
-
-        for (; iter != producerStates.end(); ++iter) {
-            Pointer<ProducerState> state = *iter;
+        Pointer< Iterator< Pointer<ProducerState> > > iter(sessionState->getProducerStates().iterator());
+        while (iter->hasNext()) {
+            Pointer<ProducerState> state = iter->next();
             transport->oneway(state->getInfo());
         }
     }
@@ -792,15 +777,15 @@ void ConnectionStateTracker::connectionI
         StlMap<Pointer<ConsumerId>, Pointer<ConsumerInfo>, ConsumerId::COMPARATOR> stalledConsumers =
             connectionState->getRecoveringPullConsumers();
 
-        std::vector<Pointer<ConsumerId> > keySet = stalledConsumers.keySet();
-        std::vector<Pointer<ConsumerId> >::const_iterator key = keySet.begin();
-
-        for (; key != keySet.end(); ++key) {
+        Pointer< Iterator< Pointer<ConsumerId> > > key(stalledConsumers.keySet().iterator());
+        while (key->hasNext()) {
             Pointer<ConsumerControl> control(new ConsumerControl());
 
-            control->setConsumerId(*key);
-            control->setPrefetch(stalledConsumers.get(*key)->getPrefetchSize());
-            control->setDestination(stalledConsumers.get(*key)->getDestination());
+            Pointer<ConsumerId> theKey = key->next();
+
+            control->setConsumerId(theKey);
+            control->setPrefetch(stalledConsumers.get(theKey)->getPrefetchSize());
+            control->setDestination(stalledConsumers.get(theKey)->getDestination());
 
             try {
                 transport->oneway(control);
@@ -815,10 +800,8 @@ void ConnectionStateTracker::connectionI
 ////////////////////////////////////////////////////////////////////////////////
 void ConnectionStateTracker::transportInterrupted() {
 
-    std::vector<Pointer<ConnectionState> > connectionStatesVec = this->connectionStates.values();
-    std::vector<Pointer<ConnectionState> >::const_iterator state = connectionStatesVec.begin();
-
-    for (; state != connectionStatesVec.end(); ++state) {
-        (*state)->setConnectionInterruptProcessingComplete(false);
+    Pointer< Iterator< Pointer<ConnectionState> > > state(this->connectionStates.values().iterator());
+    while (state->hasNext()) {
+        state->next()->setConnectionInterruptProcessingComplete(false);
     }
 }

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/state/SessionState.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/state/SessionState.h?rev=1365834&r1=1365833&r2=1365834&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/state/SessionState.h (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/state/SessionState.h Wed Jul 25 22:57:11 2012
@@ -29,7 +29,6 @@
 #include <decaf/util/concurrent/ConcurrentStlMap.h>
 
 #include <string>
-#include <memory>
 
 namespace activemq {
 namespace state {
@@ -79,7 +78,7 @@ namespace state {
 
         Pointer<ConsumerState> removeConsumer(Pointer<ConsumerId> id);
 
-        std::vector<Pointer<ProducerState> > getProducerStates() const {
+        const decaf::util::Collection<Pointer<ProducerState> >& getProducerStates() const {
             return producers.values();
         }
 
@@ -87,7 +86,7 @@ namespace state {
             return producers.get(id);
         }
 
-        std::vector<Pointer<ConsumerState> > getConsumerStates() const {
+        const decaf::util::Collection<Pointer<ConsumerState> >& getConsumerStates() const {
             return consumers.values();
         }
 

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/state/TransactionState.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/state/TransactionState.cpp?rev=1365834&r1=1365833&r2=1365834&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/state/TransactionState.cpp (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/state/TransactionState.cpp Wed Jul 25 22:57:11 2012
@@ -88,6 +88,6 @@ void TransactionState::addProducerState(
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-std::vector<Pointer<ProducerState> > TransactionState::getProducerStates() {
+const decaf::util::Collection<Pointer<ProducerState> >& TransactionState::getProducerStates() {
     return this->producers.values();
 }

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/state/TransactionState.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/state/TransactionState.h?rev=1365834&r1=1365833&r2=1365834&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/state/TransactionState.h (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/state/TransactionState.h Wed Jul 25 22:57:11 2012
@@ -100,7 +100,7 @@ namespace state {
 
         void addProducerState(Pointer<ProducerState> producerState);
 
-        std::vector<Pointer<ProducerState> > getProducerStates();
+        const decaf::util::Collection<Pointer<ProducerState> >& getProducerStates();
 
     };
 

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/transport/TransportRegistry.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/transport/TransportRegistry.cpp?rev=1365834&r1=1365833&r2=1365834&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/transport/TransportRegistry.cpp (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/transport/TransportRegistry.cpp Wed Jul 25 22:57:11 2012
@@ -17,6 +17,8 @@
 
 #include "TransportRegistry.h"
 
+#include <decaf/util/Collections.h>
+
 using namespace std;
 using namespace activemq;
 using namespace activemq::transport;
@@ -54,37 +56,35 @@ TransportFactory* TransportRegistry::fin
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-void TransportRegistry::registerFactory( const std::string& name, TransportFactory* factory ) {
+void TransportRegistry::registerFactory(const std::string& name, TransportFactory* factory) {
 
-    if( name == "" ) {
+    if (name == "") {
         throw IllegalArgumentException( __FILE__, __LINE__,
             "TransportFactory name cannot be the empty string" );
     }
 
-    if( factory == NULL ) {
+    if (factory == NULL) {
         throw NullPointerException( __FILE__, __LINE__,
             "Supplied TransportFactory pointer was NULL" );
     }
 
-    this->registry.put( name, factory );
+    this->registry.put(name, factory);
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-void TransportRegistry::unregisterFactory( const std::string& name ) {
-    if( this->registry.containsKey( name ) ) {
-        delete this->registry.get( name );
-        this->registry.remove( name );
+void TransportRegistry::unregisterFactory(const std::string& name) {
+    if (this->registry.containsKey(name)) {
+        delete this->registry.get(name);
+        this->registry.remove(name);
     }
 }
 
 ////////////////////////////////////////////////////////////////////////////////
 void TransportRegistry::unregisterAllFactories() {
 
-    std::vector<TransportFactory*> factories = this->registry.values();
-    std::vector<TransportFactory*>::iterator iter = factories.begin();
-
-    for( ; iter != factories.end(); ++iter ) {
-        delete *iter;
+    Pointer< Iterator<TransportFactory*> > iterator(this->registry.values().iterator());
+    while (iterator->hasNext()) {
+        delete iterator->next();
     }
 
     this->registry.clear();
@@ -92,7 +92,7 @@ void TransportRegistry::unregisterAllFac
 
 ////////////////////////////////////////////////////////////////////////////////
 std::vector<std::string> TransportRegistry::getTransportNames() const {
-    return this->registry.keySet();
+    return Collections::toStlVector<std::string>(this->registry.keySet());
 }
 
 ////////////////////////////////////////////////////////////////////////////////

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/transport/failover/FailoverTransport.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/transport/failover/FailoverTransport.cpp?rev=1365834&r1=1365833&r2=1365834&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/transport/failover/FailoverTransport.cpp (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/transport/failover/FailoverTransport.cpp Wed Jul 25 22:57:11 2012
@@ -454,14 +454,15 @@ void FailoverTransport::restoreTransport
         transport->oneway( cc );
 
         stateTracker.restore( transport );
-        std::vector< Pointer<Command> > commands;
-        synchronized( &requestMap ) {
-            commands = requestMap.values();
+
+        decaf::util::StlMap<int, Pointer<Command> > commands;
+        synchronized(&requestMap) {
+            commands.copy(requestMap);
         }
 
-        std::vector< Pointer<Command> >::const_iterator iter = commands.begin();
-        for( ; iter != commands.end(); ++iter ) {
-            transport->oneway( *iter );
+        Pointer< Iterator<Pointer<Command> > > iter(commands.values().iterator());
+        while (iter->hasNext()) {
+            transport->oneway(iter->next());
         }
     }
     AMQ_CATCH_RETHROW( IOException )
@@ -554,14 +555,14 @@ void FailoverTransport::processNewTransp
                 try {
                     URI uri( str );
                     list.add( uri );
-                } catch( Exception e ) {
+                } catch( Exception& e ) {
                 }
             }
 
             if( !list.isEmpty() ) {
                 try {
                     updateURIs( rebalance, list );
-                } catch( IOException e ) {
+                } catch( IOException& e ) {
                 }
             }
         }
@@ -923,8 +924,8 @@ void FailoverTransport::processResponse(
 ////////////////////////////////////////////////////////////////////////////////
 Pointer<wireformat::WireFormat> FailoverTransport::getWireFormat() const {
 
-	Pointer<wireformat::WireFormat> result;
-	Pointer<Transport> transport = this->connectedTransport;
+    Pointer<wireformat::WireFormat> result;
+    Pointer<Transport> transport = this->connectedTransport;
 
     if( transport != NULL ) {
         result = transport->getWireFormat();

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/util/PrimitiveMap.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/util/PrimitiveMap.cpp?rev=1365834&r1=1365833&r2=1365834&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/util/PrimitiveMap.cpp (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/util/PrimitiveMap.cpp Wed Jul 25 22:57:11 2012
@@ -21,10 +21,14 @@
 #include <stdio.h>
 #include <string.h>
 
+#include <decaf/lang/Pointer.h>
+#include <decaf/util/Set.h>
+
 using namespace activemq;
 using namespace activemq::util;
 using namespace decaf::lang::exceptions;
 using namespace decaf::util;
+using namespace decaf::lang;
 using namespace std;
 
 ////////////////////////////////////////////////////////////////////////////////
@@ -48,13 +52,15 @@ PrimitiveMap::PrimitiveMap(const Primiti
 ////////////////////////////////////////////////////////////////////////////////
 std::string PrimitiveMap::toString() const {
 
-    std::vector<std::string> keys = this->keySet();
     ostringstream stream;
 
     stream << "Begin Class PrimitiveMap:" << std::endl;
 
-    for (std::size_t i = 0; i < keys.size(); ++i) {
-        stream << "map[" << keys[i] << "] = " << this->get(keys[i]).toString() << std::endl;
+    Pointer< Iterator<MapEntry<std::string, PrimitiveValueNode> > > entries(this->entrySet().iterator());
+    while (entries->hasNext()) {
+        MapEntry<std::string, PrimitiveValueNode> entry = entries->next();
+        stream << "map[" << entry.getKey() << "] = " << entry.getValue().toString() << std::endl;
+
     }
 
     stream << "End Class PrimitiveMap:" << std::endl;

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/wireformat/WireFormatRegistry.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/wireformat/WireFormatRegistry.cpp?rev=1365834&r1=1365833&r2=1365834&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/wireformat/WireFormatRegistry.cpp (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/wireformat/WireFormatRegistry.cpp Wed Jul 25 22:57:11 2012
@@ -17,6 +17,8 @@
 
 #include "WireFormatRegistry.h"
 
+#include <decaf/util/Collections.h>
+
 using namespace std;
 using namespace activemq;
 using namespace activemq::wireformat;
@@ -80,11 +82,9 @@ void WireFormatRegistry::unregisterFacto
 ////////////////////////////////////////////////////////////////////////////////
 void WireFormatRegistry::unregisterAllFactories() {
 
-    std::vector<WireFormatFactory*> factories = this->registry.values();
-    std::vector<WireFormatFactory*>::iterator iter = factories.begin();
-
-    for( ; iter != factories.end(); ++iter ) {
-        delete *iter;
+    Pointer< Iterator<WireFormatFactory*> > iterator(this->registry.values().iterator());
+    while (iterator->hasNext()) {
+        delete iterator->next();
     }
 
     this->registry.clear();
@@ -92,7 +92,7 @@ void WireFormatRegistry::unregisterAllFa
 
 ////////////////////////////////////////////////////////////////////////////////
 std::vector<std::string> WireFormatRegistry::getWireFormatNames() const {
-    return this->registry.keySet();
+    return Collections::toStlVector<std::string>(this->registry.keySet());
 }
 
 ////////////////////////////////////////////////////////////////////////////////

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/wireformat/openwire/marshal/PrimitiveTypesMarshaller.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/wireformat/openwire/marshal/PrimitiveTypesMarshaller.cpp?rev=1365834&r1=1365833&r2=1365834&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/wireformat/openwire/marshal/PrimitiveTypesMarshaller.cpp (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/wireformat/openwire/marshal/PrimitiveTypesMarshaller.cpp Wed Jul 25 22:57:11 2012
@@ -36,6 +36,7 @@ using namespace activemq::wireformat::op
 using namespace decaf;
 using namespace decaf::io;
 using namespace decaf::lang;
+using namespace decaf::util;
 
 ///////////////////////////////////////////////////////////////////////////////
 void PrimitiveTypesMarshaller::marshal( const PrimitiveMap* map, std::vector<unsigned char>& buffer ) {
@@ -190,14 +191,12 @@ void PrimitiveTypesMarshaller::marshalPr
 
         dataOut.writeInt( (int)map.size() );
 
-        std::vector<std::string> keys = map.keySet();
-        std::vector<std::string>::const_iterator iter = keys.begin();
-
-        for(; iter != keys.end(); ++iter ) {
-
-            dataOut.writeUTF( *iter );
-            PrimitiveValueNode value = map.get( *iter );
-            marshalPrimitive( dataOut, value );
+        Pointer< Iterator<std::string> > keys(map.keySet().iterator());
+        while (keys->hasNext()) {
+            std::string key = keys->next();
+            dataOut.writeUTF(key);
+            PrimitiveValueNode value = map.get(key);
+            marshalPrimitive(dataOut, value);
         }
     }
     AMQ_CATCH_RETHROW( io::IOException )

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/wireformat/stomp/StompHelper.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/wireformat/stomp/StompHelper.cpp?rev=1365834&r1=1365833&r2=1365834&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/wireformat/stomp/StompHelper.cpp (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/wireformat/stomp/StompHelper.cpp Wed Jul 25 22:57:11 2012
@@ -161,11 +161,10 @@ void StompHelper::convertProperties( con
         frame->setProperty( "JMSXGroupID", message->getGroupID() );
     }
 
-    std::vector<std::string> keys = message->getMessageProperties().keySet();
-    std::vector<std::string>::const_iterator iter = keys.begin();
-
-    for( ; iter != keys.end(); ++iter ) {
-        frame->setProperty( *iter, message->getMessageProperties().getString( *iter ) );
+    Pointer< Iterator<std::string> > keys(message->getMessageProperties().keySet().iterator());
+    while (keys->hasNext()) {
+        std::string key = keys->next();
+        frame->setProperty(key, message->getMessageProperties().getString(key) );
     }
 }
 

Added: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/Collections.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/Collections.cpp?rev=1365834&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/Collections.cpp (added)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/Collections.cpp Wed Jul 25 22:57:11 2012
@@ -0,0 +1,19 @@
+/*
+ * 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 "Collections.h"
+

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

Added: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/Collections.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/Collections.h?rev=1365834&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/Collections.h (added)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/Collections.h Wed Jul 25 22:57:11 2012
@@ -0,0 +1,67 @@
+/*
+ * 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_COLLECTIONS_H_
+#define _DECAF_UTIL_COLLECTIONS_H_
+
+#include <decaf/util/Config.h>
+
+#include <decaf/util/Collection.h>
+#include <decaf/util/Iterator.h>
+
+#include <vector>
+#include <memory>
+
+namespace decaf {
+namespace util {
+
+    class DECAF_API Collections {
+    private:
+
+        Collections();
+        Collections(const Collections&);
+        Collections& operator= (const Collections&);
+
+    public:
+
+        /**
+         * Creates and returns a new STL vector instance that contains a copy of each
+         * element in the supplied collection instance.  If the Collection is empty the
+         * returned vector will also be empty.
+         *
+         * @param collection
+         *      The collection whose elements are to be copied to a std::vector.
+         *
+         * @returns a new std::vector containing a copy of each element in the Collection.
+         */
+        template<typename E>
+        static std::vector<E> toStlVector(const Collection<E>& collection) {
+
+            std::vector<E> result(collection.size());
+
+            typename std::auto_ptr< Iterator<E> > iterator(collection.iterator());
+            while (iterator->hasNext()) {
+                result.push_back(iterator->next());
+            }
+
+            return result;
+        }
+    };
+
+}}
+
+#endif /* _DECAF_UTIL_COLLECTIONS_H_ */

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

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=1365834&r1=1365833&r2=1365834&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 Wed Jul 25 22:57:11 2012
@@ -196,14 +196,14 @@ namespace util {
 
                 if (prevEntry == NULL){
                     int index = currentEntry->origKeyHash & (associatedMap->elementData.length() - 1);
-                    HashMapEntry* removed = associatedMap->elementData[index];
                     associatedMap->elementData[index] = associatedMap->elementData[index]->next;
-                    delete removed;
                 } else {
                     prevEntry->next = currentEntry->next;
                 }
 
+                delete currentEntry;
                 currentEntry = NULL;
+
                 expectedModCount++;
                 associatedMap->modCount++;
                 associatedMap->elementCount--;
@@ -291,156 +291,156 @@ namespace util {
             }
         };
 
-        private:
+    private:
 
-            class ConstAbstractMapIterator {
-            protected:
+        class ConstAbstractMapIterator {
+        protected:
 
-                mutable int position;
-                int expectedModCount;
-                const HashMapEntry* futureEntry;
-                const HashMapEntry* currentEntry;
-                const HashMapEntry* prevEntry;
+            mutable int position;
+            int expectedModCount;
+            const HashMapEntry* futureEntry;
+            const HashMapEntry* currentEntry;
+            const HashMapEntry* prevEntry;
 
-                const HashMap* associatedMap;
+            const HashMap* associatedMap;
 
-            public:
+        public:
 
-                ConstAbstractMapIterator(const HashMap* parent) : position(0),
-                                                                  expectedModCount(parent->modCount),
-                                                                  futureEntry(NULL),
-                                                                  currentEntry(NULL),
-                                                                  prevEntry(NULL),
-                                                                  associatedMap(parent) {
-                }
+            ConstAbstractMapIterator(const HashMap* parent) : position(0),
+                                                              expectedModCount(parent->modCount),
+                                                              futureEntry(NULL),
+                                                              currentEntry(NULL),
+                                                              prevEntry(NULL),
+                                                              associatedMap(parent) {
+            }
 
-                virtual ~ConstAbstractMapIterator() {}
+            virtual ~ConstAbstractMapIterator() {}
 
-                virtual bool checkHasNext() const {
-                    if (futureEntry != NULL) {
+            virtual bool checkHasNext() const {
+                if (futureEntry != NULL) {
+                    return true;
+                }
+                while (position < associatedMap->elementData.length()) {
+                    if (associatedMap->elementData[position] == NULL) {
+                        position++;
+                    } else {
                         return true;
                     }
-                    while (position < associatedMap->elementData.length()) {
-                        if (associatedMap->elementData[position] == NULL) {
-                            position++;
-                        } else {
-                            return true;
-                        }
-                    }
-                    return false;
                 }
+                return false;
+            }
 
-                void checkConcurrentMod() const {
-                    if (expectedModCount != associatedMap->modCount) {
-                        throw ConcurrentModificationException(
-                            __FILE__, __LINE__, "HashMap modified outside this iterator");
-                    }
+            void checkConcurrentMod() const {
+                if (expectedModCount != associatedMap->modCount) {
+                    throw ConcurrentModificationException(
+                        __FILE__, __LINE__, "HashMap modified outside this iterator");
                 }
+            }
 
-                void makeNext() {
-                    checkConcurrentMod();
+            void makeNext() {
+                checkConcurrentMod();
 
-                    if (!checkHasNext()) {
-                        throw NoSuchElementException(__FILE__, __LINE__, "No next element");
-                    }
+                if (!checkHasNext()) {
+                    throw NoSuchElementException(__FILE__, __LINE__, "No next element");
+                }
 
-                    if (futureEntry == NULL) {
-                        currentEntry = associatedMap->elementData[position++];
-                        futureEntry = currentEntry->next;
-                        prevEntry = NULL;
-                    } else {
-                        if (currentEntry != NULL){
-                            prevEntry = currentEntry;
-                        }
-                        currentEntry = futureEntry;
-                        futureEntry = futureEntry->next;
+                if (futureEntry == NULL) {
+                    currentEntry = associatedMap->elementData[position++];
+                    futureEntry = currentEntry->next;
+                    prevEntry = NULL;
+                } else {
+                    if (currentEntry != NULL){
+                        prevEntry = currentEntry;
                     }
+                    currentEntry = futureEntry;
+                    futureEntry = futureEntry->next;
                 }
-            };
+            }
+        };
 
-            class ConstEntryIterator : public Iterator< MapEntry<K,V> >, public ConstAbstractMapIterator {
-            private:
+        class ConstEntryIterator : public Iterator< MapEntry<K,V> >, public ConstAbstractMapIterator {
+        private:
 
-                ConstEntryIterator(const ConstEntryIterator&);
-                ConstEntryIterator& operator= (const ConstEntryIterator&);
+            ConstEntryIterator(const ConstEntryIterator&);
+            ConstEntryIterator& operator= (const ConstEntryIterator&);
 
-            public:
+        public:
 
-                ConstEntryIterator(const HashMap* parent) : ConstAbstractMapIterator(parent) {
-                }
+            ConstEntryIterator(const HashMap* parent) : ConstAbstractMapIterator(parent) {
+            }
 
-                virtual ~ConstEntryIterator() {}
+            virtual ~ConstEntryIterator() {}
 
-                virtual bool hasNext() const {
-                    return this->checkHasNext();
-                }
+            virtual bool hasNext() const {
+                return this->checkHasNext();
+            }
 
-                virtual MapEntry<K, V> next() {
-                    this->makeNext();
-                    return *(this->currentEntry);
-                }
+            virtual MapEntry<K, V> next() {
+                this->makeNext();
+                return *(this->currentEntry);
+            }
 
-                virtual void remove() {
-                    throw lang::exceptions::UnsupportedOperationException(
-                        __FILE__, __LINE__, "Cannot write to a const Iterator." );
-                }
-            };
+            virtual void remove() {
+                throw lang::exceptions::UnsupportedOperationException(
+                    __FILE__, __LINE__, "Cannot write to a const Iterator." );
+            }
+        };
 
-            class ConstKeyIterator : public Iterator<K>, public ConstAbstractMapIterator {
-            private:
+        class ConstKeyIterator : public Iterator<K>, public ConstAbstractMapIterator {
+        private:
 
-                ConstKeyIterator(const ConstKeyIterator&);
-                ConstKeyIterator& operator= (const ConstKeyIterator&);
+            ConstKeyIterator(const ConstKeyIterator&);
+            ConstKeyIterator& operator= (const ConstKeyIterator&);
 
-            public:
+        public:
 
-                ConstKeyIterator(const HashMap* parent) : ConstAbstractMapIterator(parent) {
-                }
+            ConstKeyIterator(const HashMap* parent) : ConstAbstractMapIterator(parent) {
+            }
 
-                virtual ~ConstKeyIterator() {}
+            virtual ~ConstKeyIterator() {}
 
-                virtual bool hasNext() const {
-                    return this->checkHasNext();
-                }
+            virtual bool hasNext() const {
+                return this->checkHasNext();
+            }
 
-                virtual K next() {
-                    this->makeNext();
-                    return this->currentEntry->getKey();
-                }
+            virtual K next() {
+                this->makeNext();
+                return this->currentEntry->getKey();
+            }
 
-                virtual void remove() {
-                    throw lang::exceptions::UnsupportedOperationException(
-                        __FILE__, __LINE__, "Cannot write to a const Iterator." );
-                }
-            };
+            virtual void remove() {
+                throw lang::exceptions::UnsupportedOperationException(
+                    __FILE__, __LINE__, "Cannot write to a const Iterator." );
+            }
+        };
 
-            class ConstValueIterator : public Iterator<V>, public ConstAbstractMapIterator {
-            private:
+        class ConstValueIterator : public Iterator<V>, public ConstAbstractMapIterator {
+        private:
 
-                ConstValueIterator(const ConstValueIterator&);
-                ConstValueIterator& operator= (const ConstValueIterator&);
+            ConstValueIterator(const ConstValueIterator&);
+            ConstValueIterator& operator= (const ConstValueIterator&);
 
-            public:
+        public:
 
-                ConstValueIterator(const HashMap* parent) : ConstAbstractMapIterator(parent) {
-                }
+            ConstValueIterator(const HashMap* parent) : ConstAbstractMapIterator(parent) {
+            }
 
-                virtual ~ConstValueIterator() {}
+            virtual ~ConstValueIterator() {}
 
-                virtual bool hasNext() const {
-                    return this->checkHasNext();
-                }
+            virtual bool hasNext() const {
+                return this->checkHasNext();
+            }
 
-                virtual V next() {
-                    this->makeNext();
-                    return this->currentEntry->getValue();
-                }
+            virtual V next() {
+                this->makeNext();
+                return this->currentEntry->getValue();
+            }
 
-                virtual void remove() {
-                    throw lang::exceptions::UnsupportedOperationException(
-                        __FILE__, __LINE__, "Cannot write to a const Iterator." );
-                }
-            };
+            virtual void remove() {
+                throw lang::exceptions::UnsupportedOperationException(
+                    __FILE__, __LINE__, "Cannot write to a const Iterator." );
+            }
+        };
 
     private:
 
@@ -462,10 +462,6 @@ namespace util {
 
             virtual ~HashMapEntrySet() {}
 
-            HashMap* hashMap() {
-                return this->associatedMap;
-            }
-
             virtual int size() const {
                 return associatedMap->elementCount;
             }
@@ -519,10 +515,6 @@ namespace util {
 
             virtual ~ConstHashMapEntrySet() {}
 
-            HashMap* hashMap() {
-                return this->associatedMap;
-            }
-
             virtual int size() const {
                 return associatedMap->elementCount;
             }
@@ -546,7 +538,8 @@ namespace util {
             }
 
             virtual Iterator< MapEntry<K, V> >* iterator() {
-                return new ConstEntryIterator(associatedMap);
+                throw decaf::lang::exceptions::UnsupportedOperationException(
+                        __FILE__, __LINE__, "Can't return a non-const iterator for a const collection");
             }
 
             virtual Iterator< MapEntry<K, V> >* iterator() const {
@@ -603,45 +596,130 @@ namespace util {
             }
         };
 
+        class ConstHashMapKeySet : public AbstractSet<K> {
         private:
 
-            class HashMapValueCollection : public AbstractCollection<V> {
-            private:
+            const HashMap* associatedMap;
 
-                HashMap* associatedMap;
+        private:
 
-            private:
+            ConstHashMapKeySet(const ConstHashMapKeySet&);
+            ConstHashMapKeySet& operator= (const ConstHashMapKeySet&);
 
-                HashMapValueCollection(const HashMapValueCollection&);
-                HashMapValueCollection& operator= (const HashMapValueCollection&);
+        public:
 
-            public:
+            ConstHashMapKeySet(const HashMap* parent) : AbstractSet<K>(), associatedMap(parent) {
+            }
 
-                HashMapValueCollection(HashMap* parent) : AbstractCollection<V>(), associatedMap(parent) {
-                }
+            virtual ~ConstHashMapKeySet() {}
 
-                virtual ~HashMapValueCollection() {}
+            virtual bool contains(const K& key) const {
+                return this->associatedMap->containsKey(key);
+            }
 
-                virtual bool contains(const V& value) const {
-                    return this->associatedMap->containsValue(value);
-                }
+            virtual int size() const {
+                return this->associatedMap->size();
+            }
 
-                virtual int size() const {
-                    return this->associatedMap->size();
-                }
+            virtual void clear() {
+                throw decaf::lang::exceptions::UnsupportedOperationException(
+                        __FILE__, __LINE__, "Can't modify a const collection");
+            }
 
-                virtual void clear() {
-                    this->associatedMap->clear();
-                }
+            virtual bool remove(const K& key) {
+                throw decaf::lang::exceptions::UnsupportedOperationException(
+                        __FILE__, __LINE__, "Can't modify a const collection");
+            }
 
-                virtual Iterator<V>* iterator() {
-                    return new ValueIterator(this->associatedMap);
-                }
+            virtual Iterator<K>* iterator() {
+                throw decaf::lang::exceptions::UnsupportedOperationException(
+                        __FILE__, __LINE__, "Can't return a non-const iterator for a const collection");
+            }
 
-                virtual Iterator<V>* iterator() const {
-                    return new ConstValueIterator(this->associatedMap);
-                }
-            };
+            virtual Iterator<K>* iterator() const {
+                return new ConstKeyIterator(this->associatedMap);
+            }
+        };
+
+    private:
+
+        class HashMapValueCollection : public AbstractCollection<V> {
+        private:
+
+            HashMap* associatedMap;
+
+        private:
+
+            HashMapValueCollection(const HashMapValueCollection&);
+            HashMapValueCollection& operator= (const HashMapValueCollection&);
+
+        public:
+
+            HashMapValueCollection(HashMap* parent) : AbstractCollection<V>(), associatedMap(parent) {
+            }
+
+            virtual ~HashMapValueCollection() {}
+
+            virtual bool contains(const V& value) const {
+                return this->associatedMap->containsValue(value);
+            }
+
+            virtual int size() const {
+                return this->associatedMap->size();
+            }
+
+            virtual void clear() {
+                this->associatedMap->clear();
+            }
+
+            virtual Iterator<V>* iterator() {
+                return new ValueIterator(this->associatedMap);
+            }
+
+            virtual Iterator<V>* iterator() const {
+                return new ConstValueIterator(this->associatedMap);
+            }
+        };
+
+        class ConstHashMapValueCollection : public AbstractCollection<V> {
+        private:
+
+            const HashMap* associatedMap;
+
+        private:
+
+            ConstHashMapValueCollection(const ConstHashMapValueCollection&);
+            ConstHashMapValueCollection& operator= (const ConstHashMapValueCollection&);
+
+        public:
+
+            ConstHashMapValueCollection(const HashMap* parent) : AbstractCollection<V>(), associatedMap(parent) {
+            }
+
+            virtual ~ConstHashMapValueCollection() {}
+
+            virtual bool contains(const V& value) const {
+                return this->associatedMap->containsValue(value);
+            }
+
+            virtual int size() const {
+                return this->associatedMap->size();
+            }
+
+            virtual void clear() {
+                throw decaf::lang::exceptions::UnsupportedOperationException(
+                        __FILE__, __LINE__, "Can't modify a const collection");
+            }
+
+            virtual Iterator<V>* iterator() {
+                throw decaf::lang::exceptions::UnsupportedOperationException(
+                        __FILE__, __LINE__, "Can't return a non-const iterator for a const collection");
+            }
+
+            virtual Iterator<V>* iterator() const {
+                return new ConstValueIterator(this->associatedMap);
+            }
+        };
 
     private:
 
@@ -676,6 +754,16 @@ namespace util {
          */
         int threshold;
 
+        // Cached values that are only initialized once a request for them is made.
+        decaf::lang::Pointer<HashMapEntrySet> cachedEntrySet;
+        decaf::lang::Pointer<HashMapKeySet> cachedKeySet;
+        decaf::lang::Pointer<HashMapValueCollection> cachedValueCollection;
+
+        // Cached values that are only initialized once a request for them is made.
+        mutable decaf::lang::Pointer<ConstHashMapEntrySet> cachedConstEntrySet;
+        mutable decaf::lang::Pointer<ConstHashMapKeySet> cachedConstKeySet;
+        mutable decaf::lang::Pointer<ConstHashMapValueCollection> cachedConstValueCollection;
+
     private:
 
         void computeThreshold() {
@@ -859,8 +947,12 @@ namespace util {
                     __FILE__, __LINE__, "The specified key is not present in the Map");
         }
 
-        virtual void put(const K& key, const V& value) {
-            this->putImpl(key, value);
+        virtual bool put(const K& key, const V& value) {
+            return this->putImpl(key, value);
+        }
+
+        virtual bool put(const K& key, const V& value, V& oldValue) {
+            return this->putImpl(key, value, oldValue);
         }
 
         virtual void putAll(const Map<K, V>& map) {
@@ -881,28 +973,46 @@ namespace util {
                 __FILE__, __LINE__, "Specified key not present in the Map.");
         }
 
-        virtual Set< MapEntry<K,V> >* entrySet() {
-            return new HashMapEntrySet(this);
+        virtual Set< MapEntry<K,V> >& entrySet() {
+            if (this->cachedEntrySet == NULL) {
+                this->cachedEntrySet.reset(new HashMapEntrySet(this));
+            }
+            return *(this->cachedEntrySet);
         }
 
-        virtual Set< MapEntry<K,V> >* entrySet() const {
-            return new ConstHashMapEntrySet(this);
+        virtual const Set< MapEntry<K,V> >& entrySet() const {
+            if (this->cachedConstEntrySet == NULL) {
+                this->cachedConstEntrySet.reset(new ConstHashMapEntrySet(this));
+            }
+            return *(this->cachedConstEntrySet);
         }
 
-        virtual std::vector<K> keySet() const {
-            return std::vector<K>();
+        virtual Set<K>& keySet() {
+            if (this->cachedKeySet == NULL) {
+                this->cachedKeySet.reset(new HashMapKeySet(this));
+            }
+            return *(this->cachedKeySet);
         }
 
-        virtual Set<K>* keySet() {
-            return new HashMapKeySet(this);
+        virtual const Set<K>& keySet() const {
+            if (this->cachedConstKeySet == NULL) {
+                this->cachedConstKeySet.reset(new ConstHashMapKeySet(this));
+            }
+            return *(this->cachedConstKeySet);
         }
 
-        virtual Collection<V>* values() {
-            return new HashMapValueCollection(this);
+        virtual Collection<V>& values() {
+            if (this->cachedValueCollection == NULL) {
+                this->cachedValueCollection.reset(new HashMapValueCollection(this));
+            }
+            return *(this->cachedValueCollection);
         }
 
-        virtual std::vector<V> values() const {
-            return std::vector<V>();
+        virtual const Collection<V>& values() const {
+            if (this->cachedConstValueCollection == NULL) {
+                this->cachedConstValueCollection.reset(new ConstHashMapValueCollection(this));
+            }
+            return *(this->cachedConstValueCollection);
         }
 
         virtual bool equals(const Map<K, V>& source) const {
@@ -935,8 +1045,34 @@ namespace util {
             return result;
         }
 
-        void putImpl(const K& key, const V& value) {
+        bool putImpl(const K& key, const V& value, V& oldValue) {
+            bool replaced = true;
+            HashMapEntry* entry = NULL;
+
+            int hash = hashFunc(key);
+            int index = hash & (elementData.length() - 1);
+
+            entry = findKeyEntry(key, index, hash);
+
+            if (entry == NULL) {
+                modCount++;
+                entry = createHashedEntry(key, index, hash);
+                if (++elementCount > threshold) {
+                    rehash();
+                }
+                replaced = false;
+            } else {
+                oldValue = entry->getValue();
+            }
+
+            entry->setValue(value);
+
+            return replaced;
+        }
+
+        bool putImpl(const K& key, const V& value) {
 
+            bool replaced = true;
             HashMapEntry* entry = NULL;
 
             int hash = hashFunc(key);
@@ -950,9 +1086,12 @@ namespace util {
                 if (++elementCount > threshold) {
                     rehash();
                 }
+                replaced = false;
             }
 
             entry->setValue(value);
+
+            return replaced;
         }
 
         void putAllImpl(const Map<K, V>& map) {
@@ -961,8 +1100,7 @@ namespace util {
                 rehash(capacity);
             }
 
-            decaf::lang::Pointer<Set< MapEntry<K,V> > > entries(map.entrySet());
-            decaf::lang::Pointer<Iterator< MapEntry<K,V> > > iterator(entries->iterator());
+            decaf::lang::Pointer<Iterator< MapEntry<K,V> > > iterator(map.entrySet().iterator());
             while (iterator->hasNext()) {
                 MapEntry<K, V> entry = iterator->next();
                 this->putImpl(entry.getKey(), entry.getValue());

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=1365834&r1=1365833&r2=1365834&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 Wed Jul 25 22:57:11 2012
@@ -23,8 +23,8 @@
 #include <decaf/lang/exceptions/UnsupportedOperationException.h>
 #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/Collection.h>
 #include <decaf/util/MapEntry.h>
 
 namespace decaf{
@@ -91,45 +91,63 @@ namespace util{
         /**
          * Default constructor - does nothing.
          */
-        Map() {}
+        Map() : concurrent::Synchronizable() {}
 
         virtual ~Map() {}
 
         /**
-         * Comparison, equality is dependent on the method of determining
-         * if the element are equal.
-         * @param source - Map to compare to this one.
+         * Compares the specified object with this map for equality. Returns true if the two
+         * maps represent the same mappings. More formally, two maps m1 and m2 represent the
+         * same mappings if m1.entrySet().equals(m2.entrySet()). This ensures that the equals
+         * method works properly across different implementations of the Map interface.
+         *
+         * @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;
 
         /**
-         * 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.
+         * Copies the content of the source map into this map.  Erases all existing mappings
+         * in this map.  The copy is performed by using the entrySet of the source Map and
+         * iterating over those entries, inserting each into the target.
+         *
+         * @param source
+         *      The source object to copy from.
          */
         virtual void copy(const Map& source) = 0;
 
         /**
-         * Removes all keys and values from this map.
-         * @throw UnsupportedOperationException if this map is unmodifiable.
+         * Removes all of the mappings from this map (optional operation). The map will
+         * be empty after this call returns.
+         *
+         * @throw UnsupportedOperationException if the clear operation is not supported by this map.
          */
         virtual void clear() = 0;
 
         /**
-         * Indicates whether or this map contains a value for the
-         * given key.
-         * @param key The key to look up.
-         * @return true if this map contains the value, otherwise false.
+         * Returns true if this map contains a mapping for the specified key. More formally,
+         * returns true if and only if this map contains a mapping for a key k such that
+         * (key == k). (There can be at most one such mapping.)
+         *
+         * @param key
+         *      The key to look up.
+         *
+         * @return true if this map contains the key mapping, otherwise false.
          */
         virtual bool containsKey(const K& key) const = 0;
 
         /**
-         * Indicates whether or this map contains a value for the
-         * given value, i.e. they are equal, this is done by operator==
-         * so the types must pass equivalence testing in this manner.
-         * @param value The Value to look up.
-         * @return true if this map contains the value, otherwise false.
+         * Returns true if this map maps one or more keys to the specified value. More
+         * formally, returns true if and only if this map contains at least one mapping to
+         * a value v such that (value==v). This operation will probably require time linear
+         * in the map size for most implementations of the Map interface.
+         *
+         * @param value
+         *      The Value to look up in this Map.
+         *
+         * @return true if this map contains at least one mapping for the value, otherwise false.
          */
         virtual bool containsValue(const V& value) const = 0;
 
@@ -148,8 +166,10 @@ namespace util{
          * element in the map whose key is equivalent to the key provided then a
          * NoSuchElementException is thrown.
          *
-         * @param key The search key.
-         * @return A reference to the value for the given key.
+         * @param key
+         *      The search key whose value should be returned if present.
+         *
+         * @return A reference to the value for the given key if present in the Map.
          *
          * @throws NoSuchElementException if the key requests doesn't exist in the Map.
          */
@@ -160,24 +180,68 @@ namespace util{
          * element in the map whose key is equivalent to the key provided then a
          * NoSuchElementException is thrown.
          *
-         * @param key The search key.
-         * @return A {const} reference to the value for the given key.
+         * @param key
+         *      The search key whose value should be returned if present.
+         *
+         * @return A const reference to the value for the given key if present in the Map.
          *
          * @throws NoSuchElementException if the key requests doesn't exist in the Map.
          */
         virtual const V& get(const K& key) const = 0;
 
         /**
-         * Sets the value for the specified key.
-         * @param key The target key.
-         * @param value The value to be set.
+         * Associates the specified value with the specified key in this map (optional
+         * operation). If the map previously contained a mapping for the key, the old value
+         * is replaced by the specified value. (A map m is said to contain a mapping for a
+         * key k if and only if m.containsKey(k) would return true.)
          *
-         * @throw UnsupportedOperationException if this map is unmodifiable.
+         * @param key
+         *      The target key.
+         * @param value
+         *      The value to be set.
+         *
+         * @returns true if the put operation replaced a value that was associated with
+         *          an existing mapping to the given key or false otherwise.
+         *
+         * @throws UnsupportedOperationException if this map is unmodifiable.
+         * @throws IllegalArgumentException if some property of the specified key or value
+         *                                  prevents it from being stored in this map
          */
-        virtual void put(const K& key, const V& value) = 0;
+        virtual bool put(const K& key, const V& value) = 0;
 
         /**
-         * Stores a copy of the Mappings contained in the other Map in this one.
+         * Associates the specified value with the specified key in this map (optional
+         * operation). If the map previously contained a mapping for the key, the old value
+         * is replaced by the specified value. (A map m is said to contain a mapping for a
+         * key k if and only if m.containsKey(k) would return true.)
+         *
+         * This method accepts a reference to a value which will be assigned the previous
+         * value for the given key (if any).  If there was no previous mapping for the
+         * given key the out value is not written to.  A return of true indicates that a
+         * value was replaced by this put operation.
+         *
+         * @param key
+         *      The target key.
+         * @param value
+         *      The value to be set.
+         * @param oldValue (out)
+         *      The value previously held in the mapping for this key.  .
+         *
+         * @returns true if the put operation replaced a value that was associated with
+         *          an existing mapping to the given key or false otherwise.
+         *
+         * @throws UnsupportedOperationException if this map is unmodifiable.
+         * @throws IllegalArgumentException if some property of the specified key or value
+         *                                  prevents it from being stored in this map
+         */
+        virtual bool put(const K& key, const V& value, V& oldValue) = 0;
+
+        /**
+         * Copies all of the mappings from the specified map to this map (optional operation).
+         * The effect of this call is equivalent to that of calling put(k, v) on this map once
+         * for each mapping from key k to value v in the specified map. The behavior of this
+         * operation is undefined if the specified map is modified while the operation is in
+         * progress.
          *
          * @param other
          *      A Map instance whose elements are to all be inserted in this Map.
@@ -188,11 +252,14 @@ namespace util{
         virtual void putAll(const Map<K, V>& other) = 0;
 
         /**
-         * Removes the value (key/value pair) for the specified key from
-         * the map, returns a copy of the value that was mapped to the key.
+         * Removes the value (key/value pair) for the specified key from the map, returns
+         * a copy of the value that was mapped to the key.  Care must be taken when using this
+         * operation as it will throw an exception if there is no mapping for the given key.
+         *
+         * @param key
+         *      The search key whose mapping is to be removed.
          *
-         * @param key The search key.
-         * @return a copy of the element that was previously mapped to the given key
+         * @return a copy of the element that was previously mapped to the given key.
          *
          * @throw NoSuchElementException if this key is not in the Map.
          * @throw UnsupportedOperationException if this map is unmodifiable.
@@ -209,21 +276,39 @@ namespace util{
          * 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.
+         * @returns a reference  to a Set<MapEntry<K,V>> that is backed by this Map.
          */
-        virtual Set< MapEntry<K,V> >* entrySet() = 0;
-        virtual Set< MapEntry<K,V> >* entrySet() const = 0;
+        virtual Set< MapEntry<K,V> >& entrySet() = 0;
+        virtual const Set< MapEntry<K,V> >& entrySet() const = 0;
 
         /**
-         * @return the entire set of keys in this map as a std::vector.
+         * Returns a Set view of the keys contained in this map. The set is backed by the map,
+         * so changes to the map are reflected in the set, and vice-versa. If the map is modified
+         * while an iteration over the set is in progress (except through the iterator's own
+         * remove operation), the results of the iteration are undefined. The set supports element
+         * 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.
+         *
+         * @return a set view of the keys contained in this map,
          */
-        virtual std::vector<K> keySet() const = 0;
+        virtual Set<K>& keySet() = 0;
+        virtual const Set<K>& keySet() const = 0;
 
         /**
-         * @return the entire set of values in this map as a std::vector.
+         * Returns a Collection view of the values contained in this map. The collection is backed
+         * by the map, so changes to the map are reflected in the collection, and vice-versa. If
+         * the map is modified while an iteration over the collection is in progress (except
+         * through the iterator's own remove operation), the results of the iteration are
+         * undefined. The collection supports element removal, which removes the corresponding
+         * mapping from the map, via the Iterator.remove, Collection.remove, removeAll, retainAll
+         * and clear operations. It does not support the add or addAll operations.  For the const
+         * version of this method the Collection can only be used as a view into the Map.
+         *
+         * @return a collection view of the values contained in this map.
          */
-        virtual std::vector<V> values() const = 0;
+        virtual Collection<V>& values() = 0;
+        virtual const Collection<V>& values() const = 0;
 
     };
 

Modified: 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=1365834&r1=1365833&r2=1365834&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/MapEntry.h (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/MapEntry.h Wed Jul 25 22:57:11 2012
@@ -35,6 +35,9 @@ namespace util {
         MapEntry() : key(), value() {
         }
 
+        MapEntry(const K& key, const V& value) : key(key), value(value) {
+        }
+
         virtual ~MapEntry() {};
 
         virtual void setKey(K key) {
@@ -70,7 +73,7 @@ namespace util {
                 return false;
             }
 
-            if (!(this->value != entry.getValue())) {
+            if (!(this->value == entry.getValue())) {
                 return false;
             }
 

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/Properties.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/Properties.cpp?rev=1365834&r1=1365833&r2=1365834&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/Properties.cpp (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/Properties.cpp Wed Jul 25 22:57:11 2012
@@ -22,6 +22,7 @@
 #include <decaf/util/Date.h>
 #include <decaf/util/Map.h>
 #include <decaf/util/StlMap.h>
+#include <decaf/util/Collections.h>
 #include <decaf/io/BufferedInputStream.h>
 #include <decaf/lang/Character.h>
 #include <decaf/lang/Integer.h>
@@ -104,6 +105,7 @@ namespace {
                         }
                         buffer << hex;
                     }
+                    break;
             }
         }
     }
@@ -241,12 +243,11 @@ std::vector< std::pair< std::string, std
     std::vector< std::pair<std::string, std::string> > result;
 
     synchronized( &( internal->properties ) ) {
-        std::vector<std::string> keys = this->internal->properties.keySet();
-        std::vector<std::string>::const_iterator iter = keys.begin();
-
-        for( ; iter != keys.end(); ++iter ) {
-            result.push_back(
-                std::make_pair( *iter, this->internal->properties.get( *iter ) ) );
+        Pointer< Iterator< MapEntry<std::string, std::string> > > entries(
+                this->internal->properties.entrySet().iterator());
+        while (entries->hasNext()) {
+            MapEntry<std::string, std::string> entry = entries->next();
+            result.push_back(std::make_pair(entry.getKey(), entry.getValue()));
         }
     }
 
@@ -302,12 +303,11 @@ std::string Properties::toString() const
     stream << "Begin Class decaf::util::Properties:" << std::endl;
 
     synchronized( &( internal->properties ) ) {
-        std::vector<std::string> keys = this->internal->properties.keySet();
-        std::vector<std::string>::const_iterator iter = keys.begin();
-
-        for( iter = keys.begin(); iter != keys.end(); ++iter ){
-            stream << " property[" << *iter << "] = "
-                   << this->internal->properties.get( *iter ) << std::endl;
+        Pointer< Iterator< MapEntry<std::string, std::string> > > entries(
+                this->internal->properties.entrySet().iterator());
+        while (entries->hasNext()) {
+            MapEntry<std::string, std::string> entry = entries->next();
+            stream << " property[" << entry.getKey() << "] = " << entry.getValue() << std::endl;
         }
     }
 
@@ -318,12 +318,9 @@ std::string Properties::toString() const
 
 ////////////////////////////////////////////////////////////////////////////////
 std::vector<std::string> Properties::propertyNames() const {
-
     StlMap<std::string, std::string> selectedProperties;
-
     this->selectProperties( selectedProperties );
-
-    return selectedProperties.keySet();
+    return Collections::toStlVector<std::string>(selectedProperties.keySet());
 }
 
 ////////////////////////////////////////////////////////////////////////////////
@@ -333,11 +330,11 @@ void Properties::selectProperties( StlMa
         this->defaults->selectProperties( selectProperties );
     }
 
-    std::vector<std::string> keys = this->internal->properties.keySet();
-    std::vector<std::string>::const_iterator key = keys.begin();
-
-    for( ; key != keys.end(); ++key ) {
-        selectProperties.put( *key, this->internal->properties.get( *key ) );
+    Pointer< Iterator< MapEntry<std::string, std::string> > > entries(
+            this->internal->properties.entrySet().iterator());
+    while (entries->hasNext()) {
+        MapEntry<std::string, std::string> entry = entries->next();
+        selectProperties.put(entry.getKey(), entry.getValue());
     }
 }
 
@@ -549,14 +546,14 @@ void Properties::store( decaf::io::Outpu
         writer << Date().toString();
         writer << std::endl;
 
-        std::vector<std::string> keys = this->internal->properties.keySet();
-        std::vector<std::string>::const_iterator key = keys.begin();
-
-        for( ; key != keys.end(); ++key ) {
+        Pointer< Iterator< MapEntry<std::string, std::string> > > entries(
+                this->internal->properties.entrySet().iterator());
+        while (entries->hasNext()) {
+            MapEntry<std::string, std::string> entry = entries->next();
 
-            dumpString( buffer, *key, true );
+            dumpString( buffer, entry.getKey(), true );
             buffer << "=";
-            dumpString( buffer, this->internal->properties.get( *key ), false );
+            dumpString( buffer, entry.getValue(), false );
             buffer << std::endl;
 
             writer << buffer.str();