Return-Path: Delivered-To: apmail-commons-commits-archive@minotaur.apache.org Received: (qmail 48409 invoked from network); 29 Jan 2009 18:50:19 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 29 Jan 2009 18:50:19 -0000 Received: (qmail 55708 invoked by uid 500); 29 Jan 2009 18:50:00 -0000 Delivered-To: apmail-commons-commits-archive@commons.apache.org Received: (qmail 55631 invoked by uid 500); 29 Jan 2009 18:50:00 -0000 Mailing-List: contact commits-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@commons.apache.org Delivered-To: mailing list commits@commons.apache.org Received: (qmail 55605 invoked by uid 99); 29 Jan 2009 18:49:59 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 29 Jan 2009 10:49:59 -0800 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, 29 Jan 2009 18:49:47 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 537F62388BE1; Thu, 29 Jan 2009 18:49:02 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r738956 [11/34] - in /commons/proper/collections/branches/collections_jdk5_branch/src: java/org/apache/commons/collections/ java/org/apache/commons/collections/bag/ java/org/apache/commons/collections/bidimap/ java/org/apache/commons/collec... Date: Thu, 29 Jan 2009 18:48:47 -0000 To: commits@commons.apache.org From: mbenson@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20090129184902.537F62388BE1@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Modified: commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/iterators/IteratorChain.java URL: http://svn.apache.org/viewvc/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/iterators/IteratorChain.java?rev=738956&r1=738955&r2=738956&view=diff ============================================================================== --- commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/iterators/IteratorChain.java (original) +++ commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/iterators/IteratorChain.java Thu Jan 29 18:48:37 2009 @@ -26,45 +26,50 @@ /** * An IteratorChain is an Iterator that wraps a number of Iterators. *

- * This class makes multiple iterators look like one to the caller - * When any method from the Iterator interface is called, the IteratorChain - * will delegate to a single underlying Iterator. The IteratorChain will - * invoke the Iterators in sequence until all Iterators are exhausted. + * This class makes multiple iterators look like one to the caller When any + * method from the Iterator interface is called, the IteratorChain will delegate + * to a single underlying Iterator. The IteratorChain will invoke the Iterators + * in sequence until all Iterators are exhausted. *

- * Under many circumstances, linking Iterators together in this manner is - * more efficient (and convenient) than reading out the contents of each - * Iterator into a List and creating a new Iterator. + * Under many circumstances, linking Iterators together in this manner is more + * efficient (and convenient) than reading out the contents of each Iterator + * into a List and creating a new Iterator. *

* Calling a method that adds new Iteratorafter a method in the Iterator - * interface has been called will result in an UnsupportedOperationException. - * Subclasses should take care to not alter the underlying List of Iterators. + * interface has been called will result in an + * UnsupportedOperationException. Subclasses should take care to not + * alter the underlying List of Iterators. *

- * NOTE: As from version 3.0, the IteratorChain may contain no - * iterators. In this case the class will function as an empty iterator. - * + * NOTE: As from version 3.0, the IteratorChain may contain no iterators. In + * this case the class will function as an empty iterator. + * * @since Commons Collections 2.1 - * @version $Revision$ $Date$ - * + * @version $Revision$ $Date: 2006-10-27 19:52:37 -0500 (Fri, 27 Oct + * 2006) $ + * * @author Morgan Delagrange * @author Stephen Colebourne */ -public class IteratorChain implements Iterator { +public class IteratorChain implements Iterator { + + /** The chain of iterators */ + protected final List> iteratorChain = new ArrayList>(); - /** The chain of iterators */ - protected final List iteratorChain = new ArrayList(); /** The index of the current iterator */ protected int currentIteratorIndex = 0; + /** The current iterator */ - protected Iterator currentIterator = null; + protected Iterator currentIterator = null; + /** - * The "last used" Iterator is the Iterator upon which - * next() or hasNext() was most recently called - * used for the remove() operation only + * The "last used" Iterator is the Iterator upon which next() or hasNext() + * was most recently called used for the remove() operation only */ - protected Iterator lastUsedIterator = null; + protected Iterator lastUsedIterator = null; + /** - * ComparatorChain is "locked" after the first time - * compare(Object,Object) is called + * ComparatorChain is "locked" after the first time compare(Object,Object) + * is called */ protected boolean isLocked = false; @@ -72,8 +77,8 @@ /** * Construct an IteratorChain with no Iterators. *

- * You will normally use {@link #addIterator(Iterator)} to add - * some iterators after using this constructor. + * You will normally use {@link #addIterator(Iterator)} to add some + * iterators after using this constructor. */ public IteratorChain() { super(); @@ -82,49 +87,47 @@ /** * Construct an IteratorChain with a single Iterator. *

- * This method takes one iterator. The newly constructed iterator - * will iterate through that iterator. Thus calling this constructor - * on its own will have no effect other than decorating the input iterator. + * This method takes one iterator. The newly constructed iterator will + * iterate through that iterator. Thus calling this constructor on its own + * will have no effect other than decorating the input iterator. *

- * You will normally use {@link #addIterator(Iterator)} to add - * some more iterators after using this constructor. - * - * @param iterator the first child iterator in the IteratorChain, not null + * You will normally use {@link #addIterator(Iterator)} to add some more + * iterators after using this constructor. + * + * @param iterator the first child iterator in the IteratorChain, not null * @throws NullPointerException if the iterator is null */ - public IteratorChain(Iterator iterator) { + public IteratorChain(Iterator iterator) { super(); addIterator(iterator); } /** - * Constructs a new IteratorChain over the two - * given iterators. + * Constructs a new IteratorChain over the two given iterators. *

- * This method takes two iterators. The newly constructed iterator - * will iterate through each one of the input iterators in turn. - * - * @param first the first child iterator in the IteratorChain, not null - * @param second the second child iterator in the IteratorChain, not null + * This method takes two iterators. The newly constructed iterator will + * iterate through each one of the input iterators in turn. + * + * @param first the first child iterator in the IteratorChain, not null + * @param second the second child iterator in the IteratorChain, not null * @throws NullPointerException if either iterator is null */ - public IteratorChain(Iterator first, Iterator second) { + public IteratorChain(Iterator first, Iterator second) { super(); addIterator(first); addIterator(second); } /** - * Constructs a new IteratorChain over the array - * of iterators. + * Constructs a new IteratorChain over the array of iterators. *

* This method takes an array of iterators. The newly constructed iterator * will iterate through each one of the input iterators in turn. - * - * @param iteratorChain the array of iterators, not null + * + * @param iteratorChain the array of iterators, not null * @throws NullPointerException if iterators array is or contains null */ - public IteratorChain(Iterator[] iteratorChain) { + public IteratorChain(Iterator[] iteratorChain) { super(); for (int i = 0; i < iteratorChain.length; i++) { addIterator(iteratorChain[i]); @@ -132,33 +135,33 @@ } /** - * Constructs a new IteratorChain over the collection - * of iterators. + * Constructs a new IteratorChain over the collection of + * iterators. *

- * This method takes a collection of iterators. The newly constructed iterator - * will iterate through each one of the input iterators in turn. - * - * @param iteratorChain the collection of iterators, not null + * This method takes a collection of iterators. The newly constructed + * iterator will iterate through each one of the input iterators in turn. + * + * @param iteratorChain the collection of iterators, not null * @throws NullPointerException if iterators collection is or contains null - * @throws ClassCastException if iterators collection doesn't contain an iterator + * @throws ClassCastException if iterators collection doesn't contain an + * iterator */ - public IteratorChain(Collection iteratorChain) { + public IteratorChain(Collection> iteratorChain) { super(); - for (Iterator it = iteratorChain.iterator(); it.hasNext();) { - Iterator item = (Iterator) it.next(); - addIterator(item); + for (Iterator iterator : iteratorChain) { + addIterator(iterator); } } //----------------------------------------------------------------------- /** * Add an Iterator to the end of the chain - * + * * @param iterator Iterator to add * @throws IllegalStateException if I've already started iterating * @throws NullPointerException if the iterator is null */ - public void addIterator(Iterator iterator) { + public void addIterator(Iterator iterator) { checkLocked(); if (iterator == null) { throw new NullPointerException("Iterator must not be null"); @@ -168,14 +171,15 @@ /** * Set the Iterator at the given index - * - * @param index index of the Iterator to replace - * @param iterator Iterator to place at the given index + * + * @param index index of the Iterator to replace + * @param iterator Iterator to place at the given index * @throws IndexOutOfBoundsException if index < 0 or index > size() * @throws IllegalStateException if I've already started iterating * @throws NullPointerException if the iterator is null */ - public void setIterator(int index, Iterator iterator) throws IndexOutOfBoundsException { + public void setIterator(int index, Iterator iterator) + throws IndexOutOfBoundsException { checkLocked(); if (iterator == null) { throw new NullPointerException("Iterator must not be null"); @@ -185,16 +189,16 @@ /** * Get the list of Iterators (unmodifiable) - * + * * @return the unmodifiable list of iterators added */ - public List getIterators() { + public List> getIterators() { return UnmodifiableList.decorate(iteratorChain); } /** * Number of Iterators in the current IteratorChain. - * + * * @return Iterator count */ public int size() { @@ -203,9 +207,9 @@ /** * Determine if modifications can still be made to the IteratorChain. - * IteratorChains cannot be modified once they have executed a method - * from the Iterator interface. - * + * IteratorChains cannot be modified once they have executed a method from + * the Iterator interface. + * * @return true if IteratorChain cannot be modified, false if it can */ public boolean isLocked() { @@ -217,13 +221,14 @@ */ private void checkLocked() { if (isLocked == true) { - throw new UnsupportedOperationException("IteratorChain cannot be changed after the first use of a method from the Iterator interface"); + throw new UnsupportedOperationException( + "IteratorChain cannot be changed after the first use of a method from the Iterator interface"); } } /** - * Lock the chain so no more iterators can be added. - * This must be called from all Iterator interface methods. + * Lock the chain so no more iterators can be added. This must be called + * from all Iterator interface methods. */ private void lockChain() { if (isLocked == false) { @@ -232,31 +237,32 @@ } /** - * Updates the current iterator field to ensure that the current Iterator - * is not exhausted + * Updates the current iterator field to ensure that the current Iterator is + * not exhausted */ protected void updateCurrentIterator() { if (currentIterator == null) { if (iteratorChain.isEmpty()) { - currentIterator = EmptyIterator.INSTANCE; + currentIterator = EmptyIterator. getInstance(); } else { - currentIterator = (Iterator) iteratorChain.get(0); + currentIterator = iteratorChain.get(0); } // set last used iterator here, in case the user calls remove // before calling hasNext() or next() (although they shouldn't) lastUsedIterator = currentIterator; } - while (currentIterator.hasNext() == false && currentIteratorIndex < iteratorChain.size() - 1) { + while (currentIterator.hasNext() == false + && currentIteratorIndex < iteratorChain.size() - 1) { currentIteratorIndex++; - currentIterator = (Iterator) iteratorChain.get(currentIteratorIndex); + currentIterator = iteratorChain.get(currentIteratorIndex); } } //----------------------------------------------------------------------- /** * Return true if any Iterator in the IteratorChain has a remaining element. - * + * * @return true if elements remain */ public boolean hasNext() { @@ -269,11 +275,12 @@ /** * Returns the next Object of the current Iterator - * + * * @return Object from the current Iterator - * @throws java.util.NoSuchElementException if all the Iterators are exhausted + * @throws java.util.NoSuchElementException if all the Iterators are + * exhausted */ - public Object next() { + public E next() { lockChain(); updateCurrentIterator(); lastUsedIterator = currentIterator; @@ -282,18 +289,17 @@ } /** - * Removes from the underlying collection the last element - * returned by the Iterator. As with next() and hasNext(), - * this method calls remove() on the underlying Iterator. - * Therefore, this method may throw an - * UnsupportedOperationException if the underlying - * Iterator does not support this method. - * - * @throws UnsupportedOperationException - * if the remove operator is not supported by the underlying Iterator - * @throws IllegalStateException - * if the next method has not yet been called, or the remove method has - * already been called after the last call to the next method. + * Removes from the underlying collection the last element returned by the + * Iterator. As with next() and hasNext(), this method calls remove() on the + * underlying Iterator. Therefore, this method may throw an + * UnsupportedOperationException if the underlying Iterator does not support + * this method. + * + * @throws UnsupportedOperationException if the remove operator is not + * supported by the underlying Iterator + * @throws IllegalStateException if the next method has not yet been called, + * or the remove method has already been called after the last call to the + * next method. */ public void remove() { lockChain(); Modified: commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/iterators/IteratorEnumeration.java URL: http://svn.apache.org/viewvc/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/iterators/IteratorEnumeration.java?rev=738956&r1=738955&r2=738956&view=diff ============================================================================== --- commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/iterators/IteratorEnumeration.java (original) +++ commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/iterators/IteratorEnumeration.java Thu Jan 29 18:48:37 2009 @@ -19,36 +19,36 @@ import java.util.Enumeration; import java.util.Iterator; -/** - * Adapter to make an {@link Iterator Iterator} instance appear to be - * an {@link Enumeration Enumeration} instance. - * +/** + * Adapter to make an {@link Iterator Iterator} instance appear to be an + * {@link Enumeration Enumeration} instance. + * * @since Commons Collections 1.0 - * @version $Revision$ $Date$ + * @version $Revision$ $Date: 2006-10-27 19:52:37 -0500 (Fri, 27 Oct + * 2006) $ * * @author James Strachan */ -public class IteratorEnumeration implements Enumeration { - +public class IteratorEnumeration implements Enumeration { + /** The iterator being decorated. */ - private Iterator iterator; - + private Iterator iterator; + /** - * Constructs a new IteratorEnumeration that will not - * function until {@link #setIterator(Iterator) setIterator} is - * invoked. + * Constructs a new IteratorEnumeration that will not function + * until {@link #setIterator(Iterator) setIterator} is invoked. */ public IteratorEnumeration() { super(); } /** - * Constructs a new IteratorEnumeration that will use - * the given iterator. + * Constructs a new IteratorEnumeration that will use the given + * iterator. * - * @param iterator the iterator to use + * @param iterator the iterator to use */ - public IteratorEnumeration( Iterator iterator ) { + public IteratorEnumeration(Iterator iterator) { super(); this.iterator = iterator; } @@ -57,22 +57,22 @@ //------------------------------------------------------------------------- /** - * Returns true if the underlying iterator has more elements. - * - * @return true if the underlying iterator has more elements + * Returns true if the underlying iterator has more elements. + * + * @return true if the underlying iterator has more elements */ public boolean hasMoreElements() { return iterator.hasNext(); } /** - * Returns the next element from the underlying iterator. - * - * @return the next element from the underlying iterator. - * @throws java.util.NoSuchElementException if the underlying iterator has no - * more elements + * Returns the next element from the underlying iterator. + * + * @return the next element from the underlying iterator. + * @throws java.util.NoSuchElementException if the underlying iterator has + * no more elements */ - public Object nextElement() { + public E nextElement() { return iterator.next(); } @@ -80,21 +80,21 @@ //------------------------------------------------------------------------- /** - * Returns the underlying iterator. + * Returns the underlying iterator. * - * @return the underlying iterator + * @return the underlying iterator */ - public Iterator getIterator() { + public Iterator getIterator() { return iterator; } /** - * Sets the underlying iterator. - * - * @param iterator the new underlying iterator + * Sets the underlying iterator. + * + * @param iterator the new underlying iterator */ - public void setIterator( Iterator iterator ) { + public void setIterator(Iterator iterator) { this.iterator = iterator; } - + } Modified: commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/iterators/ListIteratorWrapper.java URL: http://svn.apache.org/viewvc/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/iterators/ListIteratorWrapper.java?rev=738956&r1=738955&r2=738956&view=diff ============================================================================== --- commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/iterators/ListIteratorWrapper.java (original) +++ commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/iterators/ListIteratorWrapper.java Thu Jan 29 18:48:37 2009 @@ -42,16 +42,16 @@ * @author Morgan Delagrange * @author Stephen Colebourne */ -public class ListIteratorWrapper implements ResettableListIterator { +public class ListIteratorWrapper implements ResettableListIterator { /** Message used when remove, set or add are called. */ private static final String UNSUPPORTED_OPERATION_MESSAGE = "ListIteratorWrapper does not support optional operations of ListIterator."; /** The underlying iterator being decorated. */ - private final Iterator iterator; + private final Iterator iterator; /** The list being used to cache the iterator. */ - private final List list = new ArrayList(); + private final List list = new ArrayList(); /** The current index of this iterator. */ private int currentIndex = 0; @@ -67,7 +67,7 @@ * @param iterator the iterator to wrap * @throws NullPointerException if the iterator is null */ - public ListIteratorWrapper(Iterator iterator) { + public ListIteratorWrapper(Iterator iterator) { super(); if (iterator == null) { throw new NullPointerException("Iterator must not be null"); @@ -83,7 +83,7 @@ * @param obj the object to add, ignored * @throws UnsupportedOperationException always */ - public void add(Object obj) throws UnsupportedOperationException { + public void add(E obj) throws UnsupportedOperationException { throw new UnsupportedOperationException(UNSUPPORTED_OPERATION_MESSAGE); } @@ -117,13 +117,13 @@ * @return the next element from the iterator * @throws NoSuchElementException if there are no more elements */ - public Object next() throws NoSuchElementException { + public E next() throws NoSuchElementException { if (currentIndex < wrappedIteratorIndex) { ++currentIndex; return list.get(currentIndex - 1); } - Object retval = iterator.next(); + E retval = iterator.next(); list.add(retval); ++currentIndex; ++wrappedIteratorIndex; @@ -145,7 +145,7 @@ * @return the previous element * @throws NoSuchElementException if there are no previous elements */ - public Object previous() throws NoSuchElementException { + public E previous() throws NoSuchElementException { if (currentIndex == 0) { throw new NoSuchElementException(); } @@ -177,7 +177,7 @@ * @param obj the object to set, ignored * @throws UnsupportedOperationException always */ - public void set(Object obj) throws UnsupportedOperationException { + public void set(E obj) throws UnsupportedOperationException { throw new UnsupportedOperationException(UNSUPPORTED_OPERATION_MESSAGE); } Modified: commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/iterators/LoopingIterator.java URL: http://svn.apache.org/viewvc/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/iterators/LoopingIterator.java?rev=738956&r1=738955&r2=738956&view=diff ============================================================================== --- commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/iterators/LoopingIterator.java (original) +++ commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/iterators/LoopingIterator.java Thu Jan 29 18:48:37 2009 @@ -38,12 +38,12 @@ * @author Jonathan Carlson * @author Stephen Colebourne */ -public class LoopingIterator implements ResettableIterator { +public class LoopingIterator implements ResettableIterator { /** The collection to base the iterator on */ - private Collection collection; + private Collection collection; /** The current iterator */ - private Iterator iterator; + private Iterator iterator; /** * Constructor that wraps a collection. @@ -54,7 +54,7 @@ * @param coll the collection to wrap * @throws NullPointerException if the collection is null */ - public LoopingIterator(Collection coll) { + public LoopingIterator(Collection coll) { if (coll == null) { throw new NullPointerException("The collection must not be null"); } @@ -82,7 +82,7 @@ * @throws NoSuchElementException if there are no elements * at all. Use {@link #hasNext} to avoid this error. */ - public Object next() { + public E next() { if (collection.size() == 0) { throw new NoSuchElementException("There are no elements for this iterator to loop on"); } Modified: commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/iterators/LoopingListIterator.java URL: http://svn.apache.org/viewvc/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/iterators/LoopingListIterator.java?rev=738956&r1=738955&r2=738956&view=diff ============================================================================== --- commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/iterators/LoopingListIterator.java (original) +++ commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/iterators/LoopingListIterator.java Thu Jan 29 18:48:37 2009 @@ -39,12 +39,12 @@ * * @author Eric Crampton */ -public class LoopingListIterator implements ResettableListIterator { +public class LoopingListIterator implements ResettableListIterator { /** The list to base the iterator on */ - private List list; + private List list; /** The current list iterator */ - private ListIterator iterator; + private ListIterator iterator; /** * Constructor that wraps a list. @@ -56,7 +56,7 @@ * @param list the list to wrap * @throws NullPointerException if the list it null */ - public LoopingListIterator(List list) { + public LoopingListIterator(List list) { if (list == null) { throw new NullPointerException("The list must not be null"); } @@ -84,7 +84,7 @@ * @return the object after the last element returned * @throws NoSuchElementException if there are no elements in the list */ - public Object next() { + public E next() { if (list.isEmpty()) { throw new NoSuchElementException( "There are no elements for this iterator to loop on"); @@ -113,9 +113,8 @@ } if (iterator.hasNext() == false) { return 0; - } else { - return iterator.nextIndex(); } + return iterator.nextIndex(); } /** @@ -139,21 +138,20 @@ * @return the object before the last element returned * @throws NoSuchElementException if there are no elements in the list */ - public Object previous() { + public E previous() { if (list.isEmpty()) { throw new NoSuchElementException( "There are no elements for this iterator to loop on"); } if (iterator.hasPrevious() == false) { - Object result = null; + E result = null; while (iterator.hasNext()) { result = iterator.next(); } iterator.previous(); return result; - } else { - return iterator.previous(); } + return iterator.previous(); } /** @@ -174,9 +172,8 @@ } if (iterator.hasPrevious() == false) { return list.size() - 1; - } else { - return iterator.previousIndex(); } + return iterator.previousIndex(); } /** @@ -216,7 +213,7 @@ * @throws UnsupportedOperationException if the add method is not * supported by the iterator implementation of the underlying list */ - public void add(Object obj) { + public void add(E obj) { iterator.add(obj); } @@ -232,7 +229,7 @@ * @throws UnsupportedOperationException if the set method is not * supported by the iterator implementation of the underlying list */ - public void set(Object obj) { + public void set(E obj) { iterator.set(obj); } Modified: commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/iterators/ObjectArrayIterator.java URL: http://svn.apache.org/viewvc/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/iterators/ObjectArrayIterator.java?rev=738956&r1=738955&r2=738956&view=diff ============================================================================== --- commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/iterators/ObjectArrayIterator.java (original) +++ commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/iterators/ObjectArrayIterator.java Thu Jan 29 18:48:37 2009 @@ -40,11 +40,11 @@ * @author Stephen Colebourne * @author Phil Steitz */ -public class ObjectArrayIterator - implements Iterator, ResettableIterator { +public class ObjectArrayIterator + implements Iterator, ResettableIterator { /** The array */ - protected Object[] array = null; + protected E[] array = null; /** The start index to loop from */ protected int startIndex = 0; /** The end index to loop to */ @@ -69,7 +69,7 @@ * @param array the array to iterate over * @throws NullPointerException if array is null */ - public ObjectArrayIterator(Object[] array) { + public ObjectArrayIterator(E[] array) { this(array, 0, array.length); } @@ -82,7 +82,7 @@ * @throws NullPointerException if array is null * @throws IndexOutOfBoundsException if the start index is out of bounds */ - public ObjectArrayIterator(Object array[], int start) { + public ObjectArrayIterator(E array[], int start) { this(array, start, array.length); } @@ -97,7 +97,7 @@ * @throws IllegalArgumentException if end index is before the start * @throws NullPointerException if array is null */ - public ObjectArrayIterator(Object array[], int start, int end) { + public ObjectArrayIterator(E array[], int start, int end) { super(); if (start < 0) { throw new ArrayIndexOutOfBoundsException("Start index must not be less than zero"); @@ -136,7 +136,7 @@ * @throws NoSuchElementException if all the elements in the array * have already been returned */ - public Object next() { + public E next() { if (hasNext() == false) { throw new NoSuchElementException(); } @@ -162,7 +162,7 @@ * the no-arg constructor was used and {@link #setArray} has never * been called with a valid array. */ - public Object[] getArray() { + public E[] getArray() { return this.array; } @@ -178,7 +178,7 @@ * @throws IllegalStateException if the array was set in the constructor * @throws NullPointerException if array is null */ - public void setArray(Object[] array) { + public void setArray(E[] array) { if (this.array != null) { throw new IllegalStateException("The array to iterate over has already been set"); } Modified: commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/iterators/ObjectArrayListIterator.java URL: http://svn.apache.org/viewvc/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/iterators/ObjectArrayListIterator.java?rev=738956&r1=738955&r2=738956&view=diff ============================================================================== --- commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/iterators/ObjectArrayListIterator.java (original) +++ commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/iterators/ObjectArrayListIterator.java Thu Jan 29 18:48:37 2009 @@ -41,8 +41,8 @@ * @author Stephen Colebourne * @author Phil Steitz */ -public class ObjectArrayListIterator extends ObjectArrayIterator - implements ListIterator, ResettableListIterator { +public class ObjectArrayListIterator extends ObjectArrayIterator + implements ListIterator, ResettableListIterator { /** * Holds the index of the last item returned by a call to next() @@ -69,7 +69,7 @@ * @param array the array to iterate over * @throws NullPointerException if array is null */ - public ObjectArrayListIterator(Object[] array) { + public ObjectArrayListIterator(E[] array) { super(array); } @@ -82,7 +82,7 @@ * @throws NullPointerException if array is null * @throws IndexOutOfBoundsException if the start index is out of bounds */ - public ObjectArrayListIterator(Object[] array, int start) { + public ObjectArrayListIterator(E[] array, int start) { super(array, start); } @@ -97,7 +97,7 @@ * @throws IllegalArgumentException if end index is before the start * @throws NullPointerException if array is null */ - public ObjectArrayListIterator(Object[] array, int start, int end) { + public ObjectArrayListIterator(E[] array, int start, int end) { super(array, start, end); } @@ -119,7 +119,7 @@ * @return the previous element * @throws NoSuchElementException if there is no previous element */ - public Object previous() { + public E previous() { if (hasPrevious() == false) { throw new NoSuchElementException(); } @@ -133,7 +133,7 @@ * @return the next element * @throws NoSuchElementException if there is no next element */ - public Object next() { + public E next() { if (hasNext() == false) { throw new NoSuchElementException(); } @@ -166,7 +166,7 @@ * @param obj the object to add * @throws UnsupportedOperationException always thrown. */ - public void add(Object obj) { + public void add(E obj) { throw new UnsupportedOperationException("add() method is not supported"); } @@ -187,7 +187,7 @@ * @throws IllegalStateException if next() has not yet been called. * @throws ClassCastException if the object type is unsuitable for the array */ - public void set(Object obj) { + public void set(E obj) { if (this.lastItemIndex == -1) { throw new IllegalStateException("must call next() or previous() before a call to set()"); } Modified: commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/iterators/ObjectGraphIterator.java URL: http://svn.apache.org/viewvc/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/iterators/ObjectGraphIterator.java?rev=738956&r1=738955&r2=738956&view=diff ============================================================================== --- commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/iterators/ObjectGraphIterator.java (original) +++ commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/iterators/ObjectGraphIterator.java Thu Jan 29 18:48:37 2009 @@ -75,23 +75,23 @@ * * @author Stephen Colebourne */ -public class ObjectGraphIterator implements Iterator { +public class ObjectGraphIterator implements Iterator { /** The stack of iterators */ - protected final ArrayStack stack = new ArrayStack(8); + protected final ArrayStack> stack = new ArrayStack>(8); /** The root object in the tree */ - protected Object root; + protected E root; /** The transformer to use */ - protected Transformer transformer; + protected Transformer transformer; /** Whether there is another element in the iteration */ - protected boolean hasNext = false; + protected boolean hasNext = false; /** The current iterator */ - protected Iterator currentIterator; + protected Iterator currentIterator; /** The current value */ - protected Object currentValue; + protected E currentValue; /** The last used iterator, needed for remove() */ - protected Iterator lastUsedIterator; + protected Iterator lastUsedIterator; //----------------------------------------------------------------------- /** @@ -103,10 +103,11 @@ * @param root the root object, null will result in an empty iterator * @param transformer the transformer to use, null will use a no effect transformer */ - public ObjectGraphIterator(Object root, Transformer transformer) { + @SuppressWarnings("unchecked") + public ObjectGraphIterator(E root, Transformer transformer) { super(); if (root instanceof Iterator) { - this.currentIterator = (Iterator) root; + this.currentIterator = (Iterator) root; } else { this.root = root; } @@ -123,7 +124,7 @@ * * @param rootIterator the root iterator, null will result in an empty iterator */ - public ObjectGraphIterator(Iterator rootIterator) { + public ObjectGraphIterator(Iterator rootIterator) { super(); this.currentIterator = rootIterator; this.transformer = null; @@ -158,10 +159,11 @@ * * @param value the value to start from */ - protected void findNext(Object value) { + @SuppressWarnings("unchecked") + protected void findNext(E value) { if (value instanceof Iterator) { // need to examine this iterator - findNextByIterator((Iterator) value); + findNextByIterator((Iterator) value); } else { // next value found currentValue = value; @@ -174,7 +176,7 @@ * * @param iterator the iterator to start from */ - protected void findNextByIterator(Iterator iterator) { + protected void findNextByIterator(Iterator iterator) { if (iterator != currentIterator) { // recurse a level if (currentIterator != null) { @@ -184,7 +186,7 @@ } while (currentIterator.hasNext() && hasNext == false) { - Object next = currentIterator.next(); + E next = currentIterator.next(); if (transformer != null) { next = transformer.transform(next); } @@ -196,7 +198,7 @@ // all iterators exhausted } else { // current iterator exhausted, go up a level - currentIterator = (Iterator) stack.pop(); + currentIterator = (Iterator) stack.pop(); findNextByIterator(currentIterator); } } @@ -218,13 +220,13 @@ * @return the next element from the iteration * @throws NoSuchElementException if all the Iterators are exhausted */ - public Object next() { + public E next() { updateCurrentIterator(); if (hasNext == false) { throw new NoSuchElementException("No more elements in the iteration"); } lastUsedIterator = currentIterator; - Object result = currentValue; + E result = currentValue; currentValue = null; hasNext = false; return result; Modified: commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/iterators/ReverseListIterator.java URL: http://svn.apache.org/viewvc/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/iterators/ReverseListIterator.java?rev=738956&r1=738955&r2=738956&view=diff ============================================================================== --- commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/iterators/ReverseListIterator.java (original) +++ commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/iterators/ReverseListIterator.java Thu Jan 29 18:48:37 2009 @@ -38,12 +38,12 @@ * @since Commons Collections 3.2 * @version $Revision: $ $Date$ */ -public class ReverseListIterator implements ResettableListIterator { +public class ReverseListIterator implements ResettableListIterator { /** The list being wrapped. */ - private final List list; + private final List list; /** The list iterator being wrapped. */ - private ListIterator iterator; + private ListIterator iterator; /** Flag to indicate if updating is possible at the moment. */ private boolean validForUpdate = true; @@ -53,7 +53,7 @@ * @param list the list to create a reversed iterator for * @throws NullPointerException if the list is null */ - public ReverseListIterator(List list) { + public ReverseListIterator(List list) { super(); this.list = list; iterator = list.listIterator(list.size()); @@ -75,8 +75,8 @@ * * @return the next element in the iterator */ - public Object next() { - Object obj = iterator.previous(); + public E next() { + E obj = iterator.previous(); validForUpdate = true; return obj; } @@ -105,8 +105,8 @@ * * @return the previous element in the iterator */ - public Object previous() { - Object obj = iterator.next(); + public E previous() { + E obj = iterator.next(); validForUpdate = true; return obj; } @@ -140,7 +140,7 @@ * @throws UnsupportedOperationException if the list is unmodifiable * @throws IllegalStateException if the iterator is not in a valid state for set */ - public void set(Object obj) { + public void set(E obj) { if (validForUpdate == false) { throw new IllegalStateException("Cannot set to list until next() or previous() called"); } @@ -154,7 +154,7 @@ * @throws UnsupportedOperationException if the list is unmodifiable * @throws IllegalStateException if the iterator is not in a valid state for set */ - public void add(Object obj) { + public void add(E obj) { // the validForUpdate flag is needed as the necessary previous() // method call re-enables remove and add if (validForUpdate == false) { Modified: commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/iterators/SingletonIterator.java URL: http://svn.apache.org/viewvc/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/iterators/SingletonIterator.java?rev=738956&r1=738955&r2=738956&view=diff ============================================================================== --- commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/iterators/SingletonIterator.java (original) +++ commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/iterators/SingletonIterator.java Thu Jan 29 18:48:37 2009 @@ -32,8 +32,8 @@ * @author Stephen Colebourne * @author Rodney Waldhoff */ -public class SingletonIterator - implements Iterator, ResettableIterator { +public class SingletonIterator + implements Iterator, ResettableIterator { /** Whether remove is allowed */ private final boolean removeAllowed; @@ -42,7 +42,7 @@ /** Has the element been removed */ private boolean removed = false; /** The object */ - private Object object; + private E object; /** * Constructs a new SingletonIterator where remove @@ -50,7 +50,7 @@ * * @param object the single object to return from the iterator */ - public SingletonIterator(Object object) { + public SingletonIterator(E object) { this(object, true); } @@ -62,7 +62,7 @@ * @param removeAllowed true if remove is allowed * @since Commons Collections 3.1 */ - public SingletonIterator(Object object, boolean removeAllowed) { + public SingletonIterator(E object, boolean removeAllowed) { super(); this.object = object; this.removeAllowed = removeAllowed; @@ -89,7 +89,7 @@ * @throws NoSuchElementException if the single object has already * been returned */ - public Object next() { + public E next() { if (!beforeFirst || removed) { throw new NoSuchElementException(); } Modified: commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/iterators/SingletonListIterator.java URL: http://svn.apache.org/viewvc/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/iterators/SingletonListIterator.java?rev=738956&r1=738955&r2=738956&view=diff ============================================================================== --- commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/iterators/SingletonListIterator.java (original) +++ commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/iterators/SingletonListIterator.java Thu Jan 29 18:48:37 2009 @@ -31,19 +31,19 @@ * @author Stephen Colebourne * @author Rodney Waldhoff */ -public class SingletonListIterator implements ListIterator, ResettableListIterator { +public class SingletonListIterator implements ListIterator, ResettableListIterator { private boolean beforeFirst = true; private boolean nextCalled = false; private boolean removed = false; - private Object object; + private E object; /** * Constructs a new SingletonListIterator. * * @param object the single object to return from the iterator */ - public SingletonListIterator(Object object) { + public SingletonListIterator(E object) { super(); this.object = object; } @@ -100,7 +100,7 @@ * @throws NoSuchElementException if the single object has already * been returned */ - public Object next() { + public E next() { if (!beforeFirst || removed) { throw new NoSuchElementException(); } @@ -118,7 +118,7 @@ * @throws NoSuchElementException if the single object has not already * been returned */ - public Object previous() { + public E previous() { if (beforeFirst || removed) { throw new NoSuchElementException(); } @@ -147,7 +147,7 @@ * * @throws UnsupportedOperationException always */ - public void add(Object obj) { + public void add(E obj) { throw new UnsupportedOperationException("add() is not supported by this iterator"); } @@ -158,7 +158,7 @@ * @throws IllegalStateException if next has not been called * or the object has been removed */ - public void set(Object obj) { + public void set(E obj) { if (!nextCalled || removed) { throw new IllegalStateException(); } Modified: commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/iterators/TransformIterator.java URL: http://svn.apache.org/viewvc/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/iterators/TransformIterator.java?rev=738956&r1=738955&r2=738956&view=diff ============================================================================== --- commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/iterators/TransformIterator.java (original) +++ commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/iterators/TransformIterator.java Thu Jan 29 18:48:37 2009 @@ -29,18 +29,18 @@ * @author James Strachan * @author Stephen Colebourne */ -public class TransformIterator implements Iterator { +public class TransformIterator implements Iterator { /** The iterator being used */ - private Iterator iterator; + private Iterator iterator; /** The transformer being used */ - private Transformer transformer; + private Transformer transformer; //----------------------------------------------------------------------- /** * Constructs a new TransformIterator that will not function - * until the {@link #setIterator(Iterator) setIterator} method is - * invoked. + * until the {@link #setIterator(Iterator) setIterator} and + * {@link #setTransformer(Transformer)} methods are invoked. */ public TransformIterator() { super(); @@ -52,7 +52,7 @@ * * @param iterator the iterator to use */ - public TransformIterator(Iterator iterator) { + public TransformIterator(Iterator iterator) { super(); this.iterator = iterator; } @@ -65,7 +65,7 @@ * @param iterator the iterator to use * @param transformer the transformer to use */ - public TransformIterator(Iterator iterator, Transformer transformer) { + public TransformIterator(Iterator iterator, Transformer transformer) { super(); this.iterator = iterator; this.transformer = transformer; @@ -84,7 +84,7 @@ * @return the next object * @throws java.util.NoSuchElementException if there are no more elements */ - public Object next() { + public O next() { return transform(iterator.next()); } @@ -98,7 +98,7 @@ * * @return the iterator. */ - public Iterator getIterator() { + public Iterator getIterator() { return iterator; } @@ -108,7 +108,7 @@ * * @param iterator the iterator to use */ - public void setIterator(Iterator iterator) { + public void setIterator(Iterator iterator) { this.iterator = iterator; } @@ -118,7 +118,7 @@ * * @return the transformer. */ - public Transformer getTransformer() { + public Transformer getTransformer() { return transformer; } @@ -128,7 +128,7 @@ * * @param transformer the transformer to use */ - public void setTransformer(Transformer transformer) { + public void setTransformer(Transformer transformer) { this.transformer = transformer; } @@ -140,10 +140,7 @@ * @param source the object to transform * @return the transformed object */ - protected Object transform(Object source) { - if (transformer != null) { - return transformer.transform(source); - } - return source; + protected O transform(I source) { + return transformer.transform(source); } } Modified: commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/iterators/UniqueFilterIterator.java URL: http://svn.apache.org/viewvc/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/iterators/UniqueFilterIterator.java?rev=738956&r1=738955&r2=738956&view=diff ============================================================================== --- commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/iterators/UniqueFilterIterator.java (original) +++ commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/iterators/UniqueFilterIterator.java Thu Jan 29 18:48:37 2009 @@ -5,9 +5,9 @@ * 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. @@ -20,26 +20,26 @@ import org.apache.commons.collections.functors.UniquePredicate; -/** +/** * A FilterIterator which only returns "unique" Objects. Internally, * the Iterator maintains a Set of objects it has already encountered, * and duplicate Objects are skipped. * * @since Commons Collections 2.1 * @version $Revision$ $Date$ - * + * * @author Morgan Delagrange */ -public class UniqueFilterIterator extends FilterIterator { - +public class UniqueFilterIterator extends FilterIterator { + //------------------------------------------------------------------------- - + /** * Constructs a new UniqueFilterIterator. * * @param iterator the iterator to use */ - public UniqueFilterIterator( Iterator iterator ) { + public UniqueFilterIterator(Iterator iterator) { super(iterator, UniquePredicate.getInstance()); } Modified: commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/iterators/UnmodifiableIterator.java URL: http://svn.apache.org/viewvc/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/iterators/UnmodifiableIterator.java?rev=738956&r1=738955&r2=738956&view=diff ============================================================================== --- commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/iterators/UnmodifiableIterator.java (original) +++ commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/iterators/UnmodifiableIterator.java Thu Jan 29 18:48:37 2009 @@ -28,10 +28,10 @@ * * @author Stephen Colebourne */ -public final class UnmodifiableIterator implements Iterator, Unmodifiable { +public final class UnmodifiableIterator implements Iterator, Unmodifiable { /** The iterator being decorated */ - private Iterator iterator; + private Iterator iterator; //----------------------------------------------------------------------- /** @@ -42,23 +42,23 @@ * @param iterator the iterator to decorate * @throws IllegalArgumentException if the iterator is null */ - public static Iterator decorate(Iterator iterator) { + public static Iterator decorate(Iterator iterator) { if (iterator == null) { throw new IllegalArgumentException("Iterator must not be null"); } if (iterator instanceof Unmodifiable) { return iterator; } - return new UnmodifiableIterator(iterator); + return new UnmodifiableIterator(iterator); } - + //----------------------------------------------------------------------- /** * Constructor. * * @param iterator the iterator to decorate */ - private UnmodifiableIterator(Iterator iterator) { + private UnmodifiableIterator(Iterator iterator) { super(); this.iterator = iterator; } @@ -68,7 +68,7 @@ return iterator.hasNext(); } - public Object next() { + public E next() { return iterator.next(); } Modified: commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/iterators/UnmodifiableListIterator.java URL: http://svn.apache.org/viewvc/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/iterators/UnmodifiableListIterator.java?rev=738956&r1=738955&r2=738956&view=diff ============================================================================== --- commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/iterators/UnmodifiableListIterator.java (original) +++ commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/iterators/UnmodifiableListIterator.java Thu Jan 29 18:48:37 2009 @@ -28,10 +28,10 @@ * * @author Stephen Colebourne */ -public final class UnmodifiableListIterator implements ListIterator, Unmodifiable { +public final class UnmodifiableListIterator implements ListIterator, Unmodifiable { /** The iterator being decorated */ - private ListIterator iterator; + private ListIterator iterator; //----------------------------------------------------------------------- /** @@ -40,14 +40,14 @@ * @param iterator the iterator to decorate * @throws IllegalArgumentException if the iterator is null */ - public static ListIterator decorate(ListIterator iterator) { + public static ListIterator decorate(ListIterator iterator) { if (iterator == null) { throw new IllegalArgumentException("ListIterator must not be null"); } if (iterator instanceof Unmodifiable) { return iterator; } - return new UnmodifiableListIterator(iterator); + return new UnmodifiableListIterator(iterator); } //----------------------------------------------------------------------- @@ -56,7 +56,7 @@ * * @param iterator the iterator to decorate */ - private UnmodifiableListIterator(ListIterator iterator) { + private UnmodifiableListIterator(ListIterator iterator) { super(); this.iterator = iterator; } @@ -66,7 +66,7 @@ return iterator.hasNext(); } - public Object next() { + public E next() { return iterator.next(); } @@ -78,7 +78,7 @@ return iterator.hasPrevious(); } - public Object previous() { + public E previous() { return iterator.previous(); } @@ -90,11 +90,11 @@ throw new UnsupportedOperationException("remove() is not supported"); } - public void set(Object obj) { + public void set(E obj) { throw new UnsupportedOperationException("set() is not supported"); } - public void add(Object obj) { + public void add(E obj) { throw new UnsupportedOperationException("add() is not supported"); } Modified: commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/iterators/UnmodifiableMapIterator.java URL: http://svn.apache.org/viewvc/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/iterators/UnmodifiableMapIterator.java?rev=738956&r1=738955&r2=738956&view=diff ============================================================================== --- commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/iterators/UnmodifiableMapIterator.java (original) +++ commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/iterators/UnmodifiableMapIterator.java Thu Jan 29 18:48:37 2009 @@ -27,10 +27,10 @@ * * @author Stephen Colebourne */ -public final class UnmodifiableMapIterator implements MapIterator, Unmodifiable { +public final class UnmodifiableMapIterator implements MapIterator, Unmodifiable { /** The iterator being decorated */ - private MapIterator iterator; + private MapIterator iterator; //----------------------------------------------------------------------- /** @@ -39,23 +39,23 @@ * @param iterator the iterator to decorate * @throws IllegalArgumentException if the iterator is null */ - public static MapIterator decorate(MapIterator iterator) { + public static MapIterator decorate(MapIterator iterator) { if (iterator == null) { throw new IllegalArgumentException("MapIterator must not be null"); } if (iterator instanceof Unmodifiable) { return iterator; } - return new UnmodifiableMapIterator(iterator); + return new UnmodifiableMapIterator(iterator); } - + //----------------------------------------------------------------------- /** * Constructor. * * @param iterator the iterator to decorate */ - private UnmodifiableMapIterator(MapIterator iterator) { + private UnmodifiableMapIterator(MapIterator iterator) { super(); this.iterator = iterator; } @@ -65,19 +65,19 @@ return iterator.hasNext(); } - public Object next() { + public K next() { return iterator.next(); } - public Object getKey() { + public K getKey() { return iterator.getKey(); } - public Object getValue() { + public V getValue() { return iterator.getValue(); } - public Object setValue(Object value) { + public V setValue(V value) { throw new UnsupportedOperationException("setValue() is not supported"); } Modified: commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/iterators/UnmodifiableOrderedMapIterator.java URL: http://svn.apache.org/viewvc/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/iterators/UnmodifiableOrderedMapIterator.java?rev=738956&r1=738955&r2=738956&view=diff ============================================================================== --- commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/iterators/UnmodifiableOrderedMapIterator.java (original) +++ commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/iterators/UnmodifiableOrderedMapIterator.java Thu Jan 29 18:48:37 2009 @@ -5,9 +5,9 @@ * 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. @@ -19,18 +19,19 @@ import org.apache.commons.collections.OrderedMapIterator; import org.apache.commons.collections.Unmodifiable; -/** +/** * Decorates an ordered map iterator such that it cannot be modified. * * @since Commons Collections 3.0 * @version $Revision$ $Date$ - * + * * @author Stephen Colebourne */ -public final class UnmodifiableOrderedMapIterator implements OrderedMapIterator, Unmodifiable { +public final class UnmodifiableOrderedMapIterator implements OrderedMapIterator, + Unmodifiable { /** The iterator being decorated */ - private OrderedMapIterator iterator; + private OrderedMapIterator iterator; //----------------------------------------------------------------------- /** @@ -39,23 +40,23 @@ * @param iterator the iterator to decorate * @throws IllegalArgumentException if the iterator is null */ - public static OrderedMapIterator decorate(OrderedMapIterator iterator) { + public static OrderedMapIterator decorate(OrderedMapIterator iterator) { if (iterator == null) { throw new IllegalArgumentException("OrderedMapIterator must not be null"); } if (iterator instanceof Unmodifiable) { return iterator; } - return new UnmodifiableOrderedMapIterator(iterator); + return new UnmodifiableOrderedMapIterator(iterator); } - + //----------------------------------------------------------------------- /** * Constructor. * * @param iterator the iterator to decorate */ - private UnmodifiableOrderedMapIterator(OrderedMapIterator iterator) { + private UnmodifiableOrderedMapIterator(OrderedMapIterator iterator) { super(); this.iterator = iterator; } @@ -65,7 +66,7 @@ return iterator.hasNext(); } - public Object next() { + public K next() { return iterator.next(); } @@ -73,19 +74,19 @@ return iterator.hasPrevious(); } - public Object previous() { + public K previous() { return iterator.previous(); } - public Object getKey() { + public K getKey() { return iterator.getKey(); } - public Object getValue() { + public V getValue() { return iterator.getValue(); } - public Object setValue(Object value) { + public V setValue(V value) { throw new UnsupportedOperationException("setValue() is not supported"); } Modified: commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/keyvalue/AbstractKeyValue.java URL: http://svn.apache.org/viewvc/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/keyvalue/AbstractKeyValue.java?rev=738956&r1=738955&r2=738956&view=diff ============================================================================== --- commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/keyvalue/AbstractKeyValue.java (original) +++ commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/keyvalue/AbstractKeyValue.java Thu Jan 29 18:48:37 2009 @@ -30,12 +30,12 @@ * @author Neil O'Toole * @author Stephen Colebourne */ -public abstract class AbstractKeyValue implements KeyValue { +public abstract class AbstractKeyValue implements KeyValue { /** The key */ - protected Object key; + protected K key; /** The value */ - protected Object value; + protected V value; /** * Constructs a new pair with the specified key and given value. @@ -43,7 +43,7 @@ * @param key the key for the entry, may be null * @param value the value for the entry, may be null */ - protected AbstractKeyValue(Object key, Object value) { + protected AbstractKeyValue(K key, V value) { super(); this.key = key; this.value = value; @@ -54,7 +54,7 @@ * * @return the key */ - public Object getKey() { + public K getKey() { return key; } @@ -63,7 +63,7 @@ * * @return the value */ - public Object getValue() { + public V getValue() { return value; } Modified: commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/keyvalue/AbstractMapEntry.java URL: http://svn.apache.org/viewvc/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/keyvalue/AbstractMapEntry.java?rev=738956&r1=738955&r2=738956&view=diff ============================================================================== --- commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/keyvalue/AbstractMapEntry.java (original) +++ commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/keyvalue/AbstractMapEntry.java Thu Jan 29 18:48:37 2009 @@ -30,7 +30,7 @@ * @author Neil O'Toole * @author Stephen Colebourne */ -public abstract class AbstractMapEntry extends AbstractKeyValue implements Map.Entry { +public abstract class AbstractMapEntry extends AbstractKeyValue implements Map.Entry { /** * Constructs a new entry with the given key and given value. @@ -38,7 +38,7 @@ * @param key the key for the entry, may be null * @param value the value for the entry, may be null */ - protected AbstractMapEntry(Object key, Object value) { + protected AbstractMapEntry(K key, V value) { super(key, value); } @@ -53,8 +53,8 @@ * @param value the new value * @return the previous value */ - public Object setValue(Object value) { - Object answer = this.value; + public V setValue(V value) { + V answer = this.value; this.value = value; return answer; } @@ -67,6 +67,7 @@ * @param obj the object to compare to * @return true if equal key and value */ + @SuppressWarnings("unchecked") public boolean equals(Object obj) { if (obj == this) { return true; Modified: commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/keyvalue/AbstractMapEntryDecorator.java URL: http://svn.apache.org/viewvc/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/keyvalue/AbstractMapEntryDecorator.java?rev=738956&r1=738955&r2=738956&view=diff ============================================================================== --- commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/keyvalue/AbstractMapEntryDecorator.java (original) +++ commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/keyvalue/AbstractMapEntryDecorator.java Thu Jan 29 18:48:37 2009 @@ -29,10 +29,10 @@ * * @author Stephen Colebourne */ -public abstract class AbstractMapEntryDecorator implements Map.Entry, KeyValue { +public abstract class AbstractMapEntryDecorator implements Map.Entry, KeyValue { /** The Map.Entry to decorate */ - protected final Map.Entry entry; + protected final Map.Entry entry; /** * Constructor that wraps (not copies). @@ -40,7 +40,7 @@ * @param entry the Map.Entry to decorate, must not be null * @throws IllegalArgumentException if the collection is null */ - public AbstractMapEntryDecorator(Map.Entry entry) { + public AbstractMapEntryDecorator(Map.Entry entry) { if (entry == null) { throw new IllegalArgumentException("Map Entry must not be null"); } @@ -52,20 +52,20 @@ * * @return the decorated map */ - protected Map.Entry getMapEntry() { + protected Map.Entry getMapEntry() { return entry; } //----------------------------------------------------------------------- - public Object getKey() { + public K getKey() { return entry.getKey(); } - public Object getValue() { + public V getValue() { return entry.getValue(); } - public Object setValue(Object object) { + public V setValue(V object) { return entry.setValue(object); } Modified: commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/keyvalue/DefaultKeyValue.java URL: http://svn.apache.org/viewvc/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/keyvalue/DefaultKeyValue.java?rev=738956&r1=738955&r2=738956&view=diff ============================================================================== --- commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/keyvalue/DefaultKeyValue.java (original) +++ commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/keyvalue/DefaultKeyValue.java Thu Jan 29 18:48:37 2009 @@ -35,7 +35,7 @@ * @author Neil O'Toole * @author Stephen Colebourne */ -public class DefaultKeyValue extends AbstractKeyValue { +public class DefaultKeyValue extends AbstractKeyValue { /** * Constructs a new pair with a null key and null value. @@ -50,7 +50,7 @@ * @param key the key for the entry, may be null * @param value the value for the entry, may be null */ - public DefaultKeyValue(final Object key, final Object value) { + public DefaultKeyValue(final K key, final V value) { super(key, value); } @@ -60,7 +60,7 @@ * @param pair the pair to copy, must not be null * @throws NullPointerException if the entry is null */ - public DefaultKeyValue(final KeyValue pair) { + public DefaultKeyValue(final KeyValue pair) { super(pair.getKey(), pair.getValue()); } @@ -70,7 +70,7 @@ * @param entry the entry to copy, must not be null * @throws NullPointerException if the entry is null */ - public DefaultKeyValue(final Map.Entry entry) { + public DefaultKeyValue(final Map.Entry entry) { super(entry.getKey(), entry.getValue()); } @@ -82,12 +82,12 @@ * @return the old key * @throws IllegalArgumentException if key is this object */ - public Object setKey(final Object key) { + public K setKey(final K key) { if (key == this) { throw new IllegalArgumentException("DefaultKeyValue may not contain itself as a key."); } - final Object old = this.key; + final K old = this.key; this.key = key; return old; } @@ -99,12 +99,12 @@ * @param value the new value * @throws IllegalArgumentException if value is this object */ - public Object setValue(final Object value) { + public V setValue(final V value) { if (value == this) { throw new IllegalArgumentException("DefaultKeyValue may not contain itself as a value."); } - final Object old = this.value; + final V old = this.value; this.value = value; return old; } @@ -115,8 +115,8 @@ * * @return a MapEntry instance */ - public Map.Entry toMapEntry() { - return new DefaultMapEntry(this); + public Map.Entry toMapEntry() { + return new DefaultMapEntry(this); } //----------------------------------------------------------------------- @@ -129,6 +129,7 @@ * @param obj the object to compare to * @return true if equal key and value */ + @SuppressWarnings("unchecked") public boolean equals(final Object obj) { if (obj == this) { return true; Modified: commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/keyvalue/DefaultMapEntry.java URL: http://svn.apache.org/viewvc/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/keyvalue/DefaultMapEntry.java?rev=738956&r1=738955&r2=738956&view=diff ============================================================================== --- commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/keyvalue/DefaultMapEntry.java (original) +++ commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/keyvalue/DefaultMapEntry.java Thu Jan 29 18:48:37 2009 @@ -32,7 +32,7 @@ * @author Neil O'Toole * @author Stephen Colebourne */ -public final class DefaultMapEntry extends AbstractMapEntry { +public final class DefaultMapEntry extends AbstractMapEntry { /** * Constructs a new entry with the specified key and given value. @@ -40,7 +40,7 @@ * @param key the key for the entry, may be null * @param value the value for the entry, may be null */ - public DefaultMapEntry(final Object key, final Object value) { + public DefaultMapEntry(final K key, final V value) { super(key, value); } @@ -50,7 +50,7 @@ * @param pair the pair to copy, must not be null * @throws NullPointerException if the entry is null */ - public DefaultMapEntry(final KeyValue pair) { + public DefaultMapEntry(final KeyValue pair) { super(pair.getKey(), pair.getValue()); } @@ -60,7 +60,7 @@ * @param entry the entry to copy, must not be null * @throws NullPointerException if the entry is null */ - public DefaultMapEntry(final Map.Entry entry) { + public DefaultMapEntry(final Map.Entry entry) { super(entry.getKey(), entry.getValue()); } Modified: commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/keyvalue/MultiKey.java URL: http://svn.apache.org/viewvc/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/keyvalue/MultiKey.java?rev=738956&r1=738955&r2=738956&view=diff ============================================================================== --- commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/keyvalue/MultiKey.java (original) +++ commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/keyvalue/MultiKey.java Thu Jan 29 18:48:37 2009 @@ -45,17 +45,17 @@ * @author Howard Lewis Ship * @author Stephen Colebourne */ -public class MultiKey implements Serializable { +public class MultiKey implements Serializable { // This class could implement List, but that would confuse it's purpose /** Serialisation version */ private static final long serialVersionUID = 4465448607415788805L; /** The individual keys */ - private final Object[] keys; + private final K[] keys; /** The cached hashCode */ private final int hashCode; - + /** * Constructor taking two keys. *

@@ -65,10 +65,11 @@ * @param key1 the first key * @param key2 the second key */ - public MultiKey(Object key1, Object key2) { - this(new Object[] {key1, key2}, false); + @SuppressWarnings("unchecked") + public MultiKey(K key1, K key2) { + this((K[]) new Object[] { key1, key2 }, false); } - + /** * Constructor taking three keys. *

@@ -79,10 +80,11 @@ * @param key2 the second key * @param key3 the third key */ - public MultiKey(Object key1, Object key2, Object key3) { - this(new Object[] {key1, key2, key3}, false); + @SuppressWarnings("unchecked") + public MultiKey(K key1, K key2, K key3) { + this((K[]) new Object[] {key1, key2, key3}, false); } - + /** * Constructor taking four keys. *

@@ -94,10 +96,11 @@ * @param key3 the third key * @param key4 the fourth key */ - public MultiKey(Object key1, Object key2, Object key3, Object key4) { - this(new Object[] {key1, key2, key3, key4}, false); + @SuppressWarnings("unchecked") + public MultiKey(K key1, K key2, K key3, K key4) { + this((K[]) new Object[] {key1, key2, key3, key4}, false); } - + /** * Constructor taking five keys. *

@@ -110,10 +113,11 @@ * @param key4 the fourth key * @param key5 the fifth key */ - public MultiKey(Object key1, Object key2, Object key3, Object key4, Object key5) { - this(new Object[] {key1, key2, key3, key4, key5}, false); + @SuppressWarnings("unchecked") + public MultiKey(K key1, K key2, K key3, K key4, K key5) { + this((K[]) new Object[] {key1, key2, key3, key4, key5}, false); } - + /** * Constructor taking an array of keys which is cloned. *

@@ -125,10 +129,10 @@ * @param keys the array of keys, not null * @throws IllegalArgumentException if the key array is null */ - public MultiKey(Object[] keys) { + public MultiKey(K[] keys) { this(keys, true); } - + /** * Constructor taking an array of keys, optionally choosing whether to clone. *

@@ -153,17 +157,17 @@ * @throws IllegalArgumentException if the key array is null * @since Commons Collections 3.1 */ - public MultiKey(Object[] keys, boolean makeClone) { + public MultiKey(K[] keys, boolean makeClone) { super(); if (keys == null) { throw new IllegalArgumentException("The array of keys must not be null"); } if (makeClone) { - this.keys = (Object[]) keys.clone(); + this.keys = keys.clone(); } else { this.keys = keys; } - + int total = 0; for (int i = 0; i < keys.length; i++) { if (keys[i] != null) { @@ -172,7 +176,7 @@ } hashCode = total; } - + //----------------------------------------------------------------------- /** * Gets a clone of the array of keys. @@ -182,10 +186,10 @@ * * @return the individual keys */ - public Object[] getKeys() { - return (Object[]) keys.clone(); + public K[] getKeys() { + return keys.clone(); } - + /** * Gets the key at the specified index. *

@@ -197,10 +201,10 @@ * @throws IndexOutOfBoundsException if the index is invalid * @since Commons Collections 3.1 */ - public Object getKey(int index) { + public K getKey(int index) { return keys[index]; } - + /** * Gets the size of the list of keys. * @@ -210,7 +214,7 @@ public int size() { return keys.length; } - + //----------------------------------------------------------------------- /** * Compares this object to another. @@ -226,7 +230,7 @@ return true; } if (other instanceof MultiKey) { - MultiKey otherMulti = (MultiKey) other; + MultiKey otherMulti = (MultiKey) other; return Arrays.equals(keys, otherMulti.keys); } return false; Modified: commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/keyvalue/TiedMapEntry.java URL: http://svn.apache.org/viewvc/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/keyvalue/TiedMapEntry.java?rev=738956&r1=738955&r2=738956&view=diff ============================================================================== --- commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/keyvalue/TiedMapEntry.java (original) +++ commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/keyvalue/TiedMapEntry.java Thu Jan 29 18:48:37 2009 @@ -32,15 +32,16 @@ * * @author Stephen Colebourne */ -public class TiedMapEntry implements Map.Entry, KeyValue, Serializable { +public class TiedMapEntry implements Map.Entry, KeyValue, Serializable { /** Serialization version */ private static final long serialVersionUID = -8453869361373831205L; /** The map underlying the entry/iterator */ - private final Map map; + private final Map map; + /** The key */ - private final Object key; + private final K key; /** * Constructs a new entry with the given Map and key. @@ -48,7 +49,7 @@ * @param map the map * @param key the key */ - public TiedMapEntry(Map map, Object key) { + public TiedMapEntry(Map map, K key) { super(); this.map = map; this.key = key; @@ -61,7 +62,7 @@ * * @return the key */ - public Object getKey() { + public K getKey() { return key; } @@ -70,7 +71,7 @@ * * @return the value */ - public Object getValue() { + public V getValue() { return map.get(key); } @@ -81,7 +82,7 @@ * @return the old value * @throws IllegalArgumentException if the value is set to this map entry */ - public Object setValue(Object value) { + public V setValue(V value) { if (value == this) { throw new IllegalArgumentException("Cannot set value to this map entry"); } @@ -96,6 +97,7 @@ * @param obj the object to compare to * @return true if equal key and value */ + @SuppressWarnings("unchecked") public boolean equals(Object obj) { if (obj == this) { return true; Modified: commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/keyvalue/UnmodifiableMapEntry.java URL: http://svn.apache.org/viewvc/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/keyvalue/UnmodifiableMapEntry.java?rev=738956&r1=738955&r2=738956&view=diff ============================================================================== --- commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/keyvalue/UnmodifiableMapEntry.java (original) +++ commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/keyvalue/UnmodifiableMapEntry.java Thu Jan 29 18:48:37 2009 @@ -30,7 +30,7 @@ * * @author Stephen Colebourne */ -public final class UnmodifiableMapEntry extends AbstractMapEntry implements Unmodifiable { +public final class UnmodifiableMapEntry extends AbstractMapEntry implements Unmodifiable { /** * Constructs a new entry with the specified key and given value. @@ -38,7 +38,7 @@ * @param key the key for the entry, may be null * @param value the value for the entry, may be null */ - public UnmodifiableMapEntry(final Object key, final Object value) { + public UnmodifiableMapEntry(final K key, final V value) { super(key, value); } @@ -48,7 +48,7 @@ * @param pair the pair to copy, must not be null * @throws NullPointerException if the entry is null */ - public UnmodifiableMapEntry(final KeyValue pair) { + public UnmodifiableMapEntry(final KeyValue pair) { super(pair.getKey(), pair.getValue()); } @@ -58,7 +58,7 @@ * @param entry the entry to copy, must not be null * @throws NullPointerException if the entry is null */ - public UnmodifiableMapEntry(final Map.Entry entry) { + public UnmodifiableMapEntry(final Map.Entry entry) { super(entry.getKey(), entry.getValue()); } @@ -69,7 +69,7 @@ * @return the previous value * @throws UnsupportedOperationException always */ - public Object setValue(Object value) { + public V setValue(V value) { throw new UnsupportedOperationException("setValue() is not supported"); }