activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject svn commit: r744952 - in /activemq/activemq-cpp/trunk/src/main/decaf/util: AbstractCollection.h AbstractSet.h Collection.h ListIterator.h Map.h StlList.h StlSet.h
Date Mon, 16 Feb 2009 16:01:45 GMT
Author: tabish
Date: Mon Feb 16 16:01:43 2009
New Revision: 744952

URL: http://svn.apache.org/viewvc?rev=744952&view=rev
Log:
Further implementation of the Decaf Collections API

Modified:
    activemq/activemq-cpp/trunk/src/main/decaf/util/AbstractCollection.h
    activemq/activemq-cpp/trunk/src/main/decaf/util/AbstractSet.h
    activemq/activemq-cpp/trunk/src/main/decaf/util/Collection.h
    activemq/activemq-cpp/trunk/src/main/decaf/util/ListIterator.h
    activemq/activemq-cpp/trunk/src/main/decaf/util/Map.h
    activemq/activemq-cpp/trunk/src/main/decaf/util/StlList.h
    activemq/activemq-cpp/trunk/src/main/decaf/util/StlSet.h

Modified: activemq/activemq-cpp/trunk/src/main/decaf/util/AbstractCollection.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/decaf/util/AbstractCollection.h?rev=744952&r1=744951&r2=744952&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/decaf/util/AbstractCollection.h (original)
+++ activemq/activemq-cpp/trunk/src/main/decaf/util/AbstractCollection.h Mon Feb 16 16:01:43
2009
@@ -64,29 +64,95 @@
 
         virtual ~AbstractCollection() {}
 
+        /**
+         * Ensures that this collection contains the specified element (optional operation).
+         * Returns true if this collection changed as a result of the call. (Returns false
if
+         * this collection does not permit duplicates and already contains the specified
element.)
+         *
+         * Collections that support this operation may place limitations on what elements
may be
+         * added to this collection. Collection classes should clearly specify in their
+         * documentation any restrictions on what elements may be added.
+         *
+         * If a collection refuses to add a particular element for any reason other than
that it
+         * already contains the element, it must throw an exception (rather than returning
false).
+         * This preserves the invariant that a collection always contains the specified element
+         * after this call returns.
+         *
+         * This implementation always throws an UnsupportedOperationException.
+         *
+         * @param value - The element that must be ensured to be in this collection.
+         *
+         * @return true if the collection was changed as a result of this call.
+         *
+         * @throw UnsupportedOperationException
+         *        if the add operation is not supported by this collection
+         * @throw IllegalArgumentException
+         *        if some property of the element prevents it from being added to this collection
+         * @throw IllegalStateException
+         *        if the element cannot be added at this time due to insertion restrictions
+         */
         virtual bool add( const E& value DECAF_UNUSED )
             throw ( lang::exceptions::UnsupportedOperationException,
-                    lang::exceptions::IllegalArgumentException ) {
+                    lang::exceptions::IllegalArgumentException,
+                    lang::exceptions::IllegalStateException ) {
 
             throw decaf::lang::exceptions::UnsupportedOperationException(
                 __FILE__, __LINE__, "AbstractCollection add is not implemented.");
         }
 
+        /**
+         * Adds all of the elements in the specified collection to this collection (optional
+         * operation). The behavior of this operation is undefined if the specified collection
+         * is modified while the operation is in progress. (This implies that the behavior
of
+         * this call is undefined if the specified collection is this collection, and this
+         * collection is nonempty.)
+         *
+         * This implementation iterates over the specified collection, and adds each object
+         * returned by the iterator to this collection, in turn.
+         *
+         * Note that this implementation will throw an UnsupportedOperationException unless
add
+         * is overridden (assuming the specified collection is non-empty).
+         *
+         * @param collection - The Collection whose elements are to be added to this Collection.
+         *
+         * @return true if the collection was changed as a result of this call.
+         *
+         * @throw UnsupportedOperationException
+         *        if the addAll operation is not supported by this collection
+         * @throw IllegalArgumentException
+         *        if some property of the element prevents it from being added to this collection
+         * @throw IllegalStateException
+         *        if the element cannot be added at this time due to insertion restrictions
+         */
         virtual bool addAll( const Collection<E>& collection )
             throw ( lang::exceptions::UnsupportedOperationException,
-                    lang::exceptions::IllegalArgumentException ) {
+                    lang::exceptions::IllegalArgumentException,
+                    lang::exceptions::IllegalStateException ) {
 
             bool result = false;
             std::auto_ptr< Iterator<E> > iter( collection.iterator() );
             while( iter->hasNext() ) {
-                if( this->add( iter->next() ) ) {
-                    result = true;
-                }
+                result = this->add( iter->next() ) || result;
             }
 
             return result;
         }
 
+        /**
+         * Removes all of the elements from this collection (optional operation). The collection
+         * will be empty after this method returns.
+         *
+         * This implementation iterates over this collection, removing each element using
the
+         * Iterator.remove operation. Most implementations will probably choose to override
this
+         * method for efficiency.
+         *
+         * Note that this implementation will throw an UnsupportedOperationException if the
+         * iterator returned by this collection's iterator method does not implement the
remove
+         * method and this collection is non-empty.
+         *
+         * @throw UnsupportedOperationException
+         *        if the clear operation is not supported by this collection
+         */
         virtual void clear()
             throw ( lang::exceptions::UnsupportedOperationException ) {
 
@@ -97,6 +163,14 @@
             }
         }
 
+        /**
+         * Renders this Collection as a Copy of the given Collection
+         *
+         * This implementation iterates over the contents of the given collection adding
each
+         * to this collection after first calling this Collection's clear method.
+         *
+         * @param collection - the collection to mirror.
+         */
         virtual void copy( const Collection<E>& collection ) {
             this->clear();
 
@@ -106,6 +180,18 @@
             }
         }
 
+        /**
+         * Returns true if this collection contains the specified element.
+         *
+         * This implementation iterates over the elements in the collection, checking each
+         * element in turn for equality with the specified element.
+         *
+         * @param value - the value whose presence is to be queried for in this Collection.
+         *
+         * @return true if the value is contained in this collection
+         *
+         * @throw Exception if an error occurs,
+         */
         virtual bool contains( const E& value ) const throw ( lang::Exception ) {
 
             bool result = false;
@@ -119,57 +205,135 @@
             return result;
         }
 
+        /**
+         * Returns true if this collection contains all of the elements in the specified
+         * collection.
+         *
+         * This implementation iterates over the specified collection, checking each element
+         * returned by the iterator in turn to see if it's contained in this collection.
If
+         * all elements are so contained true is returned, otherwise false.
+         *
+         * @param collection
+         *        collection to be checked for containment in this collection
+         *
+         * @return true if this collection contains all of the elements in the specified
+         *         collection.
+         *
+         * @throw Exception if an error occurs,
+         */
         virtual bool containsAll( const Collection<E>& collection ) const
             throw ( lang::Exception ) {
 
             bool result = false;
             std::auto_ptr< Iterator<E> > iter( collection.iterator() );
             while( iter->hasNext() ) {
-                if( this->contains( iter->next() ) ) {
-                    result = true;
-                }
+                result = this->contains( iter->next() ) || result;
             }
 
             return result;
         }
 
+        /**
+         * Answers true if this Collection and the one given are the same size and if each
+         * element contained in the Collection given is equal to an element contained in
this
+         * collection.
+         *
+         * @param collection - The Collection to be compared to this one.
+         *
+         * @return true if this Collection is equal to the one given.
+         */
         virtual bool equals( const Collection<E>& collection ) const {
-            if( this->size() != collection.size() ) {
-                return false;
-            }
 
-            std::auto_ptr< Iterator<E> > srcIter( collection.iterator() );
-            std::auto_ptr< Iterator<E> > thisIter( this->iterator() );
+            if( this == &collection ) {
+                return true;
+            }
 
-            while( srcIter->hasNext() ) {
-                if( !( thisIter->next() == srcIter->next() ) ) {
-                    return false;
-                }
+            if( this->size() == collection.size() && this->containsAll( collection
) ) {
+                return true;
             }
 
-            return true;
+            return false;
         }
 
+        /**
+         * Returns true if this collection contains no elements.
+         *
+         * This implementation returns size() == 0.
+         *
+         * @returns true if the size method return 0.
+         */
         virtual bool isEmpty() const {
             return this->size() == 0;
         }
 
+        /**
+         * Removes a single instance of the specified element from this collection, if it
is
+         * present (optional operation). More formally, removes the first element e such
that
+         * e == o, if this collection contains one or more such elements. Returns true if
this
+         * collection contained the specified element (or equivalently, if this collection
+         * changed as a result of the call).
+         *
+         * This implementation iterates over the collection looking for the specified element.
If
+         * it finds the element, it removes the element from the collection using the iterator's
+         * remove method.
+         *
+         * Note that this implementation throws an UnsupportedOperationException if the iterator
+         * returned by this collection's iterator method does not implement the remove method
and
+         * this collection contains the specified object.
+         *
+         * @param value - element to be removed from this collection, if present
+         *
+         * @return true if an element was removed as a result of this call
+         *
+         * @throw UnsupportedOperationException
+         *        if the remove operation is not supported by this collection
+         * @throw IllegalArgumentException.
+         */
         virtual bool remove( const E& value DECAF_UNUSED )
             throw ( lang::exceptions::UnsupportedOperationException,
                     lang::exceptions::IllegalArgumentException ) {
 
-            throw decaf::lang::exceptions::UnsupportedOperationException(
-                __FILE__, __LINE__, "AbstractCollection add is not implemented.");
+            std::auto_ptr< Iterator<E> > iter( this->iterator() );
+            while( iter->hasNext() ) {
+                if( value == iter->next() ) {
+                    iter->remove();
+                    return true;
+                }
+            }
+
+            return false;
         }
 
+        /**
+         * Removes all of this collection's elements that are also contained in the specified
+         * collection (optional operation). After this call returns, this collection will
contain
+         * no elements in common with the specified collection.
+         *
+         * This implementation iterates over this collection, checking each element returned
by
+         * the iterator in turn to see if it's contained in the specified collection. If
it's so
+         * contained, it's removed from this collection with the iterator's remove method.
+         *
+         * Note that this implementation will throw an UnsupportedOperationException if the
+         * iterator returned by the iterator method does not implement the remove method
and this
+         * collection contains one or more elements in common with the specified collection.
+         *
+         * @param collection - collection containing elements to be removed from this collection
+         *
+         * @return true if this collection changed as a result of the call
+         *
+         * @throw UnsupportedOperationException
+         *        if the remove operation is not supported by this collection
+         * @throw IllegalArgumentException.
+         */
         virtual bool removeAll( const Collection<E>& collection )
             throw ( lang::exceptions::UnsupportedOperationException,
                     lang::exceptions::IllegalArgumentException ) {
 
             bool result = false;
-            std::auto_ptr< Iterator<E> > iter( collection.iterator() );
+            std::auto_ptr< Iterator<E> > iter( this->iterator() );
             while( iter->hasNext() ) {
-                if( this->remove( iter->next() ) ) {
+                if( collection.contains( iter->next() ) ) {
+                    iter->remove();
                     result = true;
                 }
             }
@@ -177,6 +341,27 @@
             return result;
         }
 
+        /**
+         * Retains only the elements in this collection that are contained in the specified
+         * collection (optional operation). In other words, removes from this collection
all of
+         * its elements that are not contained in the specified collection.
+         *
+         * This implementation iterates over this collection, checking each element returned
by
+         * the iterator in turn to see if it's contained in the specified collection. If
it's not
+         * so contained, it's removed from this collection with the iterator's remove method.
+         *
+         * Note that this implementation will throw an UnsupportedOperationException if the
+         * iterator returned by the iterator method does not implement the remove method
and this
+         * collection contains one or more elements not present in the specified collection.
+         *
+         * @param collection - collection containing elements to be retained in this collection
+         *
+         * @return true if this collection changed as a result of the call
+         *
+         * @throw UnsupportedOperationException
+         *        if the remove operation is not supported by this collection
+         * @throw IllegalArgumentException.
+         */
         virtual bool retainAll( const Collection<E>& collection )
             throw ( lang::exceptions::UnsupportedOperationException,
                     lang::exceptions::IllegalArgumentException ) {
@@ -193,6 +378,14 @@
             return result;
         }
 
+        /**
+         * Answers an STL vector containing copies of all elements contained in this Collection.
+         * All the elements in the array will not be referenced by the collection. The elements
+         * in the returned array will be sorted to the same order as those returned by the
+         * iterator of this collection itself if the collection guarantees the order.
+         *
+         * @return an vector of copies of all the elements from this Collection
+         */
         virtual std::vector<E> toArray() const {
             std::vector<E> valueArray;
             valueArray.reserve( this->size() );

Modified: activemq/activemq-cpp/trunk/src/main/decaf/util/AbstractSet.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/decaf/util/AbstractSet.h?rev=744952&r1=744951&r2=744952&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/decaf/util/AbstractSet.h (original)
+++ activemq/activemq-cpp/trunk/src/main/decaf/util/AbstractSet.h Mon Feb 16 16:01:43 2009
@@ -48,6 +48,56 @@
 
         virtual ~AbstractSet() {}
 
+        /**
+         * Removes from this set all of its elements that are contained in the specified
+         * collection (optional operation). If the specified collection is also a set, this
+         * operation effectively modifies this set so that its value is the asymmetric set
+         * difference of the two sets.
+         *
+         * This implementation determines which is the smaller of this set and the specified
+         * collection, by invoking the size method on each. If this set has fewer elements,
+         * then the implementation iterates over this set, checking each element returned
by
+         * the iterator in turn to see if it is contained in the specified collection. If
it
+         * is so contained, it is removed from this set with the iterator's remove method.
If
+         * the specified collection has fewer elements, then the implementation iterates
over
+         * the specified collection, removing from this set each element returned by the
+         * iterator, using this set's remove method.
+         *
+         * Note that this implementation will throw an UnsupportedOperationException if the
+         * iterator returned by the iterator method does not implement the remove method.
+         *
+         * @param collection - The Collection whose elements are to be retained
+         * @returns true if the collection changed as a result of this call
+         *
+         * @throw UnsupportedOperationException
+         * @throw IllegalArgumentException
+         */
+        virtual bool removeAll( const Collection<E>& collection )
+            throw ( lang::exceptions::UnsupportedOperationException,
+                    lang::exceptions::IllegalArgumentException ) {
+
+            bool result = false;
+            if( this->size() <= collection.size() ) {
+
+                std::auto_ptr< Iterator<E> > iter( this->iterator() );
+                while( iter->hasNext() ) {
+                    if( collection.contains( iter->next() ) ) {
+                        iter->remove();
+                        result = true;
+                    }
+                }
+
+            } else {
+
+                std::auto_ptr< Iterator<E> > iter( collection.iterator() );
+                while( iter->hasNext() ) {
+                    result = this->remove( iter->next() ) || result;
+                }
+            }
+
+            return result;
+        }
+
     };
 
 }}

Modified: activemq/activemq-cpp/trunk/src/main/decaf/util/Collection.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/decaf/util/Collection.h?rev=744952&r1=744951&r2=744952&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/decaf/util/Collection.h (original)
+++ activemq/activemq-cpp/trunk/src/main/decaf/util/Collection.h Mon Feb 16 16:01:43 2009
@@ -98,10 +98,13 @@
          * @returns true if the element was added
          * @throw UnsupportedOperationException
          * @throw IllegalArgumentException
+         * @throw IllegalStateException
+         *        if the element cannot be added at this time due to insertion restrictions
          */
         virtual bool add( const E& value )
             throw ( lang::exceptions::UnsupportedOperationException,
-                    lang::exceptions::IllegalArgumentException ) = 0;
+                    lang::exceptions::IllegalArgumentException,
+                    lang::exceptions::IllegalStateException ) = 0;
 
         /**
          * Adds all of the elements in the specified collection to this
@@ -110,14 +113,17 @@
          * (This implies that the behavior of this call is undefined if the
          * specified collection is this collection, and this collection is
          * nonempty.)
-         * @param source - Collection whose elements are added to this one.
+         * @param collection - Collection whose elements are added to this one.
          * @return true if this collection changed as a result of the call
          * @throw UnsupportedOperationException
          * @throw IllegalArgumentException
+         * @throw IllegalStateException
+         *        if the element cannot be added at this time due to insertion restrictions
          */
-        virtual bool addAll( const Collection<E>& source )
+        virtual bool addAll( const Collection<E>& collection )
             throw ( lang::exceptions::UnsupportedOperationException,
-                    lang::exceptions::IllegalArgumentException ) = 0;
+                    lang::exceptions::IllegalArgumentException,
+                    lang::exceptions::IllegalStateException ) = 0;
 
         /**
          * Removes all of the elements from this collection (optional operation).
@@ -141,10 +147,10 @@
         /**
          * Returns true if this collection contains all of the elements in
          * the specified collection.
-         * @param source - Collection to compare to this one.
+         * @param collection - Collection to compare to this one.
          * @throw Exception
          */
-        virtual bool containsAll( const Collection<E>& source ) const
+        virtual bool containsAll( const Collection<E>& collection ) const
             throw ( lang::Exception ) = 0;
 
         /**
@@ -181,12 +187,12 @@
          * the specified collection (optional operation). After this call returns,
          * this collection will contain no elements in common with the specified
          * collection.
-         * @param value - The Collection whose elements are to be removed
+         * @param collection - The Collection whose elements are to be removed
          * @returns true if the collection changed as a result of this call
          * @throw UnsupportedOperationException
          * @throw IllegalArgumentException
          */
-        virtual bool removeAll( const Collection<E>& value )
+        virtual bool removeAll( const Collection<E>& collection )
             throw ( lang::exceptions::UnsupportedOperationException,
                     lang::exceptions::IllegalArgumentException ) = 0;
 
@@ -195,12 +201,12 @@
          * specified collection (optional operation). In other words, removes from
          * this collection all of its elements that are not contained in the
          * specified collection.
-         * @param value - The Collection whose elements are to be retained
+         * @param collection - The Collection whose elements are to be retained
          * @returns true if the collection changed as a result of this call
          * @throw UnsupportedOperationException
          * @throw IllegalArgumentException
          */
-        virtual bool retainAll( const Collection<E>& value )
+        virtual bool retainAll( const Collection<E>& collection )
             throw ( lang::exceptions::UnsupportedOperationException,
                     lang::exceptions::IllegalArgumentException ) = 0;
 

Modified: activemq/activemq-cpp/trunk/src/main/decaf/util/ListIterator.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/decaf/util/ListIterator.h?rev=744952&r1=744951&r2=744952&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/decaf/util/ListIterator.h (original)
+++ activemq/activemq-cpp/trunk/src/main/decaf/util/ListIterator.h Mon Feb 16 16:01:43 2009
@@ -101,7 +101,7 @@
          * @return the previous element in the list.
          * @throw NoSuchElementException - if the iteration has no previous element.
          */
-        virtual const E& previous() = 0;
+        virtual E previous() = 0;
 
         /**
          * Returns the index of the element that would be returned by a

Modified: activemq/activemq-cpp/trunk/src/main/decaf/util/Map.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/decaf/util/Map.h?rev=744952&r1=744951&r2=744952&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/decaf/util/Map.h (original)
+++ activemq/activemq-cpp/trunk/src/main/decaf/util/Map.h Mon Feb 16 16:01:43 2009
@@ -36,23 +36,22 @@
         public concurrent::Synchronizable {
     public:
 
-        template< typename K1, typename V1>
         class Entry {
         private:
 
-            K1 key;
-            V1 value;
+            K key;
+            V value;
 
         public:
 
             Entry() {}
             virtual ~Entry() {}
 
-            const K1& getKey() const;
+            const K& getKey() const = 0;
 
-            const V1& getValue() const;
+            const V& getValue() const = 0;
 
-            void setValue( const V1& value );
+            void setValue( const V& value ) = 0;
 
         };
 
@@ -161,6 +160,18 @@
                     decaf::lang::exceptions::UnsupportedOperationException ) = 0;
 
         /**
+         * Returns a Set view of the mappings 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, or through the setValue operation on a map entry returned
by
+         * the iterator) 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 the entire set of keys in this map as a std::vector.
          */
         virtual std::vector<K> keySet() const = 0;

Modified: activemq/activemq-cpp/trunk/src/main/decaf/util/StlList.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/decaf/util/StlList.h?rev=744952&r1=744951&r2=744952&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/decaf/util/StlList.h (original)
+++ activemq/activemq-cpp/trunk/src/main/decaf/util/StlList.h Mon Feb 16 16:01:43 2009
@@ -117,7 +117,7 @@
                 return ( this->current != this->list->begin() );
             }
 
-            virtual const E& previous() {
+            virtual E previous() {
                 if( this->current == this->list->begin() ) {
                     throw lang::exceptions::NoSuchElementException(
                         __FILE__, __LINE__,
@@ -209,7 +209,7 @@
                 return ( this->current != this->list->begin() );
             }
 
-            virtual const E& previous() {
+            virtual E previous() {
                 if( this->current == this->list->begin() ) {
                     throw lang::exceptions::NoSuchElementException(
                         __FILE__, __LINE__,
@@ -437,7 +437,8 @@
          */
         virtual bool add( const E& value )
             throw ( lang::exceptions::UnsupportedOperationException,
-                    lang::exceptions::IllegalArgumentException ) {
+                    lang::exceptions::IllegalArgumentException,
+                    lang::exceptions::IllegalStateException ) {
 
             values.insert( values.end(), value );
 

Modified: activemq/activemq-cpp/trunk/src/main/decaf/util/StlSet.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/decaf/util/StlSet.h?rev=744952&r1=744951&r2=744952&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/decaf/util/StlSet.h (original)
+++ activemq/activemq-cpp/trunk/src/main/decaf/util/StlSet.h Mon Feb 16 16:01:43 2009
@@ -213,7 +213,8 @@
          */
         virtual bool add( const E& value )
             throw ( lang::exceptions::UnsupportedOperationException,
-                    lang::exceptions::IllegalArgumentException ) {
+                    lang::exceptions::IllegalArgumentException,
+                    lang::exceptions::IllegalStateException ) {
 
             return values.insert( value ).second;
         }



Mime
View raw message