com.github.thorbenkuck.network.pipeline.Pipeline Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of easy-net Show documentation
Show all versions of easy-net Show documentation
An EventStream driven, simple to use Client/Server framework
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();
}
}