org.progeeks.util
Class CompositeIterator

java.lang.Object
  extended by org.progeeks.util.CompositeIterator
All Implemented Interfaces:
java.util.Iterator, CloseableIterator

public class CompositeIterator
extends java.lang.Object
implements CloseableIterator

Combines several iterators into one iterator view. How the next iterator is retrieved is customizable by subclasses. The default implementation assumes an iterator of iterators.

Version:
$Revision: 1.3 $
Author:
Paul Speed

Constructor Summary
CompositeIterator(java.util.Iterator mainIterator)
           
 
Method Summary
 void close()
          If the current iterator is a CloseableIterator then it is closed.
protected  java.util.Iterator getCurrentIterator()
           
protected  java.util.Iterator getIterator(java.lang.Object item)
          Returns the iterator for the specified item as retrieved from the main iterator.
protected  java.util.Iterator getLastIterator()
           
 boolean hasNext()
           
protected  boolean isRemoved()
          Returns true if an entry has been removed but next() hasn't been called yet.
 java.lang.Object next()
           
protected  void refresh()
          Makes sure the current iterator is valid and retrives the next one as necessary.
 void remove()
           
protected  java.util.Iterator setLastIterator(java.util.Iterator last)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CompositeIterator

public CompositeIterator(java.util.Iterator mainIterator)
Method Detail

close

public void close()
If the current iterator is a CloseableIterator then it is closed. It also closes the main iterator if it is closeable.

Specified by:
close in interface CloseableIterator

getCurrentIterator

protected java.util.Iterator getCurrentIterator()

getLastIterator

protected java.util.Iterator getLastIterator()

setLastIterator

protected java.util.Iterator setLastIterator(java.util.Iterator last)

isRemoved

protected boolean isRemoved()
Returns true if an entry has been removed but next() hasn't been called yet.


getIterator

protected java.util.Iterator getIterator(java.lang.Object item)
Returns the iterator for the specified item as retrieved from the main iterator. The default implementation casts it to Iterator and returns it. A return of null will cause the composite iterator to try the next entry.


refresh

protected void refresh()
Makes sure the current iterator is valid and retrives the next one as necessary.


hasNext

public boolean hasNext()
Specified by:
hasNext in interface java.util.Iterator

next

public java.lang.Object next()
Specified by:
next in interface java.util.Iterator

remove

public void remove()
Specified by:
remove in interface java.util.Iterator


Copyright © 2002-2003 Paul Speed. All Rights Reserved.