com.tinkerpop.pipes.util.iterators.SingleExpandableIterator 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.Iterator;
/**
* SingleExpandableIterator can have an object added to it. However, it only stores one object.
* If the previous object hasn't be next()'d before adding a new one, the previous object is overwritten.
*
* @author Marko A. Rodriguez (http://markorodriguez.com)
*/
public class SingleExpandableIterator implements Iterator {
public T t;
private boolean alive;
public SingleExpandableIterator(final T t) {
this.t = t;
this.alive = true;
}
public SingleExpandableIterator() {
this.alive = false;
}
public void remove() {
throw new UnsupportedOperationException();
}
public boolean hasNext() {
return this.alive;
}
public void add(final T t) {
this.t = t;
this.alive = true;
}
public T next() {
if (this.alive) {
this.alive = false;
return this.t;
} else {
throw FastNoSuchElementException.instance();
}
}
}