net.sf.mmm.util.collection.base
Class FilteredIterator<E>

java.lang.Object
  extended by net.sf.mmm.util.collection.base.AbstractIterator<E>
      extended by net.sf.mmm.util.collection.base.FilteredIterator<E>
Type Parameters:
E - is the generic type of the iterated elements.
All Implemented Interfaces:
Iterator<E>

public class FilteredIterator<E>
extends AbstractIterator<E>

This is an implementation of an Iterator that adapts another Iterator but only iterates the elements that are accepted by a given Filter.
ATTENTION:
According to the design of the Iterator interface, it is NOT possible to implement the AbstractIterator.remove() method properly here. The method AbstractIterator.hasNext() has to step forward in the adapted Iterator and a call of AbstractIterator.remove() would cause unintended and unpredictable results after AbstractIterator.hasNext() has been called. To prevent damage AbstractIterator.remove() will always throw an UnsupportedOperationException.

Since:
2.0.0
Author:
Joerg Hohwiller (hohwille at users.sourceforge.net)

Field Summary
private  Iterator<E> delegate
          The actual iterator instance to adapt.
private  Filter<E> filter
           
 
Constructor Summary
FilteredIterator(Iterator<E> delegate, Filter<E> filter)
          The constructor.
 
Method Summary
protected  E findNext()
          This method tries to find the next element.
 
Methods inherited from class net.sf.mmm.util.collection.base.AbstractIterator
findFirst, hasNext, next, remove
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

delegate

private final Iterator<E> delegate
The actual iterator instance to adapt.


filter

private final Filter<E> filter
See Also:
findNext()
Constructor Detail

FilteredIterator

public FilteredIterator(Iterator<E> delegate,
                        Filter<E> filter)
The constructor.

Parameters:
delegate - is the Iterator to adapt.
filter - is the Filter that filters the iterated elements.
Method Detail

findNext

protected E findNext()
This method tries to find the next element.

Specified by:
findNext in class AbstractIterator<E>
Returns:
the next element or null if done.


Copyright © 2001-2010 mmm-Team. All Rights Reserved.