Return-Path: Delivered-To: apmail-activemq-commits-archive@www.apache.org Received: (qmail 87872 invoked from network); 16 Dec 2010 23:18:32 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 16 Dec 2010 23:18:32 -0000 Received: (qmail 84701 invoked by uid 500); 16 Dec 2010 23:18:32 -0000 Delivered-To: apmail-activemq-commits-archive@activemq.apache.org Received: (qmail 84672 invoked by uid 500); 16 Dec 2010 23:18:32 -0000 Mailing-List: contact commits-help@activemq.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@activemq.apache.org Delivered-To: mailing list commits@activemq.apache.org Received: (qmail 84665 invoked by uid 99); 16 Dec 2010 23:18:32 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 16 Dec 2010 23:18:32 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 16 Dec 2010 23:18:29 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 4CFD32388A64; Thu, 16 Dec 2010 23:18:09 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1050221 [2/8] - in /activemq/activemq-cpp/trunk/activemq-cpp/src: main/ main/activemq/cmsutil/ main/activemq/core/ main/activemq/state/ main/activemq/threads/ main/activemq/transport/ main/activemq/transport/failover/ main/activemq/util/ m... Date: Thu, 16 Dec 2010 23:18:06 -0000 To: commits@activemq.apache.org From: tabish@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20101216231809.4CFD32388A64@eris.apache.org> Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/AbstractCollection.h URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/AbstractCollection.h?rev=1050221&r1=1050220&r2=1050221&view=diff ============================================================================== --- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/AbstractCollection.h (original) +++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/AbstractCollection.h Thu Dec 16 23:18:02 2010 @@ -55,7 +55,7 @@ namespace util { * @since 1.0 */ template< typename E > - class AbstractCollection : public decaf::util::Collection { + class AbstractCollection : public virtual decaf::util::Collection { protected: mutable util::concurrent::Mutex mutex; @@ -85,74 +85,6 @@ namespace util { } /** - * 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 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& collection ) { - - bool result = false; - std::auto_ptr< Iterator > iter( collection.iterator() ); - while( iter->hasNext() ) { - 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. * @@ -177,33 +109,10 @@ namespace util { } /** - * 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& collection ) { - this->clear(); - - std::auto_ptr< Iterator > iter( collection.iterator() ); - while( iter->hasNext() ) { - this->add( iter->next() ); - } - } - - /** - * Returns true if this collection contains the specified element. + * {@inheritDoc} * * 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 { @@ -219,30 +128,22 @@ namespace util { } /** - * Returns true if this collection contains all of the elements in the specified - * collection. + * {@inheritDoc} * * 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& collection ) const { - bool result = false; std::auto_ptr< Iterator > iter( collection.iterator() ); while( iter->hasNext() ) { - result = this->contains( iter->next() ) || result; + if( !this->contains( iter->next() ) ) { + return false; + } } - return result; + return true; } /** @@ -268,6 +169,28 @@ namespace util { } /** + * Renders this Collection as a Copy of the given Collection + * + * The default 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. + * + * @throws UnsupportedOperationExceptio if this is an unmodifiable collection. + * @throws IllegalStateException if the elements cannot be added at this time due + * to insertion restrictions. + */ + virtual void copy( const Collection& collection ) { + this->clear(); + + std::auto_ptr< Iterator > iter( collection.iterator() ); + while( iter->hasNext() ) { + this->add( iter->next() ); + } + } + + /** * Returns true if this collection contains no elements. * * This implementation returns size() == 0. @@ -279,11 +202,37 @@ namespace util { } /** - * 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). + * {@inheritDoc} + * + * This implementation always throws an UnsupportedOperationException. + */ + virtual bool add( const E& value DECAF_UNUSED ) { + throw decaf::lang::exceptions::UnsupportedOperationException( + __FILE__, __LINE__, "AbstractCollection add is not implemented."); + } + + /** + * {@inheritDoc} + * + * 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). + */ + virtual bool addAll( const Collection& collection ) { + + bool result = false; + std::auto_ptr< Iterator > iter( collection.iterator() ); + while( iter->hasNext() ) { + result = this->add( iter->next() ) || result; + } + + return result; + } + + /** + * {@inheritDoc} * * 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 @@ -292,15 +241,6 @@ namespace util { * 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 - * If the value is not a valid entry for this Collection. */ virtual bool remove( const E& value ) { @@ -316,9 +256,7 @@ namespace util { } /** - * 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. + * {@inheritDoc} * * 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 @@ -327,14 +265,6 @@ namespace util { * 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& collection ) { @@ -351,9 +281,7 @@ namespace util { } /** - * 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. + * {@inheritDoc} * * 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 @@ -362,14 +290,6 @@ namespace util { * 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& collection ) { Added: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/AbstractList.cpp URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/AbstractList.cpp?rev=1050221&view=auto ============================================================================== --- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/AbstractList.cpp (added) +++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/AbstractList.cpp Thu Dec 16 23:18:02 2010 @@ -0,0 +1,18 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "AbstractList.h" Propchange: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/AbstractList.cpp ------------------------------------------------------------------------------ svn:eol-style = native Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/AbstractList.h URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/AbstractList.h?rev=1050221&r1=1050220&r2=1050221&view=diff ============================================================================== --- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/AbstractList.h (original) +++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/AbstractList.h Thu Dec 16 23:18:02 2010 @@ -19,12 +19,15 @@ #define _DECAF_UTIL_ABSTRACTLIST_H_ #include +#include #include #include #include +#include #include #include #include +#include #include namespace decaf { @@ -59,11 +62,376 @@ namespace util { * @since 1.0 */ template< typename E > - class AbstractList : public decaf::util::List { + class AbstractList : public decaf::util::List, + public decaf::util::AbstractCollection { + protected: + + int modCount; + + private: + + class SimpleListIterator : public ListIterator { + protected: + + AbstractList* parent; + int numLeft; + int expectedModCount; + int lastPosition; + + private: + + SimpleListIterator( const SimpleListIterator& ); + SimpleListIterator operator= ( const SimpleListIterator& ); + + public: + + SimpleListIterator( AbstractList* parent, int start ) : + ListIterator(), parent(NULL), numLeft(0), expectedModCount(0), lastPosition(-1) { + + if( parent == NULL ) { + throw decaf::lang::exceptions::NullPointerException( + __FILE__, __LINE__, "List Iterator constructed with NULL parent" ); + } + + if( start < 0 || start > parent->size() ) { + throw decaf::lang::exceptions::IndexOutOfBoundsException( + __FILE__, __LINE__, "start index passed was negative or greater than size()" ); + } + + this->numLeft = parent->size() - start; + this->parent = parent; + this->expectedModCount = parent->modCount; + } + + virtual ~SimpleListIterator() {} + + virtual bool hasNext() const { + return this->numLeft > 0; + } + + virtual E next() { + + if( this->expectedModCount != this->parent->modCount ) { + throw ConcurrentModificationException( + __FILE__, __LINE__, "Concurrent Modification of Parent List detected." ); + } + + try { + + int index = this->parent->size() - this->numLeft; + E result = this->parent->get( index ); + this->lastPosition = index; + this->numLeft--; + + return result; + } catch( decaf::lang::exceptions::IndexOutOfBoundsException& e ) { + throw decaf::util::NoSuchElementException( + __FILE__, __LINE__, "Next called without a next element to process." ); + } + } + + virtual void remove() { + + if( this->lastPosition == -1 ) { + throw decaf::lang::exceptions::IllegalStateException( + __FILE__, __LINE__, "Remove called before next() was called." ); + } + + if( this->expectedModCount != this->parent->modCount ) { + throw ConcurrentModificationException( + __FILE__, __LINE__, "Concurrent Modification of Parent List detected." ); + } + + try { + + if( this->lastPosition == this->parent->size() - this->numLeft ) { + this->numLeft--; // we're removing after a call to previous() + } + + this->parent->removeAt( lastPosition ); + + } catch( decaf::lang::exceptions::IndexOutOfBoundsException& e ) { + throw ConcurrentModificationException( + __FILE__, __LINE__, "Concurrent Modification detected." ); + } + + this->expectedModCount = this->parent->modCount; + this->lastPosition = -1; + } + + virtual void add( const E& value ) { + + if( this->expectedModCount != this->parent->modCount ) { + throw ConcurrentModificationException( + __FILE__, __LINE__, "Concurrent Modification of Parent List detected." ); + } + + try { + this->parent->add( this->parent->size() - this->numLeft, value ); + this->expectedModCount = this->parent->modCount; + this->lastPosition = -1; + } catch( decaf::lang::exceptions::IndexOutOfBoundsException& e ) { + throw decaf::util::NoSuchElementException( + __FILE__, __LINE__, "Add called without a next element to process." ); + } + } + + virtual bool hasPrevious() const { + return this->numLeft < this->parent->size(); + } + + virtual int nextIndex() const { + return this->parent->size() - this->numLeft; + } + + virtual E previous() { + + if( this->expectedModCount != this->parent->modCount ) { + throw ConcurrentModificationException( + __FILE__, __LINE__, "Concurrent Modification detected." ); + } + + try { + + int index = this->parent->size() - this->numLeft - 1; + E result = this->parent->get( index ); + this->numLeft++; + this->lastPosition = index; + + return result; + } catch( decaf::lang::exceptions::IndexOutOfBoundsException& e ) { + throw decaf::util::NoSuchElementException( + __FILE__, __LINE__, "No previous element exists." ); + } + } + + virtual int previousIndex() const { + return this->parent->size() - this->numLeft - 1; + } + + virtual void set( const E& value ) { + + if( this->expectedModCount != this->parent->modCount ) { + throw ConcurrentModificationException( + __FILE__, __LINE__, "Concurrent Modification detected." ); + } + + try { + this->parent->set( this->lastPosition, value ); + } catch( decaf::lang::exceptions::IndexOutOfBoundsException& e ) { + throw decaf::lang::exceptions::IllegalStateException(); + } + } + }; + + class ConstSimpleListIterator : public ListIterator { + protected: + + const AbstractList* parent; + int numLeft; + int expectedModCount; + int lastPosition; + + public: + + ConstSimpleListIterator( const AbstractList* parent, int start ) : + ListIterator(), parent(parent), numLeft(0), expectedModCount(0), lastPosition(-1) { + + if( parent == NULL ) { + throw decaf::lang::exceptions::NullPointerException( + __FILE__, __LINE__, "List Iterator constructed with NULL parent" ); + } + + if( start < 0 || start > parent->size() ) { + throw decaf::lang::exceptions::IndexOutOfBoundsException( + __FILE__, __LINE__, "start index passed was negative or greater than size()" ); + } + + this->numLeft = parent->size() - start; + this->parent = parent; + this->expectedModCount = parent->modCount; + } + + virtual ~ConstSimpleListIterator() {} + + virtual bool hasNext() const { + return this->numLeft > 0; + } + + virtual E next() { + + if( this->expectedModCount != this->parent->modCount ) { + throw ConcurrentModificationException( + __FILE__, __LINE__, "Concurrent Modification of Parent List detected." ); + } + + try { + + int index = this->parent->size() - this->numLeft; + E result = this->parent->get( index ); + this->lastPosition = index; + this->numLeft--; + + return result; + } catch( decaf::lang::exceptions::IndexOutOfBoundsException& e ) { + throw decaf::util::NoSuchElementException( + __FILE__, __LINE__, "Next called without a next element to process." ); + } + } + + virtual void remove() { + throw lang::exceptions::UnsupportedOperationException( + __FILE__, __LINE__, + "AbstractList::Iterator::remove - Const Iterator." ); + } + + virtual void add( const E& value DECAF_UNUSED ) { + throw lang::exceptions::UnsupportedOperationException( + __FILE__, __LINE__, + "AbstractList::ListIterator::radd - Const Iterator." ); + } + + virtual bool hasPrevious() const { + return this->numLeft < this->parent->size(); + } + + virtual int nextIndex() const { + return this->parent->size() - this->numLeft; + } + + virtual E previous() { + + if( this->expectedModCount != this->parent->modCount ) { + throw ConcurrentModificationException( + __FILE__, __LINE__, "Concurrent Modification detected." ); + } + + try { + + int index = this->parent->size() - this->numLeft - 1; + E result = this->parent->get( index ); + this->numLeft++; + this->lastPosition = index; + + return result; + } catch( decaf::lang::exceptions::IndexOutOfBoundsException& e ) { + throw decaf::util::NoSuchElementException( + __FILE__, __LINE__, "No previous element exists." ); + } + } + + virtual int previousIndex() const { + return this->parent->size() - this->numLeft - 1; + } + + virtual void set( const E& value DECAF_UNUSED ) { + throw lang::exceptions::UnsupportedOperationException( + __FILE__, __LINE__, + "AbstractList::ListIterator::set - Const Iterator." ); + } + }; + public: + AbstractList() : modCount( 0 ) {} + virtual ~AbstractList() {} + virtual Iterator* iterator() { + return new SimpleListIterator( this, 0 ); + } + virtual Iterator* iterator() const { + return new ConstSimpleListIterator( this, 0 ); + } + + virtual ListIterator* listIterator() { + return new SimpleListIterator( this, 0 ); + } + virtual ListIterator* listIterator() const { + return new ConstSimpleListIterator( this, 0 ); + } + + virtual ListIterator* listIterator( int index ) { + return new SimpleListIterator( this, index ); + } + virtual ListIterator* listIterator( int index ) const { + return new ConstSimpleListIterator( this, index ); + } + + virtual void clear() { + this->removeRange( 0, this->size() ); + } + + virtual bool add( const E& value ) { + this->add( this->size(), value ); + return true; + } + + virtual void add( int index DECAF_UNUSED, const E& element DECAF_UNUSED ) { + throw decaf::lang::exceptions::UnsupportedOperationException( + __FILE__, __LINE__, "Abstract list does not implement the add method." ); + } + + // Use this method since our own addAll will hide the base class version. + using AbstractCollection::addAll; + + virtual bool addAll( int index, const Collection& source ) { + std::auto_ptr< decaf::util::Iterator > iter( source.iterator() ); + while( iter->hasNext() ) { + this->add( index++, iter->next() ); + } + + return !source.isEmpty(); + } + + virtual E removeAt( int index DECAF_UNUSED ) { + throw decaf::lang::exceptions::UnsupportedOperationException( + __FILE__, __LINE__, "Abstract list does not implement the removeAt method." ); + } + + virtual E set( int index DECAF_UNUSED, const E& element DECAF_UNUSED ) { + throw decaf::lang::exceptions::UnsupportedOperationException( + __FILE__, __LINE__, "Abstract list does not implement the set method." ); + } + + virtual int indexOf( const E& value ) const { + + std::auto_ptr< decaf::util::ListIterator > iter( this->listIterator() ); + + while( iter->hasNext() ) { + + if( value == iter->next() ) { + return iter->previousIndex(); + } + } + + return -1; + } + + virtual int lastIndexOf( const E& value ) const { + + std::auto_ptr< decaf::util::ListIterator > iter( this->listIterator( this->size() ) ); + + while( iter->hasPrevious() ) { + + if( value == iter->previous() ) { + return iter->nextIndex(); + } + } + + return -1; + } + + protected: + + void removeRange( int start, int end ) { + std::auto_ptr< decaf::util::Iterator > iter( this->listIterator( start ) ); + for( int i = start; i < end; i++ ) { + iter->next(); + iter->remove(); + } + } + }; }} Added: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/AbstractMap.cpp URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/AbstractMap.cpp?rev=1050221&view=auto ============================================================================== --- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/AbstractMap.cpp (added) +++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/AbstractMap.cpp Thu Dec 16 23:18:02 2010 @@ -0,0 +1,18 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "AbstractMap.h" Propchange: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/AbstractMap.cpp ------------------------------------------------------------------------------ svn:eol-style = native Added: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/AbstractQueue.cpp URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/AbstractQueue.cpp?rev=1050221&view=auto ============================================================================== --- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/AbstractQueue.cpp (added) +++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/AbstractQueue.cpp Thu Dec 16 23:18:02 2010 @@ -0,0 +1,18 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "AbstractQueue.h" Propchange: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/AbstractQueue.cpp ------------------------------------------------------------------------------ svn:eol-style = native Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/AbstractQueue.h URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/AbstractQueue.h?rev=1050221&r1=1050220&r2=1050221&view=diff ============================================================================== --- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/AbstractQueue.h (original) +++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/AbstractQueue.h Thu Dec 16 23:18:02 2010 @@ -44,7 +44,8 @@ namespace util { * @since 1.0 */ template< typename E > - class AbstractQueue : public decaf::util::Queue { + class AbstractQueue : public decaf::util::Queue, + public decaf::util::AbstractCollection { public: AbstractQueue() : Queue() {} @@ -52,18 +53,10 @@ namespace util { virtual ~AbstractQueue() {} /** - * Inserts the specified element into this queue if it is possible to do so - * immediately without violating capacity restrictions, returning true upon - * success and throwing an IllegalStateException if no space is currently available. + * {@inheritDoc} * * This implementation returns true if offer succeeds, else throws an * IllegalStateException. - * - * @param value - the element to offer to the Queue. - * - * @return true if the add succeeds. - * - * @throw IllegalArgumentException if the element cannot be added. */ virtual bool add( const E& value ) { @@ -76,20 +69,11 @@ namespace util { } /** - * Adds all the elements of a collection to the queue. If the collection is - * the queue itself, then an IllegalArgumentException will be thrown out. If - * during the process, some runtime exception is thrown out, then part of - * the elements in the collection that have successfully added will remain - * in the queue. - * - * The result of the method is undefined if the collection is modified - * during the process of the method. + * {@inheritDoc} * - * @param collection - the collection to be added to the queue. - * @return true if the operation succeeds. - * - * @throws IllegalArgumentException If the collection to be added to the - * queue is the queue itself. + * This implementation checks to see if the Queue is being added to itself and + * throws an IllegalArgumentException if so, otherwise it delegates the add to + * the AbstractCollection's addAll implementation. */ virtual bool addAll( const Collection& collection ) { @@ -98,18 +82,13 @@ namespace util { __FILE__, __LINE__, "A Queue cannot be added to itself." ); } - return Queue::addAll( collection ); + return AbstractCollection::addAll( collection ); } /** - * Retrieves and removes the head of this queue. This method differs from poll - * only in that it throws an exception if this queue is empty. + * {@inheritDoc} * * This implementation returns the result of poll unless the queue is empty. - * - * @return a copy of the element in the head of the queue. - * - * @throws NoSuchElementException if the queue is empty. */ virtual E remove() { @@ -118,18 +97,15 @@ namespace util { return result; } - throw decaf::lang::exceptions::NoSuchElementException( + throw decaf::util::NoSuchElementException( __FILE__, __LINE__, "Unable to remove specified element from the Queue." ); } /** - * Retrieves, but does not remove, the head of this queue. This method differs - * from peek only in that it throws an exception if this queue is empty. - * - * This implementation returns the result of peek unless the queue is empty. + * {@inheritDoc} * - * @return the element in the head of the queue. - * @throws NoSuchElementException if the queue is empty. + * This implementation returns the result of peek unless the queue is empty otherwise + * it throws a NoSuchElementException. */ virtual E element() const { @@ -138,14 +114,14 @@ namespace util { return result; } - throw decaf::lang::exceptions::NoSuchElementException( + throw decaf::util::NoSuchElementException( __FILE__, __LINE__, "Unable to remove specified element from the Queue." ); } /** - * Removes all elements of the queue. + * {@inheritDoc} * - * This implementation repeatedly invokes poll until it returns the empty marker. + * This implementation repeatedly invokes poll until it returns false. */ virtual void clear() { Added: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/AbstractSequentialList.cpp URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/AbstractSequentialList.cpp?rev=1050221&view=auto ============================================================================== --- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/AbstractSequentialList.cpp (added) +++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/AbstractSequentialList.cpp Thu Dec 16 23:18:02 2010 @@ -0,0 +1,18 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "AbstractSequentialList.h" Propchange: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/AbstractSequentialList.cpp ------------------------------------------------------------------------------ svn:eol-style = native Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/AbstractSequentialList.h URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/AbstractSequentialList.h?rev=1050221&r1=1050220&r2=1050221&view=diff ============================================================================== --- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/AbstractSequentialList.h (original) +++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/AbstractSequentialList.h Thu Dec 16 23:18:02 2010 @@ -56,11 +56,134 @@ namespace util { * @since 1.0 */ template< typename E > - class AbstractSequentialList : public decaf::util::AbstractList { + class AbstractSequentialList : public decaf::util::AbstractList { + public: + + using AbstractList::add; + using AbstractList::addAll; + public: virtual ~AbstractSequentialList() {} + virtual Iterator* iterator() { + return this->listIterator( 0 ); + } + virtual Iterator* iterator() const { + return this->listIterator( 0 ); + } + + virtual ListIterator* listIterator() { + return this->listIterator( 0 ); + } + virtual ListIterator* listIterator() const { + return this->listIterator( 0 ); + } + + virtual ListIterator* listIterator( int index DECAF_UNUSED ) { + throw decaf::lang::exceptions::UnsupportedOperationException( + __FILE__, __LINE__, "Abstract sequential list does not implement the listIterator." ); + } + virtual ListIterator* listIterator( int index DECAF_UNUSED ) const { + throw decaf::lang::exceptions::UnsupportedOperationException( + __FILE__, __LINE__, "Abstract sequential list does not implement the listIterator." ); + } + + /** + * {@inheritDoc} + * + * This implementation first gets a list iterator pointing to the indexed + * element (with listIterator(index)). Then, it gets the element using + * ListIterator.next and returns it. + */ + virtual E get( int index ) const { + + try { + std::auto_ptr< ListIterator > iter( this->listIterator( index ) ); + return iter->next(); + } catch( decaf::util::NoSuchElementException& ex ) { + throw decaf::lang::exceptions::IndexOutOfBoundsException( + __FILE__, __LINE__, "get called with invalid index." ); + } + } + + /** + * {@inheritDoc} + * + * This implementation first gets a list iterator pointing to the indexed element + * (with listIterator(index)). Then, it gets the current element using + * ListIterator.next and replaces it with ListIterator.set. + */ + virtual E set( int index, const E& element ) { + + try { + std::auto_ptr< ListIterator > iter( this->listIterator( index ) ); + E result = iter->next(); + iter->set( element ); + return result; + } catch( decaf::util::NoSuchElementException& ex ) { + throw decaf::lang::exceptions::IndexOutOfBoundsException( + __FILE__, __LINE__, "set called with invalid index." ); + } + } + + /** + * {@inheritDoc} + * + * This implementation first gets a list iterator pointing to the indexed element + * (with listIterator(index)). Then, it inserts the specified element with + * ListIterator.add. + */ + virtual void add( int index, const E& element ) { + + try { + std::auto_ptr< ListIterator > iter( this->listIterator( index ) ); + iter->add( element ); + } catch( decaf::util::NoSuchElementException& ex ) { + throw decaf::lang::exceptions::IndexOutOfBoundsException( + __FILE__, __LINE__, "add called with invalid index." ); + } + } + + /** + * {@inheritDoc} + * + * This implementation gets an iterator over the specified collection and a list + * iterator over this list pointing to the indexed element (with listIterator(index)). + * Then, it iterates over the specified collection, inserting the elements obtained + * from the iterator into this list, one at a time, using ListIterator.add + * (to skip over the added element). + */ + virtual bool addAll( int index, const Collection& source ) { + + std::auto_ptr< ListIterator > iter( this->listIterator( index ) ); + std::auto_ptr< Iterator > srcIter( source.iterator() ); + int next = iter->nextIndex(); + while( srcIter->hasNext() ) { + iter->add( srcIter->next() ); + } + return next != iter->nextIndex(); + } + + /** + * {@inheritDoc} + * + * This implementation first gets a list iterator pointing to the indexed element + * (with listIterator(index)). Then, it removes the element with ListIterator.remove. + */ + virtual E removeAt( int index ) { + + try { + std::auto_ptr< ListIterator > iter( this->listIterator( index ) ); + E result = iter->next(); + iter->remove(); + return result; + } catch( decaf::util::NoSuchElementException& ex ) { + throw decaf::lang::exceptions::IndexOutOfBoundsException( + __FILE__, __LINE__, "set called with invalid index." ); + } + } + }; }} Added: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/AbstractSet.cpp URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/AbstractSet.cpp?rev=1050221&view=auto ============================================================================== --- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/AbstractSet.cpp (added) +++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/AbstractSet.cpp Thu Dec 16 23:18:02 2010 @@ -0,0 +1,18 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "AbstractSet.h" Propchange: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/AbstractSet.cpp ------------------------------------------------------------------------------ svn:eol-style = native Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/AbstractSet.h URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/AbstractSet.h?rev=1050221&r1=1050220&r2=1050221&view=diff ============================================================================== --- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/AbstractSet.h (original) +++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/AbstractSet.h Thu Dec 16 23:18:02 2010 @@ -43,16 +43,14 @@ namespace util { * @since 1.0 */ template - class AbstractSet : public decaf::util::Set { + class AbstractSet : public virtual decaf::util::Set, + public virtual decaf::util::AbstractCollection { public: 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. + * {@inheritDoc} * * 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, @@ -65,12 +63,6 @@ namespace util { * * 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& collection ) { Added: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/ArrayList.cpp URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/ArrayList.cpp?rev=1050221&view=auto ============================================================================== --- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/ArrayList.cpp (added) +++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/ArrayList.cpp Thu Dec 16 23:18:02 2010 @@ -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 "ArrayList.h" + Propchange: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/ArrayList.cpp ------------------------------------------------------------------------------ svn:eol-style = native Added: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/ArrayList.h URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/ArrayList.h?rev=1050221&view=auto ============================================================================== --- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/ArrayList.h (added) +++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/ArrayList.h Thu Dec 16 23:18:02 2010 @@ -0,0 +1,428 @@ +/* + * 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_ARRAYLIST_H_ +#define _DECAF_UTIL_ARRAYLIST_H_ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace decaf { +namespace util { + + using decaf::lang::System; + + template< typename E > + class ArrayList : public decaf::util::AbstractList { + private: + + E* elements; + int capacity; + int head; + int curSize; + + public: + + ArrayList() : AbstractList(), elements( NULL ), capacity( 0 ), head( 0 ), curSize( 0 ) { + this->ensureCapacity( 10 ); + } + + ArrayList( const Collection& collection ) : AbstractList(), elements( NULL ), + capacity( 0 ), head( 0 ), curSize( 0 ) { + + this->capacity = collection.size() + ( collection.size() / 10 ); + this->elements = new E[this->capacity]; + + std::auto_ptr< Iterator > iter( collection.iterator() ); + while( iter->hasNext() ) { + this->elements[this->head++] = iter->next(); + this->curSize++; + } + } + + ArrayList( const ArrayList& arrayList ) : AbstractList(), elements( NULL ), + capacity( 0 ), head( 0 ), curSize( 0 ) { + + this->capacity = arrayList.size() + ( arrayList.size() / 10 ); + this->elements = new E[this->capacity]; + + std::auto_ptr< Iterator > iter( arrayList.iterator() ); + while( iter->hasNext() ) { + this->elements[this->head++] = iter->next(); + this->curSize++; + } + } + + ArrayList( int initialCapacity ) : AbstractList(), elements( NULL ), + capacity( initialCapacity ), head( 0 ), curSize( 0 ) { + + if( initialCapacity < 0 ) { + throw decaf::lang::exceptions::IllegalArgumentException( + __FILE__, __LINE__, "Initial Capacity argument cannot be negative." ); + } + + this->elements = new E[this->capacity]; + } + + virtual ~ArrayList() { + try{ + delete [] elements; + } + DECAF_CATCHALL_NOTHROW() + } + + public: + + /** + * Increases the capacity of this ArrayList instance, if necessary, to ensure that it can + * hold at least the number of elements specified by the minimum capacity argument. If the + * capacity is already greater than or equal to the minimum capacity argument then the array + * is left unchanged. + * + * @param minimumCapacity + * The desired minimum capacity for this ArrayList. + */ + void ensureCapacity( int minimumCapacity ) { + + if( minimumCapacity < 0 || this->capacity >= minimumCapacity ) { + return; + } + + int newCapacity = minimumCapacity == 0 ? 10 : minimumCapacity; + + E* newElements = new E[newCapacity]; + if( this->curSize > 0 ) { + decaf::lang::System::arraycopy( this->elements, this->head, newElements, 0, this->curSize ); + } + delete [] this->elements; + this->elements = newElements; + this->capacity = newCapacity; + AbstractList::modCount++; + } + + /** + * Trims the internal array to match the current size of the ArrayList. This compacts + * the internal array to save storage space used by this ArrayList. + */ + void trimToSize() { + + if( this->curSize < this->capacity ) { + + int newCapacity = this->curSize == 0 ? 10 : this->curSize; + + E* newElements = new E[newCapacity]; + if( this->curSize > 0 ) { + System::arraycopy( this->elements, 0, newElements, 0, this->curSize ); + } + + delete [] this->elements; + this->elements = newElements; + this->capacity = newCapacity; + } + + AbstractList::modCount++; + } + + public: + + virtual void clear() { + delete [] this->elements; + this->curSize = 0; + this->capacity = 10; + this->elements = new E[this->capacity]; + AbstractList::modCount++; + } + + virtual bool isEmpty() const { + return this->curSize == 0; + } + + virtual int size() const { + return this->curSize; + } + + virtual E set( int index, const E& element ) { + + if( index < 0 || index >= this->curSize ) { + throw decaf::lang::exceptions::IndexOutOfBoundsException( + __FILE__, __LINE__, + "List::get - Index greater than size() or negative" ); + } + + E oldValue = this->elements[index]; + this->elements[index] = element; + + return oldValue; + } + + virtual E get( int index ) const { + + if( index < 0 || index >= this->curSize ) { + throw decaf::lang::exceptions::IndexOutOfBoundsException( + __FILE__, __LINE__, + "List::get - Index greater than size() or negative" ); + } + + return this->elements[index]; + } + + virtual bool add( const E& value ) { + + this->expandEnd( 1 ); + this->elements[this->curSize++] = value; + AbstractList::modCount++; + + return true; + } + + virtual void add( int index, const E& element ) { + + if( index < 0 || index > this->curSize ) { + throw decaf::lang::exceptions::IndexOutOfBoundsException( + __FILE__, __LINE__, + "Index was negative or greater than size()" ); + } + + if( index == 0 ) { + this->expandFront( 1 ); + } else if( index == this->curSize ) { + this->expandEnd( 1 ); + } else { + this->expandMiddle( index, 1 ); + } + + this->elements[index] = element; + this->curSize++; + AbstractList::modCount++; + } + + virtual bool addAll( const Collection& collection ) { + + int csize = collection.size(); + if( csize == 0 ) { + return false; + } + + std::vector array = collection.toArray(); + + this->expandEnd( csize ); + + for( int i = 0; i < csize; ++i ) { + this->elements[this->curSize++] = array[i]; + } + + AbstractList::modCount++; + + return true; + } + + virtual bool addAll( int index, const Collection& collection ) { + + if( index < 0 || index > this->curSize ) { + throw decaf::lang::exceptions::IndexOutOfBoundsException( + __FILE__, __LINE__, + "List::addAll - Index greater than size()" ); + } + + int csize = collection.size(); + if( csize == 0 ) { + return false; + } + + std::vector array = collection.toArray(); + + if( index == 0 ) { + this->expandFront( csize ); + } else if( index == this->curSize ) { + this->expandEnd( csize ); + } else { + this->expandMiddle( index, csize ); + } + + for( int i = 0; i < csize; ++i, ++this->curSize ) { + this->elements[index++] = array[i]; + } + + AbstractList::modCount++; + + return true; + } + + virtual bool remove( const E& value ) { + + int result = indexOf( value ); + if( result != -1 ) { + this->removeAt( result ); + return true; + } + + return false; + } + + virtual E removeAt( int index ) { + + if( index < 0 || index >= this->curSize ) { + throw decaf::lang::exceptions::IndexOutOfBoundsException( + __FILE__, __LINE__, + "List::removeAt - Index greater than size() or negative" ); + } + + E old = this->elements[index]; + + System::arraycopy( this->elements, 0, this->elements, 0, index ); + + if( this->curSize > index ) { + System::arraycopy( this->elements, index + 1, this->elements, index, this->curSize - index - 1 ); + } + + this->elements[--this->curSize] = E(); + AbstractList::modCount++; + + return old; + } + + virtual bool contains( const E& value ) const { + return this->indexOf( value ) != -1; + } + + virtual int indexOf( const E& value ) const { + + for( int i = 0; i < this->curSize; ++i ) { + if( this->elements[i] == value ) { + return i; + } + } + + return -1; + } + + virtual int lastIndexOf( const E& value ) const { + + for( int i = this->curSize - 1; i >= 0 ; --i ) { + if( this->elements[i] == value ) { + return i; + } + } + + return -1; + } + + virtual std::vector toArray() const { + + std::vector result; + + for( int i = 0; i < this->curSize; ++i ) { + result.push_back( this->elements[i] ); + } + + return result; + } + + virtual std::string toString() const { + + std::string result; + + result.append( "decaf::util::ArrayList [ size = " ); + result.append( decaf::lang::Integer::toString( this->curSize ) ); + result.append( " ]"); + + return result; + } + + private: + + void expandFront( int amount ) { + + if( amount == 0 ) { + return; + } + + E* previous = this->elements; + + if( amount > this->capacity - this->curSize ) { + this->capacity = this->capacity + amount + 11; + this->elements = new E[this->capacity]; + } + + if( this->curSize > 0 ) { + System::arraycopy( previous, 0, this->elements, amount, this->curSize ); + } + + if( previous != this->elements ) { + delete [] previous; + } + } + + void expandEnd( int amount ) { + + if( amount == 0 ) { + return; + } + + E* previous = this->elements; + + if( amount > this->capacity - this->curSize ) { + this->capacity = this->capacity + amount + 11; + this->elements = new E[this->capacity]; + System::arraycopy( previous, 0, this->elements, 0, this->curSize ); + } + + if( previous != this->elements ) { + delete [] previous; + } + } + + void expandMiddle( int index, int amount ) { + + if( amount == 0 ) { + return; + } + + E* previous = this->elements; + + if( amount > this->capacity - this->curSize ) { + this->capacity = this->capacity + amount + 11; + this->elements = new E[this->capacity]; + } + + if( this->curSize > 0 ) { + System::arraycopy( previous, 0, this->elements, 0, index ); + } + + if( this->curSize > index ) { + System::arraycopy( previous, index, this->elements, index + amount, this->curSize - index ); + } + + if( previous != this->elements ) { + delete [] previous; + } + } + + }; + +}} + +#endif /* _DECAF_UTIL_ARRAYLIST_H_ */ Propchange: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/ArrayList.h ------------------------------------------------------------------------------ svn:eol-style = native Added: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/Arrays.cpp URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/Arrays.cpp?rev=1050221&view=auto ============================================================================== --- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/Arrays.cpp (added) +++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/Arrays.cpp Thu Dec 16 23:18:02 2010 @@ -0,0 +1,29 @@ +/* + * 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 "Arrays.h" + +using namespace decaf; +using namespace decaf::util; + +//////////////////////////////////////////////////////////////////////////////// +Arrays::Arrays() { +} + +//////////////////////////////////////////////////////////////////////////////// +Arrays::~Arrays() { +} Propchange: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/Arrays.cpp ------------------------------------------------------------------------------ svn:eol-style = native Added: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/Arrays.h URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/Arrays.h?rev=1050221&view=auto ============================================================================== --- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/Arrays.h (added) +++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/Arrays.h Thu Dec 16 23:18:02 2010 @@ -0,0 +1,126 @@ +/* + * 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_ARRAYS_H_ +#define _DECAF_UTIL_ARRAYS_H_ + +#include +#include +#include + +namespace decaf { +namespace util { + + class Arrays { + private: + + Arrays( const Arrays& source ); + Arrays& operator= ( const Arrays& source ); + + private: + + Arrays(); + + public: + + virtual ~Arrays(); + + /** + * Fills an array with the specified element. + * + * @param array + * The Array to fill. + * @param size + * The actual size of the array passed. + * @param value + * The value to fill the array with. + * + * @throws NullPointerException if array is Null. + * @throws IllegalArgumentException if the size parameter is negative, or the start + * index is greater than the end index. + */ + template< typename E> + static void fill( E* array, int size, const E& value ) { + + if( array == NULL ) { + throw decaf::lang::exceptions::NullPointerException( + __FILE__, __LINE__, "Array pointer given was NULL." ); + } + + if( size < 0 ) { + throw decaf::lang::exceptions::IllegalArgumentException( + __FILE__, __LINE__, "Array size value given was negative." ); + } + + for( int i = 0; i < size; ++i ) { + array[i] = value; + } + } + + /** + * Fills an array with the specified element within the range given. + * + * @param array + * The Array to fill. + * @param size + * The actual size of the array passed. + * @param start + * The index to start the fill from (inclusive). + * @param end + * The index to fill to (exclusive). + * @param value + * The value to fill the array with. + * + * @throws NullPointerException if array is Null. + * @throws IllegalArgumentException if the size parameter is negative, or the start + * index is greater than the end index. + * @throws IndexOutOfBoundsException if the start index is negative or the end index + * is greater than the size parameter. + */ + template< typename E> + static void fill( E* array, int size, int start, int end, const E& value ) { + + if( array == NULL ) { + throw decaf::lang::exceptions::NullPointerException( + __FILE__, __LINE__, "Array pointer given was NULL." ); + } + + if( size < 0 ) { + throw decaf::lang::exceptions::IllegalArgumentException( + __FILE__, __LINE__, "Array size value given was negative." ); + } + + if( start > end ) { + throw decaf::lang::exceptions::IllegalArgumentException( + __FILE__, __LINE__, "The start index was greater than the end index." ); + } + + if( start < 0 || end > size ) { + throw decaf::lang::exceptions::IndexOutOfBoundsException( + __FILE__, __LINE__, "The start index {%d} end index {%d} range is invalid.", start, end ); + } + + for( int i = start; i < end; ++i ) { + array[i] = value; + } + } + + }; + +}} + +#endif /* _DECAF_UTIL_ARRAYS_H_ */ Propchange: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/Arrays.h ------------------------------------------------------------------------------ svn:eol-style = native Added: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/Collection.cpp URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/Collection.cpp?rev=1050221&view=auto ============================================================================== --- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/Collection.cpp (added) +++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/Collection.cpp Thu Dec 16 23:18:02 2010 @@ -0,0 +1,18 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "Collection.h" Propchange: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/Collection.cpp ------------------------------------------------------------------------------ svn:eol-style = native Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/Collection.h URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/Collection.h?rev=1050221&r1=1050220&r2=1050221&view=diff ============================================================================== --- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/Collection.h (original) +++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/Collection.h Thu Dec 16 23:18:02 2010 @@ -65,13 +65,25 @@ namespace util{ * @since 1.0 */ template< typename E > - class Collection : public lang::Iterable, - public util::concurrent::Synchronizable { + class Collection : public virtual lang::Iterable, + public virtual util::concurrent::Synchronizable { public: virtual ~Collection() {} /** + * Renders this Collection as a Copy of the given Collection + * + * @param collection + * The collection to mirror. + * + * @throws UnsupportedOperationExceptio if this is an unmodifiable collection. + * @throws IllegalStateException if the elements cannot be added at this time due + * to insertion restrictions. + */ + virtual void copy( const Collection& collection ) = 0; + + /** * 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.) @@ -94,12 +106,18 @@ namespace util{ * being copied, must not hide the copy constructor and assignment * operator. * - * @param value - reference to the element to add. - * @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 + * @param value + * The reference to the element to add to this Collection. + * + * @returns true if the element was added to this Collection. + * + * @throws UnsupportedOperationExceptio if this is an unmodifiable collection. + * @throws NullPointerException if the Collection is a container of pointers + * and does not allow NULL values. + * @throws IllegalArgumentException if some property of the element prevents it + * from being added to this collection + * @throws IllegalStateException if the element cannot be added at this time due + * to insertion restrictions. */ virtual bool add( const E& value ) = 0; @@ -110,12 +128,19 @@ namespace util{ * (This implies that the behavior of this call is undefined if the * specified collection is this collection, and this collection is * nonempty.) - * @param collection - Collection whose elements are added to this one. + * + * @param collection + * The 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 + * + * @throws UnsupportedOperationExceptio if this is an unmodifiable collection. + * @throws NullPointerException if the Collection is a container of pointers + * and does not allow NULL values. + * @throws IllegalArgumentException if some property of an element prevents it + * from being added to this collection + * @throws IllegalStateException if an element cannot be added at this time due + * to insertion restrictions. */ virtual bool addAll( const Collection& collection ) = 0; @@ -123,25 +148,35 @@ namespace util{ * Removes all of the elements from this collection (optional operation). * This collection will be empty after this method returns unless it throws * an exception. - * @throw UnsupportedOperationException + * + * @throws UnsupportedOperationExceptio if this is an unmodifiable collection. */ virtual void clear() = 0; /** * Returns true if this collection contains the specified element. More * formally, returns true if and only if this collection contains at - * least one element e such that (o==null ? e==null : o.equals(e)). - * @param value - value to check for presence in the collection + * least one element e such that (value == NULL ? e == NULL : value == e ). + * + * @param value + * The value to check for presence in the collection. + * * @returns true if there is at least one of the elements in the collection - * @throw Exception + * + * @throws NullPointerException if the Collection contains pointers and the + * Collection does not allow for NULL elements (optional check). */ virtual bool contains( const E& value ) const = 0; /** * Returns true if this collection contains all of the elements in * the specified collection. - * @param collection - Collection to compare to this one. - * @throw Exception + * + * @param collection + * The Collection to compare to this one. + * + * @throws NullPointerException if the Collection contains pointers and the + * Collection does not allow for NULL elements (optional check). */ virtual bool containsAll( const Collection& collection ) const = 0; @@ -149,6 +184,7 @@ namespace util{ * Compares the passed collection to this one, if they contain the * same elements, i.e. all their elements are equivalent, then it * returns true. + * * @returns true if the Collections contain the same elements. */ virtual bool equals( const Collection& value ) const = 0; @@ -161,14 +197,19 @@ namespace util{ /** * Removes a single instance of the specified element from the * collection. More formally, removes an element e such that - * (o==null ? e==null : o.equals(e)), if this collection contains one + * (value == NULL ? e == NULL : value == e), 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). - * @param value - reference to the element to remove. - * @returns true if the collection was changed - * @throw UnsupportedOperationException - * @throw IllegalArgumentException + * + * @param value + * The reference to the element to remove from this Collection. + * + * @returns true if the collection was changed, false otherwise. + * + * @throws UnsupportedOperationExceptio if this is an unmodifiable collection. + * @throws NullPointerException if the Collection is a container of pointers + * and does not allow NULL values. */ virtual bool remove( const E& value ) = 0; @@ -177,10 +218,15 @@ namespace util{ * the specified collection (optional operation). After this call returns, * this collection will contain no elements in common with the specified * collection. - * @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 + * + * @param collection + * The Collection whose elements are to be removed from this one. + * + * @returns true if the collection changed as a result of this call. + * + * @throws UnsupportedOperationExceptio if this is an unmodifiable collection. + * @throws NullPointerException if the Collection is a container of pointers + * and does not allow NULL values. */ virtual bool removeAll( const Collection& collection ) = 0; @@ -189,16 +235,22 @@ namespace util{ * specified collection (optional operation). In other words, removes from * this collection all of its elements that are not contained in the * specified collection. - * @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 + * + * @param collection + * The Collection whose elements are to be retained. + * + * @returns true if the collection changed as a result of this call. + * + * @throws UnsupportedOperationExceptio if this is an unmodifiable collection. + * @throws NullPointerException if the Collection is a container of pointers + * and does not allow NULL values. */ virtual bool retainAll( const Collection& collection ) = 0; /** * Returns the number of elements in this collection. If this collection - * contains more than Integer.MAX_VALUE elements, returns Integer.MAX_VALUE. + * contains more than Integer::MAX_VALUE elements, returns Integer::MAX_VALUE. + * * @returns the number of elements in this collection */ virtual int size() const = 0; @@ -210,7 +262,9 @@ namespace util{ * same order. * * This method acts as bridge between array-based and collection-based APIs. - * @returns an array of the elements in this collection. + * + * @returns an array of the elements in this collection in the form of an + * STL vector. */ virtual std::vector toArray() const = 0; Added: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/Comparator.cpp URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/Comparator.cpp?rev=1050221&view=auto ============================================================================== --- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/Comparator.cpp (added) +++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/Comparator.cpp Thu Dec 16 23:18:02 2010 @@ -0,0 +1,18 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "Comparator.h" Propchange: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/Comparator.cpp ------------------------------------------------------------------------------ svn:eol-style = native Added: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/ConcurrentModificationException.cpp URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/ConcurrentModificationException.cpp?rev=1050221&view=auto ============================================================================== --- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/ConcurrentModificationException.cpp (added) +++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/ConcurrentModificationException.cpp Thu Dec 16 23:18:02 2010 @@ -0,0 +1,32 @@ +/* + * 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 "ConcurrentModificationException.h" + +using namespace std; +using namespace decaf; +using namespace decaf::util; +using namespace decaf::lang; +using namespace decaf::lang::exceptions; + +//////////////////////////////////////////////////////////////////////////////// +ConcurrentModificationException::ConcurrentModificationException() throw() { +} + +//////////////////////////////////////////////////////////////////////////////// +ConcurrentModificationException::~ConcurrentModificationException() throw() { +} Propchange: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/ConcurrentModificationException.cpp ------------------------------------------------------------------------------ svn:eol-style = native