ContactCenters
V. 0.9.9.

umontreal.iro.lecuyer.collections
Class FilteredIterator<E>

java.lang.Object
  extended by umontreal.iro.lecuyer.collections.FilteredIterator<E>
Type Parameters:
E - the type of the accepted objects.
All Implemented Interfaces:
Iterator<E>
Direct Known Subclasses:
FilteredListIterator, ObjectTypeIterator

public abstract class FilteredIterator<E>
extends Object
implements Iterator<E>

Represents an iterator traversing a restricted subset of the elements enumerated by another iterator. A filtered iterator encapsulates an ordinary iterator, and uses it to enumerate objects. However, this iterator only returns objects passing the test implemented in the user-defined filter(java.lang.Object) method. For example, this class could be used to iterate over objects of a certain subclass or having certain properties. Note that this iterator does not support the remove() operation.


Constructor Summary
FilteredIterator(Iterator<? super E> it)
          Constructs a new filtered iterator from the iterator it.
FilteredIterator(Iterator<? super E> it, int maxNumElements)
          Constructs a new filtered iterator from the iterator it, and returning at most maxNumElements elements.
 
Method Summary
abstract  boolean filter(Object o)
          Determines if the object o is returned by this iterator.
 Iterator<? super E> getInnerIterator()
          Returns the inner iterator used by this iterator.
 int getMaxNumElements()
          Returns the maximal number of elements that can be traversed by this iterator, or Integer.MAX_VALUE if the number of elements is not bounded.
 boolean hasNext()
           
 E next()
           
 void remove()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FilteredIterator

public FilteredIterator(Iterator<? super E> it)
Constructs a new filtered iterator from the iterator it.

Parameters:
it - the iterator being filtered.
Throws:
NullPointerException - if it is null.

FilteredIterator

public FilteredIterator(Iterator<? super E> it,
                        int maxNumElements)
Constructs a new filtered iterator from the iterator it, and returning at most maxNumElements elements.

Parameters:
it - the iterator being filtered.
maxNumElements - the maximal number of elements the iterator can return.
Throws:
NullPointerException - if it is null.
IllegalArgumentException - if maxNumElements is negative.
Method Detail

getInnerIterator

public Iterator<? super E> getInnerIterator()
Returns the inner iterator used by this iterator.

Returns:
the inner iterator.

getMaxNumElements

public int getMaxNumElements()
Returns the maximal number of elements that can be traversed by this iterator, or Integer.MAX_VALUE if the number of elements is not bounded. This does not affect the number of elements traversed by the inner iterator and passed to the filter(java.lang.Object) method.

Returns:
the maximal number of elements the iterator can return.

filter

public abstract boolean filter(Object o)
Determines if the object o is returned by this iterator. Returns true if the object is accepted, false otherwise. This iterator assumes that this method returns true for a particular object o only if o can be cast into an instance of E.

Parameters:
o - the tested object.
Returns:
the result of the test.

hasNext

public boolean hasNext()
Specified by:
hasNext in interface Iterator<E>

next

public E next()
Specified by:
next in interface Iterator<E>

remove

public void remove()
Specified by:
remove in interface Iterator<E>

ContactCenters
V. 0.9.9.

To submit a bug or ask questions, send an e-mail to Richard Simard.