Example usage for org.apache.commons.collections.iterators CollatingIterator getIterators

List of usage examples for org.apache.commons.collections.iterators CollatingIterator getIterators

Introduction

In this page you can find the example usage for org.apache.commons.collections.iterators CollatingIterator getIterators.

Prototype

public List getIterators() 

Source Link

Document

Gets the list of Iterators (unmodifiable).

Usage

From source file:org.openanzo.jdbc.utils.IteratorUtils.java

/**
 * Makes a best effort to close any closable iterator. Can close iterators nested in IteratorChain, TransformIterator, FilterIterator and CollatingIterator
 * instances./*ww  w.  j  av  a 2s  .  com*/
 * 
 * @param iterator
 *            The iterator to close.
 */
public static void close(Iterator<?> iterator) {
    if (iterator == null)
        return;
    // obvious case
    if (iterator instanceof ClosableIterator<?>) {
        ((ClosableIterator<?>) iterator).close();
    }
    // now check for all cases we know of where iterators can be nested..
    else if (iterator instanceof IteratorChain) {
        IteratorChain chain = (IteratorChain) iterator;

        @SuppressWarnings("unchecked")
        // marshal from apache commons collections
        List<Iterator<?>> iterators = chain.getIterators();

        for (Iterator<?> iteratorElement : iterators) {
            close(iteratorElement);
        }
    } else if (iterator instanceof TransformIterator) {
        TransformIterator trans = (TransformIterator) iterator;
        close(trans.getIterator());
    } else if (iterator instanceof FilterIterator) {
        FilterIterator filter = (FilterIterator) iterator;
        close(filter.getIterator());
    } else if (iterator instanceof CollatingIterator) {
        CollatingIterator iter = (CollatingIterator) iterator;

        @SuppressWarnings("unchecked")
        // marshal from apache commons collections
        List<Iterator<?>> iterators = iter.getIterators();

        for (Iterator<?> iteratorElement : iterators) {
            close(iteratorElement);
        }
    }
}