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

com.tinkerpop.pipes.branch.ExhaustMergePipe 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.branch;

import java.util.List;

import com.tinkerpop.pipes.Pipe;
import com.tinkerpop.pipes.util.AbstractMetaPipe;
import com.tinkerpop.pipes.util.FastNoSuchElementException;
import com.tinkerpop.pipes.util.MetaPipe;
import com.tinkerpop.pipes.util.PipeHelper;

/**
 * ExhaustiveMergePipe will drain its first internal pipe, then its second, so on until all internal pipes are drained.
 *
 * @author Marko A. Rodriguez (http://markorodriguez.com)
 */
public class ExhaustMergePipe extends AbstractMetaPipe implements MetaPipe {

    private final List pipes;
    int current = 0;
    final int total;

    public ExhaustMergePipe(final List pipes) {
        this.pipes = pipes;
        this.total = pipes.size();
    }

    public S processNextStart() {
        while (true) {
            final Pipe pipe = this.pipes.get(this.current);
            if (pipe.hasNext()) {
                return (S) pipe.next();
            } else {
                this.current = (this.current + 1) % this.total;
                if (this.current == 0) {
                    throw FastNoSuchElementException.instance();
                }
            }
        }
    }

    public List getCurrentPath() {
        if (this.pathEnabled)
            return this.pipes.get(this.current).getCurrentPath();
        else
            throw new RuntimeException(Pipe.NO_PATH_MESSAGE);
    }

    public List getPipes() {
        return this.pipes;
    }

    public String toString() {
        return PipeHelper.makePipeString(this, this.pipes);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy