org.openstreetmap.osmosis.core.store
Class StoreReleasingIterator<DataType>

java.lang.Object
  extended by org.openstreetmap.osmosis.core.store.StoreReleasingIterator<DataType>
Type Parameters:
DataType - The type of data to be returned by the iterator.
All Implemented Interfaces:
java.util.Iterator<DataType>, Releasable, ReleasableIterator<DataType>

public class StoreReleasingIterator<DataType>
extends java.lang.Object
implements ReleasableIterator<DataType>

This class allows an underlying store to be released along with the iterator accessing it. As such it acts as an iterator delegating all calls to a provided iterator, but during release it also releases the data store.

Author:
Brett Henderson

Constructor Summary
StoreReleasingIterator(ReleasableIterator<DataType> iterator, Releasable store)
          Creates a new instance.
 
Method Summary
 boolean hasNext()
          
 DataType next()
          
 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

StoreReleasingIterator

public StoreReleasingIterator(ReleasableIterator<DataType> iterator,
                              Releasable store)
Creates a new instance.

Parameters:
iterator - The underlying iterator to read from.
store - The store to be released after use.
Method Detail

hasNext

public boolean hasNext()

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

next

public DataType next()

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

remove

public void remove()

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

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