Javadoc and stylistic changes

git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/collections/trunk@400286 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Stephen Colebourne 2006-05-06 11:17:27 +00:00
parent 0d4cf5780b
commit daccd005b3
1 changed files with 46 additions and 46 deletions

View File

@ -21,34 +21,40 @@ import java.util.ListIterator;
import java.util.NoSuchElementException; import java.util.NoSuchElementException;
/** /**
* As the wrapped Iterator is traversed, ListIteratorWrapper * Converts an iterator into a list iterator by caching the returned entries.
* builds a LinkedList of its values, permitting all required * <p>
* operations of ListIterator. * The <code>ListIterator</code> interface has additional useful methods
* * for navigation - <code>previous()</code> and the index methods.
* This class allows a regular <code>Iterator</code> to behave as a
* <code>ListIterator</code>. It achieves this by building a list internally
* of as the underlying iterator is traversed.
* <p>
* The optional operations of <code>ListIterator</code> are not supported.
*
* @since Commons Collections 2.1 * @since Commons Collections 2.1
* @version $Revision$ $Date$ * @version $Revision$ $Date$
* *
* @author Morgan Delagrange * @author Morgan Delagrange
* @author Stephen Colebourne * @author Stephen Colebourne
*/ */
public class ListIteratorWrapper implements ListIterator { public class ListIteratorWrapper implements ListIterator {
/** Holds value of property "iterator" */ /** Message used when remove, set or add are called. */
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;
private static final String UNSUPPORTED_OPERATION_MESSAGE = private static final String UNSUPPORTED_OPERATION_MESSAGE =
"ListIteratorWrapper does not support optional operations of ListIterator."; "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 // Constructor
//------------------------------------------------------------------------- //-------------------------------------------------------------------------
/** /**
* Constructs a new <code>ListIteratorWrapper</code> that will wrap * Constructs a new <code>ListIteratorWrapper</code> that will wrap
* the given iterator. * the given iterator.
@ -66,49 +72,45 @@ public class ListIteratorWrapper implements ListIterator {
// ListIterator interface // ListIterator interface
//------------------------------------------------------------------------- //-------------------------------------------------------------------------
/** /**
* Throws {@link UnsupportedOperationException}. * Throws {@link UnsupportedOperationException}.
* *
* @param o ignored * @param obj the object to add, ignored
* @throws UnsupportedOperationException always * @throws UnsupportedOperationException always
*/ */
public void add(Object o) throws UnsupportedOperationException { public void add(Object obj) throws UnsupportedOperationException {
throw new UnsupportedOperationException(UNSUPPORTED_OPERATION_MESSAGE); 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() { public boolean hasNext() {
if (currentIndex == wrappedIteratorIndex) { if (currentIndex == wrappedIteratorIndex) {
return iterator.hasNext(); return iterator.hasNext();
} }
return true; 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() { public boolean hasPrevious() {
if (currentIndex == 0) { if (currentIndex == 0) {
return false; return false;
} }
return true; return true;
} }
/** /**
* Returns the next element from the iterator. * Returns the next element from the iterator.
* *
* @return the next element from the iterator * @return the next element from the iterator
* @throws NoSuchElementException if there are no more elements * @throws NoSuchElementException if there are no more elements
*/ */
public Object next() throws NoSuchElementException { public Object next() throws NoSuchElementException {
if (currentIndex < wrappedIteratorIndex) { 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() { public int nextIndex() {
return currentIndex; return currentIndex;
} }
/** /**
* Returns the the previous element. * Returns the the previous element.
* *
* @return the previous element * @return the previous element
* @throws NoSuchElementException if there are no previous elements * @throws NoSuchElementException if there are no previous elements
*/ */
public Object previous() throws NoSuchElementException { public Object previous() throws NoSuchElementException {
if (currentIndex == 0) { if (currentIndex == 0) {
throw new NoSuchElementException(); throw new NoSuchElementException();
} }
--currentIndex; --currentIndex;
return list.get(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() { public int previousIndex() {
return currentIndex - 1; return currentIndex - 1;
} }
/** /**
* Throws {@link UnsupportedOperationException}. * Throws {@link UnsupportedOperationException}.
* *
* @throws UnsupportedOperationException always * @throws UnsupportedOperationException always
*/ */
public void remove() throws UnsupportedOperationException { public void remove() throws UnsupportedOperationException {
throw new UnsupportedOperationException(UNSUPPORTED_OPERATION_MESSAGE); throw new UnsupportedOperationException(UNSUPPORTED_OPERATION_MESSAGE);
} }
/** /**
* Throws {@link UnsupportedOperationException}. * Throws {@link UnsupportedOperationException}.
* *
* @param o ignored * @param obj the object to set, ignored
* @throws UnsupportedOperationException always * @throws UnsupportedOperationException always
*/ */
public void set(Object o) throws UnsupportedOperationException { public void set(Object obj) throws UnsupportedOperationException {
throw new UnsupportedOperationException(UNSUPPORTED_OPERATION_MESSAGE); throw new UnsupportedOperationException(UNSUPPORTED_OPERATION_MESSAGE);
} }
} }