Package diva.util
Class NullArrayIterator
- java.lang.Object
-
- diva.util.IteratorAdapter
-
- diva.util.NullArrayIterator
-
- All Implemented Interfaces:
java.util.Iterator
- Direct Known Subclasses:
FilteredArrayIterator
public class NullArrayIterator extends IteratorAdapter
An iterator over a given array which may contain nulls. Any element of the array that is null is not returned, but is skipped over. A null value (of the whole array) is treated as an empty array. This class can be subclassed to implement the remove() method. The method getLastIndex() return the index of the previously returned element.- Version:
- $Id$
- Author:
- John Reekie
-
-
Constructor Summary
Constructors Constructor Description NullArrayIterator(java.lang.Object[] array)
Construct an iterator over the given arrayNullArrayIterator(java.lang.Object[] array, int length)
Construct an iterator over the given array, where the effective array length is given by the length argument (and must be smaller than the real length of the array).
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
advance()
Advance the next index to the next non-null element.protected int
getLastIndex()
Return the index of the element last returned.boolean
hasNext()
Return true if there are more non-null elements in the array.java.lang.Object
next()
Return the next non-null element in the array.-
Methods inherited from class diva.util.IteratorAdapter
remove
-
-
-
-
Constructor Detail
-
NullArrayIterator
public NullArrayIterator(java.lang.Object[] array)
Construct an iterator over the given array
-
NullArrayIterator
public NullArrayIterator(java.lang.Object[] array, int length)
Construct an iterator over the given array, where the effective array length is given by the length argument (and must be smaller than the real length of the array).
-
-
Method Detail
-
advance
protected void advance()
Advance the next index to the next non-null element. Set it to -1 if there are no more elements.
-
getLastIndex
protected int getLastIndex()
Return the index of the element last returned. This will be -1 if next() hasn't been called yet.
-
hasNext
public boolean hasNext()
Return true if there are more non-null elements in the array.- Specified by:
hasNext
in interfacejava.util.Iterator
- Overrides:
hasNext
in classIteratorAdapter
-
next
public java.lang.Object next()
Return the next non-null element in the array.- Specified by:
next
in interfacejava.util.Iterator
- Overrides:
next
in classIteratorAdapter
-
-