io.github.gaming32.pipeline.Pipelines Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of pipeline Show documentation
Show all versions of pipeline Show documentation
Library for performing fluent-style operations on Java objects.
It also provides a fluent format for creating generators.
The newest version!
package io.github.gaming32.pipeline;
import java.util.Iterator;
import java.util.concurrent.Callable;
import java.util.stream.Stream;
import io.github.gaming32.pipeline.calling.CallingPipeline;
import io.github.gaming32.pipeline.iterator.IteratorPipeline;
import io.github.gaming32.pipeline.iterator.iterators.ArrayIterator;
import io.github.gaming32.pipeline.unary.UnaryPipeline;
public final class Pipelines {
// Disable instantiation
private Pipelines() {
}
public static UnaryPipeline unary(T value) {
return UnaryPipeline.of(value);
}
public static CallingPipeline call(Callable func) {
return CallingPipeline.of(func);
}
public static IteratorPipeline iterator(Iterator iterator) {
return IteratorPipeline.of(iterator);
}
public static IteratorPipeline iterator(Iterable iterable) {
return IteratorPipeline.of(iterable.iterator());
}
public static IteratorPipeline iterator(E[] array) {
return IteratorPipeline.of(new ArrayIterator<>(array));
}
public static IteratorPipeline iterator(Stream stream) {
return IteratorPipeline.of(stream.iterator());
}
@SafeVarargs
public static IteratorPipeline iterators(Iterator... iterators) {
return IteratorPipeline.multi(iterators);
}
@SafeVarargs
public static IteratorPipeline iterators(Iterable... iterables) {
@SuppressWarnings("unchecked")
Iterator[] iterators = new Iterator[iterables.length];
for (int i = 0; i < iterables.length; i++) {
iterators[i] = iterables[i].iterator();
}
return IteratorPipeline.multi(iterators);
}
@SafeVarargs
public static IteratorPipeline iterators(E[]... arrays) {
@SuppressWarnings("unchecked")
Iterator[] iterators = new Iterator[arrays.length];
for (int i = 0; i < arrays.length; i++) {
iterators[i] = new ArrayIterator<>(arrays[i]);
}
return IteratorPipeline.multi(iterators);
}
@SafeVarargs
public static IteratorPipeline iterators(Stream... streams) {
@SuppressWarnings("unchecked")
Iterator[] iterators = new Iterator[streams.length];
for (int i = 0; i < streams.length; i++) {
iterators[i] = streams[i].iterator();
}
return IteratorPipeline.multi(iterators);
}
}