org.geotoolkit.util.collection
Class DeferringIterator<E>

Object
  extended by DeferringIterator<E>
Type Parameters:
E - The type of elements to be returned by the iterator.
All Implemented Interfaces:
Iterator<E>

@Decorator(value=java.util.Iterator.class)
public abstract class DeferringIterator<E>
extends Object
implements Iterator<E>

An iterator deferring to the iteration end any object which comply to some criterion. This class needs:

When the next() method is invoked, DeferringIterator first delegates to the next() method of the wrapped iterator, then gives the obtained element to the isDeferred method. If isDeferred returns true, then the element is returned immediately. Otherwise the element is enqueued and will be returned in queue insertion order only after all non-deferred elements have been returned by this iterator.

Since:
3.20
Version:
3.20
Author:
Martin Desruisseaux (Geomatys)
Module:
utility/geotk-utility (download)    View source code for this class

Constructor Summary
protected DeferringIterator(Iterator<E> iterator)
          Creates a new deferring iterator.
 
Method Summary
 boolean hasNext()
          Returns true if the iteration has more elements.
protected abstract  boolean isDeferred(E element)
          Returns true if the given element should be deferred at the end of the iteration.
 E next()
          Returns the next element in the iteration.
 void remove()
          Removes the last element returned by the iterator.
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DeferringIterator

protected DeferringIterator(Iterator<E> iterator)
Creates a new deferring iterator.

Parameters:
iterator - The iterator to wrap.
Method Detail

isDeferred

protected abstract boolean isDeferred(E element)
Returns true if the given element should be deferred at the end of the iteration. This method is invoked by the next() method for all objects returned by the wrapped iterator. If this method returns true, then the given element will be returned immediately by the next() method. Otherwise the element is enqueued and will be returned only after all non-deferred elements have been returned.

Parameters:
element - The object to test. May be null if the wrapped iterator can returns null elements.
Returns:
true if the given object should be deferred at the end of the iteration.

hasNext

public boolean hasNext()
Returns true if the iteration has more elements.

Specified by:
hasNext in interface Iterator<E>

next

public E next()
Returns the next element in the iteration.

Specified by:
next in interface Iterator<E>

remove

public void remove()
            throws UnsupportedOperationException
Removes the last element returned by the iterator. This method is supported only when the following conditions hold:

Specified by:
remove in interface Iterator<E>
Throws:
UnsupportedOperationException - If the iterator is iterating over deferred elements, or if the wrapped iterator does not support this operation.


Copyright © 2009-2012 Geotoolkit.org. All Rights Reserved.