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

com.tinkerpop.pipes.util.iterators.SingleExpandableIterator 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.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();
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy