com.tinkerpop.pipes.util.iterators.ExpandableMultiIterator Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of pipes Show documentation
Show all versions of pipes Show documentation
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.
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;
}
}
}
}