org.apache.commons.collections
Class ArrayIterator
java.lang.Object
|
+--org.apache.commons.collections.ArrayIterator
- All Implemented Interfaces:
- Iterator
- public class ArrayIterator
- extends Object
- implements Iterator
Implements an Iterator
over an array of objects.
- Version:
- $Revision: 1.12 $
- Author:
- James Strachan, Mauricio S. Moura, Michael A. Smith
Constructor Summary |
ArrayIterator()
Construct an ArrayIterator. |
ArrayIterator(Object array)
Construct an ArrayIterator that will iterate over the values in the
specified array. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
ArrayIterator
public ArrayIterator()
- Construct an ArrayIterator. Using this constructor, the iterator is
equivalent to an empty iterator until
setArray(Object)
is
called to establish the array to iterate over.
ArrayIterator
public ArrayIterator(Object array)
- Construct an ArrayIterator that will iterate over the values in the
specified array.
- Parameters:
array
- the array to iterate over.- Throws:
IllegalArgumentException
- if array
is not an
array.NullPointerException
- if array
is null
getArray
public Object getArray()
- Retrieves the array that this iterator is iterating over.
- Returns:
- the array this iterator iterates over, or
null
if
the no-arg constructor was used and setArray(Object)
has never
been called with a valid array.
hasNext
public boolean hasNext()
- Specified by:
hasNext
in interface Iterator
next
public Object next()
- Specified by:
next
in interface Iterator
remove
public void remove()
- Specified by:
remove
in interface Iterator
setArray
public void setArray(Object array)
- Changes the array that the ArrayIterator should iterate over. If an
array has previously been set (using the single-arg constructor or this
method), that array along with the current iterator position within
that array is discarded in favor of the argument to this method. This
method can be used in combination with
getArray()
to "reset"
the iterator to the beginning of the array:
ArrayIterator iterator = ...
...
iterator.setArray(iterator.getArray());
Note: Using i.setArray(i.getArray()) may throw a NullPointerException
if no array has ever been set for the iterator (see getArray()
)
- Parameters:
array
- the array that the iterator should iterate over.- Throws:
IllegalArgumentException
- if array
is not an
array.NullPointerException
- if array
is null
Copyright © 2001 Apache Software Foundation. Documenation generated April 2 2002.