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

java.lang.Object
  extended by net.sf.mmm.util.collection.base.AbstractIterator<E>
Type Parameters:
E - is the generic type of the iterated elements.
All Implemented Interfaces:
Iterator<E>
Direct Known Subclasses:
FilteredIterator, NodeIterator, PojoFieldIntrospectorImpl.PojoFieldIterator, PojoMethodIntrospectorImpl.PojoMethodIterator, StringTokenizer

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

This is an abstract base implementation of the Iterator interface. It allows to implement an read-only lookahead Iterator easier:
Simply extend this class and implement findNext(). From your constructor or initializer call findFirst().
ATTENTION:
Do NOT forget to call findFirst() from your constructor or your iterator will always be empty.

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

Field Summary
private  E next
          the next item or null if done
 
Constructor Summary
AbstractIterator()
          The constructor.
 
Method Summary
protected  void findFirst()
          This method has to be called from the constructor of the implementing class.
protected abstract  E findNext()
          This method tries to find the next element.
 boolean hasNext()
          
 E next()
          
 void remove()
          This method will always throw an exception.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

next

private E next
the next item or null if done

Constructor Detail

AbstractIterator

public AbstractIterator()
The constructor.

See Also:
findFirst()
Method Detail

findFirst

protected final void findFirst()
This method has to be called from the constructor of the implementing class.


findNext

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

Returns:
the next element or null if done.

hasNext

public final boolean hasNext()

Specified by:
hasNext in interface Iterator<E>

next

public final E next()

Specified by:
next in interface Iterator<E>

remove

public final void remove()
                  throws UnsupportedOperationException
This method will always throw an exception.

Specified by:
remove in interface Iterator<E>
Throws:
UnsupportedOperationException - whenever this method is called.
See Also:
Iterator.remove()


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