org.deegree.commons.utils
Interface CloseableIterator<T>

Type Parameters:
T - type of the iterated objects
All Superinterfaces:
Iterator<T>
All Known Implementing Classes:
ResultSetIterator

public interface CloseableIterator<T>
extends Iterator<T>

An Iterator that can (and must) be closed after it's not needed anymore.

This interface is used to implement Iterators that generate their elements lazily, e.g. from SQL ResultSets. In order to be able to release the underlying resources (such as JDBC Connections), an explicit notification is necessary which is provided by the close() method.

Version:
$Revision: 20580 $, $Date: 2009-11-04 18:47:14 +0100 (Wed, 04 Nov 2009) $
Author:
Markus Schneider, last edited by: $Author: mschneider $

Method Summary
 void close()
          Frees all underlying resources, no other method calls are permitted after calling this.
 Collection<T> getAsCollectionAndClose(Collection<T> collection)
          Copies the elements into the given Collection and closes the iterator.
 List<T> getAsListAndClose()
          Returns the elements as an easy accessible List and closes the iterator.
 
Methods inherited from interface java.util.Iterator
hasNext, next, remove
 

Method Detail

close

void close()
Frees all underlying resources, no other method calls are permitted after calling this.


getAsListAndClose

List<T> getAsListAndClose()
Returns the elements as an easy accessible List and closes the iterator.

NOTE: This should only be used for small numbers of elements.

Returns:
list that contains all elements, never null

getAsCollectionAndClose

Collection<T> getAsCollectionAndClose(Collection<T> collection)
Copies the elements into the given Collection and closes the iterator.

Parameters:
collection - collection where the elements are copied, must not be null
Returns:
collection that contains all elements, same instance as the parameter


Copyright © 2011. All Rights Reserved.