org.openstreetmap.osmosis.core.store
Class PeekableIterator<T>

java.lang.Object
  extended by org.openstreetmap.osmosis.core.store.PeekableIterator<T>
Type Parameters:
T - The type of entity to retrieved.
All Implemented Interfaces:
java.util.Iterator<T>, Releasable, ReleasableIterator<T>

public class PeekableIterator<T>
extends java.lang.Object
implements ReleasableIterator<T>

Wraps a releasable iterator and adds the ability to peek at the next value without moving to the next record.

Author:
Brett Henderson

Constructor Summary
PeekableIterator(ReleasableIterator<T> sourceIterator)
          Creates a new instance.
 
Method Summary
 boolean hasNext()
          
 T next()
          
 T peekNext()
          Returns the next available entity without advancing to the next record.
 void release()
          Performs resource cleanup tasks such as closing files, or database connections.
 void remove()
          
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PeekableIterator

public PeekableIterator(ReleasableIterator<T> sourceIterator)
Creates a new instance.

Parameters:
sourceIterator - The underlying iterator providing source data. This will be owned and released by this object.
Method Detail

hasNext

public boolean hasNext()

Specified by:
hasNext in interface java.util.Iterator<T>

peekNext

public T peekNext()
Returns the next available entity without advancing to the next record.

Returns:
The next available entity.

next

public T next()

Specified by:
next in interface java.util.Iterator<T>

release

public void release()
Performs resource cleanup tasks such as closing files, or database connections. This must be called after all processing is complete and may be called multiple times. Implementations must call release on any nested Releasable objects. It should be called within a finally block to ensure it is called in exception scenarios.

Specified by:
release in interface Releasable

remove

public void remove()

Specified by:
remove in interface java.util.Iterator<T>