
com.jongsoft.lang.collection.support.PipeCommand Maven / Gradle / Ivy
The newest version!
package com.jongsoft.lang.collection.support;
import java.util.Iterator;
import java.util.function.BiFunction;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.function.Supplier;
import java.util.stream.Stream;
import com.jongsoft.lang.collection.Collection;
import com.jongsoft.lang.collection.Pipeline;
public class PipeCommand implements Pipeline {
private final Supplier> command;
public PipeCommand(Collection origin) {
this.command = () -> origin;
}
private PipeCommand(Supplier> command) {
this.command = command;
}
@Override
public Pipeline map(Function mapper) {
return new PipeCommand<>(() -> command.get().map(mapper));
}
@Override
public Pipeline filter(Predicate predicate) {
return new PipeCommand<>(() -> command.get().filter(predicate));
}
@Override
public Pipeline reject(Predicate predicate) {
return new PipeCommand<>(() -> command.get().reject(predicate));
}
@Override
public Stream stream() {
return command.get().stream();
}
@Override
public Iterator iterator() {
return command.get().iterator();
}
@Override
public U foldLeft(U start, BiFunction super U, ? super T, ? extends U> combiner) {
return command.get().foldLeft(start, combiner);
}
@Override
public U foldRight(U start, BiFunction super T, ? super U, ? extends U> combiner) {
return command.get().foldRight(start, combiner);
}
@Override
public T reduceLeft(BiFunction super T, ? super T, ? extends T> reducer) {
return command.get().reduceLeft(reducer);
}
@Override
public void consume(final Consumer consumer) {
command.get().forEach(consumer);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy