JTemporal Home
Tutorial

net.sf.jtemporal.util
Class SimpleCloseableIterator

java.lang.Object
  extended by net.sf.jtemporal.util.SimpleCloseableIterator
All Implemented Interfaces:
java.util.Iterator, CloseableIterator

public class SimpleCloseableIterator
extends java.lang.Object
implements CloseableIterator

Decorates an existing Iterator to make it closeable.
Can also be used just as an iterator proxy to be subclassed and decorated.
Keeps track of what object has been fetched the lat time the method next() has been called.
This class is designed to be subclassed to add more functionality.
Not thread safe.

Version:
$Id: SimpleCloseableIterator.java,v 1.5 2007/05/27 10:39:16 tabeck Exp $

Constructor Summary
SimpleCloseableIterator(java.util.Iterator model)
          If the passed iterator is instanceof CloseableIterator then it will closed when this iterator is closed.
 
Method Summary
 void close()
          Closes the iterator.
protected  java.lang.Object getLastFetched()
          Returns the last object that has been retrieved using the next() method.
 boolean hasNext()
           As soon the method returns false the cursor is automatically closed.
 boolean isOpen()
          Checks whether the iterator is open, or already closed.
 java.lang.Object next()
           
 void remove()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SimpleCloseableIterator

public SimpleCloseableIterator(java.util.Iterator model)
If the passed iterator is instanceof CloseableIterator then it will closed when this iterator is closed.

Parameters:
model - the model iterator
Method Detail

getLastFetched

protected java.lang.Object getLastFetched()
Returns the last object that has been retrieved using the next() method.

Returns:
the last object that has been retrieved using the next() method.
Throws:
java.lang.IllegalStateException - if next() has not been called yet.

close

public void close()
Description copied from interface: CloseableIterator
Closes the iterator.
Once this method has been called, the iterator behaves as it had reached the end of the list, and does not return more element.
This call releases all the linked resources (for example a database cursor).
It is recommended to call this method when you do not want to iterate until the last element.
If the cursor is already closed, this method just returns, with no error.

Specified by:
close in interface CloseableIterator

remove

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

hasNext

public boolean hasNext()
Description copied from interface: CloseableIterator
As soon the method returns false the cursor is automatically closed.
This implies that if you want to remove the last element you must call Iterator.remove() before calling this method again.

Specified by:
hasNext in interface java.util.Iterator
Specified by:
hasNext in interface CloseableIterator
See Also:
Iterator.hasNext()

next

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

isOpen

public boolean isOpen()
Description copied from interface: CloseableIterator
Checks whether the iterator is open, or already closed.

Specified by:
isOpen in interface CloseableIterator
Returns:
true if the cursor is open.

JTemporal Home
Tutorial