de.unidu.is.util
Class AcceptFilterIterator

java.lang.Object
  extended byde.unidu.is.util.AcceptFilterIterator
All Implemented Interfaces:
AcceptFilter, java.util.Iterator

public abstract class AcceptFilterIterator
extends java.lang.Object
implements java.util.Iterator, AcceptFilter

A iterator that filters another iterator. The method accept(Object) is called for every item in the another iterator to test if that object should be returned by this filter iterator.

Since:
2001-04-23
Version:
$Revision: 1.5 $, $Date: 2005/02/21 17:29:29 $
Author:
Henrik Nottelmann

Field Summary
protected  boolean called
          Indicates if next() has ever been called.
protected  java.util.Iterator iterator
          The iterator to be filtered.
protected  java.lang.Object next
          The next object to be returned.
 
Constructor Summary
AcceptFilterIterator()
          Creates a new filter iterator which has to be initialised.
AcceptFilterIterator(java.util.Iterator iterator)
          Creates a new filter iterator.
 
Method Summary
abstract  boolean accept(java.lang.Object object)
          Returns true if the specified object should be returned by next().
protected  void calcNext()
          Calculates the next object to be returned.
 boolean hasNext()
          Returns true if this iterator has more elements.
 void init(java.util.Iterator iterator)
          Inits this iterator.
 java.lang.Object next()
          Returns the next object.
 void remove()
          Removing objects is unsupported!
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

iterator

protected java.util.Iterator iterator
The iterator to be filtered.


next

protected java.lang.Object next
The next object to be returned.


called

protected boolean called
Indicates if next() has ever been called. This is needed for initialisation outside the constructor (because that does not work!).

Constructor Detail

AcceptFilterIterator

public AcceptFilterIterator()
Creates a new filter iterator which has to be initialised.


AcceptFilterIterator

public AcceptFilterIterator(java.util.Iterator iterator)
Creates a new filter iterator.

Parameters:
iterator - iterator to be filtered
Method Detail

init

public void init(java.util.Iterator iterator)
Inits this iterator.

Parameters:
iterator - iterator to be filtered

hasNext

public boolean hasNext()
Returns true if this iterator has more elements.

Specified by:
hasNext in interface java.util.Iterator
Returns:
true if the iterator has more elements

next

public java.lang.Object next()
Returns the next object.

Specified by:
next in interface java.util.Iterator
Returns:
next object
Throws:
java.util.NoSuchElementException - if there is no object available

calcNext

protected void calcNext()
Calculates the next object to be returned.


accept

public abstract boolean accept(java.lang.Object object)
Returns true if the specified object should be returned by next(). This method has to be overridden!

Specified by:
accept in interface AcceptFilter
Parameters:
object - object to be testet
Returns:
true if the specified object should be returned by next()

remove

public void remove()
Removing objects is unsupported!

Specified by:
remove in interface java.util.Iterator