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

public Class ObjectArrayListIterator<E>

extends ObjectArrayIterator<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.util.NoSuchElementException, org.apache.commons.collections4.ResettableListIterator

Implements a java.util.ListIterator over an array of objects.

This iterator does not support add or remove, as the object array cannot be structurally modified. The set method is supported however.

The iterator implements a reset method, allowing the reset of the iterator back to the start if required.

Since
3.0
See Also
org.apache.commons.collections4.iterators.ObjectArrayIterator, 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.ObjectArrayIterator:
arrayendIndexindexstartIndex

Constructor Summary

AccessConstructor and Description
public
ObjectArrayListIterator(final E...
the array to iterate over
array
)

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

public
ObjectArrayListIterator(final E[]
the array to iterate over
array
,
final int
the index to start iterating at
start
)

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

public
ObjectArrayListIterator(final E[]
the array to iterate over
array
,
final int
the index to start iterating at
start
,
final int
the index (exclusive) to finish iterating at
end
)

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

Method Summary

Modifier and TypeMethod and Description
public void
add(final E
the object to add
obj
)

Implements java.util.ListIterator.add.

This iterator does not support modification of its backing array's size, 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.ObjectArrayIterator.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 E
the object to set into the array
obj
)

Implements java.util.ListIterator.set.

Sets the element under the cursor.
Inherited from org.apache.commons.collections4.iterators.ObjectArrayIterator:
getArraygetEndIndexgetStartIndexhasNextremove

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

ObjectArrayListIteratorback to summary
public ObjectArrayListIterator(final E... array)

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

Parameters
array:E[]

the array to iterate over

Exceptions
NullPointerException:
if array is null
ObjectArrayListIteratorback to summary
public ObjectArrayListIterator(final E[] array, final int start)

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

Parameters
array:E[]

the array to iterate over

start:int

the index to start iterating at

Exceptions
NullPointerException:
if array is null
IndexOutOfBoundsException:
if the start index is out of bounds
ObjectArrayListIteratorback to summary
public ObjectArrayListIterator(final E[] array, final int start, final int end)

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

Parameters
array:E[]

the array to iterate over

start:int

the index to start iterating at

end:int

the index (exclusive) to finish iterating at

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

Method Detail

addback to summary
public void add(final E obj)

Implements java.util.ListIterator.add.

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

Parameters
obj:E

the object to add

Annotations
@Override
Exceptions
UnsupportedOperationException:
always thrown.
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.ObjectArrayIterator.next.

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

Gets the next element from the array.

Returns:E

the next element

Annotations
@Override
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
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.ObjectArrayIterator.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 E obj)

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
obj:E

the object to set into the array

Annotations
@Override
Exceptions
IllegalStateException:
if next() has not yet been called.
ClassCastException:
if the object type is unsuitable for the array