org.apache.commons.collections.iterators
Class ArrayIterator

java.lang.Object
  |
  +--org.apache.commons.collections.iterators.ArrayIterator
All Implemented Interfaces:
java.util.Iterator
Direct Known Subclasses:
ArrayIterator

public class ArrayIterator
extends java.lang.Object
implements java.util.Iterator

Implements an Iterator over an array of objects.

Since:
1.0
Version:
$Revision: 1.1.2.1 $
Author:
James Strachan, Mauricio S. Moura, Michael A. Smith

Constructor Summary
ArrayIterator()
          Construct an ArrayIterator.
ArrayIterator(java.lang.Object array)
          Construct an ArrayIterator that will iterate over the values in the specified array.
ArrayIterator(java.lang.Object array, int start)
          Construct an ArrayIterator that will iterate over the values in the specified array.
ArrayIterator(java.lang.Object array, int start, int end)
          Construct an ArrayIterator that will iterate over the values in the specified array.
 
Method Summary
 java.lang.Object getArray()
          Retrieves the array that this iterator is iterating over.
 boolean hasNext()
          Returns true if there are more elements to return from the array.
 java.lang.Object next()
          Returns the next element in the array.
 void remove()
          Throws UnsupportedOperationException.
 void setArray(java.lang.Object array)
          Changes the array that the ArrayIterator should iterate over.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

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(java.lang.Object array)
Construct an ArrayIterator that will iterate over the values in the specified array.

Parameters:
array - the array to iterate over.
Throws:
java.lang.IllegalArgumentException - if array is not an array.
java.lang.NullPointerException - if array is null

ArrayIterator

public ArrayIterator(java.lang.Object array,
                     int start)
Construct an ArrayIterator that will iterate over the values in the specified array.

Parameters:
array - the array to iterate over.
start - the index to start iterating at.
Throws:
java.lang.IllegalArgumentException - if array is not an array.
java.lang.NullPointerException - if array is null

ArrayIterator

public ArrayIterator(java.lang.Object array,
                     int start,
                     int end)
Construct an ArrayIterator that will iterate over the values in the specified array.

Parameters:
array - the array to iterate over.
start - the index to start iterating at.
end - the index to finish iterating at.
Throws:
java.lang.IllegalArgumentException - if array is not an array.
java.lang.NullPointerException - if array is null
Method Detail

hasNext

public boolean hasNext()
Returns true if there are more elements to return from the array.

Specified by:
hasNext in interface java.util.Iterator
Returns:
true if there is a next element to return

next

public java.lang.Object next()
Returns the next element in the array.

Specified by:
next in interface java.util.Iterator
Returns:
the next element in the array
Throws:
java.util.NoSuchElementException - if all the elements in the array have already been returned

remove

public void remove()
Throws UnsupportedOperationException.

Specified by:
remove in interface java.util.Iterator
Throws:
java.lang.UnsupportedOperationException - always

getArray

public java.lang.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.

setArray

public void setArray(java.lang.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:
java.lang.IllegalArgumentException - if array is not an array.
java.lang.NullPointerException - if array is null


Copyright © 2001-2004 The Apache Software Foundation. All Rights Reserved.