All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.tinkerpop.blueprints.util.WrappingCloseableIterable Maven / Gradle / Ivy

There is a newer version: 2.6.0
Show newest version
package com.tinkerpop.blueprints.util;

import com.tinkerpop.blueprints.CloseableIterable;

import java.util.Iterator;

/**
 * @author Marko A. Rodriguez (http://markorodriguez.com)
 */
public class WrappingCloseableIterable implements CloseableIterable {

    private final Iterable iterable;

    public WrappingCloseableIterable(final Iterable iterable) {
        this.iterable = iterable;
    }

    public Iterator iterator() {
        return new Iterator() {
            private final Iterator itty = iterable.iterator();

            public void remove() {
                this.itty.remove();
            }

            public T next() {
                return this.itty.next();
            }

            public boolean hasNext() {
                return this.itty.hasNext();
            }
        };
    }

    public void close() {
        if (this.iterable instanceof CloseableIterable) {
            ((CloseableIterable) this.iterable).close();
        }
    }

    public String toString() {
        return this.iterable.toString();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy