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

com.tinkerpop.pipes.util.iterators.ExpandableMultiIterator Maven / Gradle / Ivy

Go to download

Pipes is a dataflow framework written in Java that enables the splitting, merging, filtering, and transformation of data from input to output. Computations are expressed using a combinator model and are evaluated in a memory-efficient, lazy fashion.

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

import com.tinkerpop.pipes.util.FastNoSuchElementException;

import java.util.Arrays;
import java.util.Iterator;
import java.util.List;

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

    private final ExpandableIterator> iterators = new ExpandableIterator>();
    private Iterator currentIterator = null;

    public ExpandableMultiIterator(final Iterator... iterators) {
        this(Arrays.asList(iterators));
    }

    public ExpandableMultiIterator(final List> iterators) {
        for (Iterator itty : iterators) {
            this.iterators.add(itty);
        }
    }

    public ExpandableMultiIterator() {

    }

    public void remove() {
        throw new UnsupportedOperationException();
    }

    public void addIterator(final Iterator itty) {
        this.iterators.add(itty);
    }

    public T next() {
        while (true) {
            if (null != this.currentIterator && this.currentIterator.hasNext()) {
                return this.currentIterator.next();
            } else {
                if (this.iterators.hasNext()) {
                    this.currentIterator = this.iterators.next();
                } else {
                    throw FastNoSuchElementException.instance();
                }
            }
        }
    }

    public boolean hasNext() {
        while (true) {
            if (null != this.currentIterator && this.currentIterator.hasNext()) {
                return true;
            } else if (this.iterators.hasNext()) {
                this.currentIterator = iterators.next();
            } else {
                return false;
            }
        }
    }


}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy