Package diva.util
Class FilteredArrayIterator
- java.lang.Object
-
- diva.util.IteratorAdapter
-
- diva.util.NullArrayIterator
-
- diva.util.FilteredArrayIterator
-
- All Implemented Interfaces:
java.util.Iterator
public abstract class FilteredArrayIterator extends NullArrayIterator
An iterator over an array, in which elements are filtered by some function. To make this efficient, the filter is specified by overriding the accept() method in a subclass rather than by passing an instance of the Filter class. 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 FilteredArrayIterator(java.lang.Object[] array)
Construct a filtered array iterator.FilteredArrayIterator(java.lang.Object[] array, int length)
Construct a filtered array iterator.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract boolean
accept(java.lang.Object o)
Test if the object is acceptable for return by the iterator.protected void
advance()
Advance the next index to the next non-null element.-
Methods inherited from class diva.util.NullArrayIterator
getLastIndex, hasNext, next
-
Methods inherited from class diva.util.IteratorAdapter
remove
-
-
-
-
Constructor Detail
-
FilteredArrayIterator
public FilteredArrayIterator(java.lang.Object[] array)
Construct a filtered array iterator.- Parameters:
array
- The array
-
FilteredArrayIterator
public FilteredArrayIterator(java.lang.Object[] array, int length)
Construct a filtered array iterator.- Parameters:
array
- The arraylength
- The length
-
-
Method Detail
-
accept
public abstract boolean accept(java.lang.Object o)
Test if the object is acceptable for return by the iterator.- Parameters:
o
- The object to be tested- Returns:
- True if the object is acceptable
-
advance
protected void advance()
Advance the next index to the next non-null element. Set it to -1 if there are no more elements.- Overrides:
advance
in classNullArrayIterator
-
-