JTemporal Home
Tutorial

net.sf.jtemporal.util
Class IteratorFilter

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

public abstract class IteratorFilter
extends java.lang.Object
implements CloseableIterator

A proxy over an existing iterator, that filters some entries.
Not thread safe.

Version:
$Id: IteratorFilter.java,v 1.1 2005/06/05 21:49:30 tabeck Exp $

Constructor Summary
IteratorFilter(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.
 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()
          
As soon hasNext() has been called, this method cannot be used anymore.
protected abstract  boolean shows(java.lang.Object o)
          Tells whether an entry must be filtered or not.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

IteratorFilter

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

Parameters:
model - the iterator whose entries must be filtered
Method Detail

shows

protected abstract boolean shows(java.lang.Object o)
Tells whether an entry must be filtered or not.
It is allowed for the implementation of this method to call close(). In this case, the method will return normally, but the method hasNext() will stop looking further in the model iterator.

Parameters:
o - the object retrieved from the unterlying iterator that must be tested
Returns:
true if the object is be visible to the client of this iterator, false if the object is filtered out.

close

public void close()
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.
If the passed iterator is instanceof CloseableIterator then it will closed when this iterator is closed.

Specified by:
close in interface CloseableIterator

remove

public void remove()

As soon hasNext() has been called, this method cannot be used anymore.
This method can be called only just after next()

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