org.apache.commons.collections.iterators

Class ArrayIterator

Implemented Interfaces:
Iterator
Known Direct Subclasses:
ArrayIterator

public class ArrayIterator
extends java.lang.Object
implements Iterator

Implements an Iterator over an array of objects.
Version:
$Revision: 1.1.2.1 $
Authors:
James Strachan
Mauricio S. Moura
Michael A. Smith
Since:
1.0

Constructor Summary

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

Method Summary

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.
Object
next()
Returns the next element in the array.
void
remove()
Throws UnsupportedOperationException.
void
setArray(Object array)
Changes the array that the ArrayIterator should iterate over.

Constructor Details

ArrayIterator

public ArrayIterator()

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.

ArrayIterator

public ArrayIterator(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.

ArrayIterator

public ArrayIterator(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.

Method Details

getArray

public Object getArray()
Retrieves the array that this iterator is iterating over.

hasNext

public boolean hasNext()
Returns true if there are more elements to return from the array.
Returns:
true if there is a next element to return

next

public Object next()
Returns the next element in the array.
Returns:
the next element in the array

remove

public void remove()
Throws UnsupportedOperationException.

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.

Copyright © 2001-2004 Apache Software Foundation. Documenation generated ${TODAY}.