Top Description Fields Constructors Methods
org.apache.commons.collections4.iterators

public Class ArrayListIterator<E>

extends ArrayIterator<E>
implements ResettableListIterator<E>
Class Inheritance
All Implemented Interfaces
org.apache.commons.collections4.ResettableListIterator, org.apache.commons.collections4.OrderedIterator, java.util.Iterator, org.apache.commons.collections4.ResettableIterator, java.util.ListIterator
Imports
java.lang.reflect.Array, java.util.NoSuchElementException, org.apache.commons.collections4.ResettableListIterator

Implements a java.util.ListIterator over an array.

The array can be either an array of object or of primitives. If you know that you have an object array, the ObjectArrayListIterator class is a better choice, as it will perform better.

This iterator does not support add(Object) or remove(), as the array cannot be changed in size. The set(Object) method is supported however.

Since
3.0
See Also
org.apache.commons.collections4.iterators.ArrayIterator, java.util.Iterator, java.util.ListIterator

Field Summary

Modifier and TypeField and Description
private int
lastItemIndex

Holds the index of the last item returned by a call to next() or previous().

Inherited from org.apache.commons.collections4.iterators.ArrayIterator:
arrayendIndexindexstartIndex

Constructor Summary

AccessConstructor and Description
public
ArrayListIterator(final Object
the array to iterate over
array
)

Constructs an ArrayListIterator that will iterate over the values in the specified array.

public
ArrayListIterator(final Object
the array to iterate over
array
,
final int
the index to start iterating at
startIndex
)

Constructs an ArrayListIterator that will iterate over the values in the specified array from a specific start index.

public
ArrayListIterator(final Object
the array to iterate over
array
,
final int
the index to start iterating at
startIndex
,
final int
the index (exclusive) to finish iterating at
endIndex
)

Construct an ArrayListIterator that will iterate over a range of values in the specified array.

Method Summary

Modifier and TypeMethod and Description
public void
add(final Object
the element to add
o
)

Implements java.util.ListIterator.add.

This iterator does not support modification of its backing collection, and so will always throw an UnsupportedOperationException when this method is invoked.
public boolean

Returns:

true if there is a previous element to return
hasPrevious
()

Implements java.util.ListIterator.hasPrevious, org.apache.commons.collections4.OrderedIterator.hasPrevious.

Returns true if there are previous elements to return from the array.
public E

Returns:

the next element
next
()

Overrides org.apache.commons.collections4.iterators.ArrayIterator.next.

Implements java.util.ListIterator.next, java.util.Iterator.next.

Gets the next element from the array.
public int

Returns:

the index of the item to be retrieved next
nextIndex
()

Implements java.util.ListIterator.nextIndex.

Gets the next index to be retrieved.
public E

Returns:

the previous element
previous
()

Implements java.util.ListIterator.previous, org.apache.commons.collections4.OrderedIterator.previous.

Gets the previous element from the array.
public int

Returns:

the index of the item to be retrieved next
previousIndex
()

Implements java.util.ListIterator.previousIndex.

Gets the index of the item to be retrieved if previous() is called.
public void
public void
set(final Object
the element to set
o
)

Implements java.util.ListIterator.set.

Sets the element under the cursor.
Inherited from org.apache.commons.collections4.iterators.ArrayIterator:
checkBoundgetArraygetEndIndexgetStartIndexhasNextremove

Field Detail

lastItemIndexback to summary
private int lastItemIndex

Holds the index of the last item returned by a call to next() or previous(). This is set to -1 if neither method has yet been invoked. lastItemIndex is used to to implement the set method.

Constructor Detail

ArrayListIteratorback to summary
public ArrayListIterator(final Object array)

Constructs an ArrayListIterator that will iterate over the values in the specified array.

Parameters
array:Object

the array to iterate over

Exceptions
IllegalArgumentException:
if array is not an array.
NullPointerException:
if array is null
ArrayListIteratorback to summary
public ArrayListIterator(final Object array, final int startIndex)

Constructs an ArrayListIterator that will iterate over the values in the specified array from a specific start index.

Parameters
array:Object

the array to iterate over

startIndex:int

the index to start iterating at

Exceptions
IllegalArgumentException:
if array is not an array.
NullPointerException:
if array is null
IndexOutOfBoundsException:
if the start index is out of bounds
ArrayListIteratorback to summary
public ArrayListIterator(final Object array, final int startIndex, final int endIndex)

Construct an ArrayListIterator that will iterate over a range of values in the specified array.

Parameters
array:Object

the array to iterate over

startIndex:int

the index to start iterating at

endIndex:int

the index (exclusive) to finish iterating at

Exceptions
IllegalArgumentException:
  • if array is not an array.
  • if end index is before the start
IndexOutOfBoundsException:
if the start or end index is out of bounds
NullPointerException:
if array is null

Method Detail

addback to summary
public void add(final Object o)

Implements java.util.ListIterator.add.

This iterator does not support modification of its backing collection, and so will always throw an UnsupportedOperationException when this method is invoked.

Parameters
o:Object

the element to add

Annotations
@Override
Exceptions
UnsupportedOperationException:
always thrown.
See Also
java.util.ListIterator#set
hasPreviousback to summary
public boolean hasPrevious()

Implements java.util.ListIterator.hasPrevious, org.apache.commons.collections4.OrderedIterator.hasPrevious.

Returns true if there are previous elements to return from the array.

Returns:boolean

true if there is a previous element to return

Annotations
@Override
nextback to summary
public E next()

Overrides org.apache.commons.collections4.iterators.ArrayIterator.next.

Implements java.util.ListIterator.next, java.util.Iterator.next.

Gets the next element from the array.

Returns:E

the next element

Annotations
@Override
@SuppressWarnings:unchecked
Exceptions
NoSuchElementException:
if there is no next element
nextIndexback to summary
public int nextIndex()

Implements java.util.ListIterator.nextIndex.

Gets the next index to be retrieved.

Returns:int

the index of the item to be retrieved next

Annotations
@Override
previousback to summary
public E previous()

Implements java.util.ListIterator.previous, org.apache.commons.collections4.OrderedIterator.previous.

Gets the previous element from the array.

Returns:E

the previous element

Annotations
@Override
@SuppressWarnings:unchecked
Exceptions
NoSuchElementException:
if there is no previous element
previousIndexback to summary
public int previousIndex()

Implements java.util.ListIterator.previousIndex.

Gets the index of the item to be retrieved if previous() is called.

Returns:int

the index of the item to be retrieved next

Annotations
@Override
resetback to summary
public void reset()

Overrides org.apache.commons.collections4.iterators.ArrayIterator.reset.

Implements org.apache.commons.collections4.ResettableIterator.reset.

Resets the iterator back to the start index.

Annotations
@Override
setback to summary
public void set(final Object o)

Implements java.util.ListIterator.set.

Sets the element under the cursor.

This method sets the element that was returned by the last call to next() of previous().

Note

java.util.ListIterator implementations that support add() and remove() only allow set() to be called once per call to next() or previous (see the java.util.ListIterator javadoc for more details). Since this implementation does not support add() or remove(), set() may be called as often as desired.

Parameters
o:Object

the element to set

Annotations
@Override
Exceptions
IllegalStateException:
if next() or previous() has not been called before set(Object)
See Also
java.util.ListIterator#set