From daccd005b34ddada8b41c191cd0985abb75f4e4d Mon Sep 17 00:00:00 2001 From: Stephen Colebourne Date: Sat, 6 May 2006 11:17:27 +0000 Subject: [PATCH] Javadoc and stylistic changes git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/collections/trunk@400286 13f79535-47bb-0310-9956-ffa450edef68 --- .../iterators/ListIteratorWrapper.java | 92 +++++++++---------- 1 file changed, 46 insertions(+), 46 deletions(-) diff --git a/src/java/org/apache/commons/collections/iterators/ListIteratorWrapper.java b/src/java/org/apache/commons/collections/iterators/ListIteratorWrapper.java index 0d0774b06..1d44249b6 100644 --- a/src/java/org/apache/commons/collections/iterators/ListIteratorWrapper.java +++ b/src/java/org/apache/commons/collections/iterators/ListIteratorWrapper.java @@ -21,34 +21,40 @@ import java.util.ListIterator; import java.util.NoSuchElementException; /** - * As the wrapped Iterator is traversed, ListIteratorWrapper - * builds a LinkedList of its values, permitting all required - * operations of ListIterator. - * + * Converts an iterator into a list iterator by caching the returned entries. + *

+ * The ListIterator interface has additional useful methods + * for navigation - previous() and the index methods. + * This class allows a regular Iterator to behave as a + * ListIterator. It achieves this by building a list internally + * of as the underlying iterator is traversed. + *

+ * The optional operations of ListIterator are not supported. + * * @since Commons Collections 2.1 * @version $Revision$ $Date$ - * + * * @author Morgan Delagrange * @author Stephen Colebourne */ public class ListIteratorWrapper implements ListIterator { - /** Holds value of property "iterator" */ - private final Iterator iterator; - private final LinkedList list = new LinkedList(); - - // position of this iterator - private int currentIndex = 0; - // position of the wrapped iterator - // this Iterator should only be used to populate the list - private int wrappedIteratorIndex = 0; - + /** 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; + /** The list being used to cache the iterator. */ + private final LinkedList list = new LinkedList(); + + /** The current index of this iterator. */ + private int currentIndex = 0; + /** The current index of the wrapped iterator. */ + private int wrappedIteratorIndex = 0; + // Constructor //------------------------------------------------------------------------- - /** * Constructs a new ListIteratorWrapper that will wrap * the given iterator. @@ -66,49 +72,45 @@ public class ListIteratorWrapper implements ListIterator { // ListIterator interface //------------------------------------------------------------------------- - /** - * Throws {@link UnsupportedOperationException}. + * Throws {@link UnsupportedOperationException}. * - * @param o ignored - * @throws UnsupportedOperationException always + * @param obj the object to add, ignored + * @throws UnsupportedOperationException always */ - public void add(Object o) throws UnsupportedOperationException { + public void add(Object obj) throws UnsupportedOperationException { throw new UnsupportedOperationException(UNSUPPORTED_OPERATION_MESSAGE); } - /** - * Returns true if there are more elements in the iterator. + * Returns true if there are more elements in the iterator. * - * @return true if there are more elements + * @return true if there are more elements */ public boolean hasNext() { if (currentIndex == wrappedIteratorIndex) { return iterator.hasNext(); } - return true; } /** - * Returns true if there are previous elements in the iterator. + * Returns true if there are previous elements in the iterator. * - * @return true if there are previous elements + * @return true if there are previous elements */ public boolean hasPrevious() { if (currentIndex == 0) { return false; } - return true; } /** - * Returns the next element from the iterator. + * Returns the next element from the iterator. * - * @return the next element from the iterator - * @throws NoSuchElementException if there are no more elements + * @return the next element from the iterator + * @throws NoSuchElementException if there are no more elements */ public Object next() throws NoSuchElementException { if (currentIndex < wrappedIteratorIndex) { @@ -124,56 +126,54 @@ public class ListIteratorWrapper implements ListIterator { } /** - * Returns in the index of the next element. + * Returns in the index of the next element. * - * @return the index of the next element + * @return the index of the next element */ public int nextIndex() { return currentIndex; } /** - * Returns the the previous element. + * Returns the the previous element. * - * @return the previous element - * @throws NoSuchElementException if there are no previous elements + * @return the previous element + * @throws NoSuchElementException if there are no previous elements */ public Object previous() throws NoSuchElementException { if (currentIndex == 0) { throw new NoSuchElementException(); } - --currentIndex; return list.get(currentIndex); } /** - * Returns the index of the previous element. + * Returns the index of the previous element. * - * @return the index of the previous element + * @return the index of the previous element */ public int previousIndex() { return currentIndex - 1; } /** - * Throws {@link UnsupportedOperationException}. + * Throws {@link UnsupportedOperationException}. * - * @throws UnsupportedOperationException always + * @throws UnsupportedOperationException always */ public void remove() throws UnsupportedOperationException { throw new UnsupportedOperationException(UNSUPPORTED_OPERATION_MESSAGE); } /** - * Throws {@link UnsupportedOperationException}. + * Throws {@link UnsupportedOperationException}. * - * @param o ignored - * @throws UnsupportedOperationException always + * @param obj the object to set, ignored + * @throws UnsupportedOperationException always */ - public void set(Object o) throws UnsupportedOperationException { + public void set(Object obj) throws UnsupportedOperationException { throw new UnsupportedOperationException(UNSUPPORTED_OPERATION_MESSAGE); } } -