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

com.github.thorbenkuck.network.pipeline.Pipeline Maven / Gradle / Ivy

There is a newer version: 0.4.0
Show newest version
package com.github.thorbenkuck.network.pipeline;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.function.Consumer;
import java.util.function.Function;

public class Pipeline {

	private final List> branches = new LinkedList<>();

	public  Stage add(Function function) {
		Branch branch = new Branch<>();
		branches.add(branch);
		return branch.add(function);
	}

	public Stage add(Consumer consumer) {
		Branch branch = new Branch<>();
		branches.add(branch);
		return branch.add(consumer);
	}

	public Stage add(Runnable runnable) {
		Branch branch = new Branch<>();
		branches.add(branch);
		return branch.add(runnable);
	}

	public void apply(T t) {
		List> branches = new ArrayList<>(this.branches);

		branches.forEach(branch -> branch.propagate(t));

		branches.clear();
	}

}