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 2013/04/09 00:44:34 UTC

svn commit: r1465817 - in /activemq/activemq-cpp/trunk/activemq-cpp/src: main/decaf/util/Collections.h test/Makefile.am test/decaf/util/CollectionsTest.cpp test/decaf/util/CollectionsTest.h test/testRegistry.cpp

Author: tabish
Date: Mon Apr  8 22:44:33 2013
New Revision: 1465817

URL: http://svn.apache.org/r1465817
Log:
Add Collections::reverse

Added:
    activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/CollectionsTest.cpp   (with props)
    activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/CollectionsTest.h   (with props)
Modified:
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/Collections.h
    activemq/activemq-cpp/trunk/activemq-cpp/src/test/Makefile.am
    activemq/activemq-cpp/trunk/activemq-cpp/src/test/testRegistry.cpp

Modified: 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=1465817&r1=1465816&r2=1465817&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/Collections.h (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/Collections.h Mon Apr  8 22:44:33 2013
@@ -22,6 +22,9 @@
 
 #include <decaf/util/Collection.h>
 #include <decaf/util/Iterator.h>
+#include <decaf/util/ListIterator.h>
+#include <decaf/util/List.h>
+#include <decaf/lang/Pointer.h>
 
 #include <vector>
 #include <memory>
@@ -38,6 +41,28 @@ namespace util {
 
     public:
 
+        /**
+         * Modifies the specified List by reversing the order of the elements.
+         *
+         * @param list
+         *      The list to reverse.
+         * @throws UnsupportedOperationException
+         *      when replacing an element in the List is not supported.
+         */
+        template<typename E>
+        static void reverse(List<E>& list) {
+            int size = list.size();
+            decaf::lang::Pointer<ListIterator<E> > front(list.listIterator());
+            decaf::lang::Pointer<ListIterator<E> > back(list.listIterator(size));
+
+            for (int i = 0; i < size / 2; i++) {
+                E frontNext = front->next();
+                E backPrev = back->previous();
+                front->set(backPrev);
+                back->set(frontNext);
+            }
+        }
+
     };
 
 }}

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/test/Makefile.am
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/test/Makefile.am?rev=1465817&r1=1465816&r2=1465817&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/test/Makefile.am (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/test/Makefile.am Mon Apr  8 22:44:33 2013
@@ -202,6 +202,7 @@ cc_sources = \
     decaf/util/ArrayListTest.cpp \
     decaf/util/ArraysTest.cpp \
     decaf/util/BitSetTest.cpp \
+    decaf/util/CollectionsTest.cpp \
     decaf/util/DateTest.cpp \
     decaf/util/Endian.cpp \
     decaf/util/HashCodeTest.cpp \
@@ -451,6 +452,7 @@ h_sources = \
     decaf/util/ArrayListTest.h \
     decaf/util/ArraysTest.h \
     decaf/util/BitSetTest.h \
+    decaf/util/CollectionsTest.h \
     decaf/util/DateTest.h \
     decaf/util/Endian.h \
     decaf/util/HashCodeTest.h \

Added: activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/CollectionsTest.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/CollectionsTest.cpp?rev=1465817&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/CollectionsTest.cpp (added)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/CollectionsTest.cpp Mon Apr  8 22:44:33 2013
@@ -0,0 +1,63 @@
+/*
+ * 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 "CollectionsTest.h"
+
+#include <decaf/util/ArrayList.h>
+#include <decaf/util/LinkedList.h>
+#include <decaf/util/Collections.h>
+
+using namespace decaf;
+using namespace decaf::util;
+
+////////////////////////////////////////////////////////////////////////////////
+CollectionsTest::CollectionsTest() {
+}
+
+////////////////////////////////////////////////////////////////////////////////
+CollectionsTest::~CollectionsTest() {
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void CollectionsTest::testReverseList() {
+
+    {
+        ArrayList<int> list;
+
+        for (int i = 0; i < 50; ++i) {
+            list.add(i);
+        }
+
+        Collections::reverse(list);
+
+        CPPUNIT_ASSERT_EQUAL(0, list.get(49));
+        CPPUNIT_ASSERT_EQUAL(49, list.get(0));
+    }
+
+    {
+        LinkedList<int> list;
+
+        for (int i = 0; i < 50; ++i) {
+            list.add(i);
+        }
+
+        Collections::reverse(list);
+
+        CPPUNIT_ASSERT_EQUAL(0, list.getLast());
+        CPPUNIT_ASSERT_EQUAL(49, list.getFirst());
+    }
+}

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

Added: activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/CollectionsTest.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/CollectionsTest.h?rev=1465817&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/CollectionsTest.h (added)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/CollectionsTest.h Mon Apr  8 22:44:33 2013
@@ -0,0 +1,44 @@
+/*
+ * 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_COLLECTIONSTEST_H_
+#define _DECAF_UTIL_COLLECTIONSTEST_H_
+
+#include <cppunit/TestFixture.h>
+#include <cppunit/extensions/HelperMacros.h>
+
+namespace decaf {
+namespace util {
+
+    class CollectionsTest : public CppUnit::TestFixture {
+
+        CPPUNIT_TEST_SUITE( CollectionsTest );
+        CPPUNIT_TEST( testReverseList );
+        CPPUNIT_TEST_SUITE_END();
+
+    public:
+
+        CollectionsTest();
+        virtual ~CollectionsTest();
+
+        void testReverseList();
+
+    };
+
+}}
+
+#endif /* _DECAF_UTIL_COLLECTIONSTEST_H_ */

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

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/test/testRegistry.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/test/testRegistry.cpp?rev=1465817&r1=1465816&r2=1465817&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/test/testRegistry.cpp (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/test/testRegistry.cpp Mon Apr  8 22:44:33 2013
@@ -326,6 +326,8 @@ CPPUNIT_TEST_SUITE_REGISTRATION( decaf::
 #include <decaf/util/concurrent/locks/ReentrantReadWriteLockTest.h>
 CPPUNIT_TEST_SUITE_REGISTRATION( decaf::util::concurrent::locks::ReentrantReadWriteLockTest );
 
+#include <decaf/util/CollectionsTest.h>
+CPPUNIT_TEST_SUITE_REGISTRATION( decaf::util::CollectionsTest );
 #include <decaf/util/HashCodeTest.h>
 CPPUNIT_TEST_SUITE_REGISTRATION( decaf::util::HashCodeTest );
 #include <decaf/util/LinkedHashMapTest.h>