functionalj.stream.intstream.collect.DerivedIntCollectorToBooleanPlus Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of functionalj-core Show documentation
Show all versions of functionalj-core Show documentation
The module for FunctionalJ Core.
package functionalj.stream.intstream.collect;
import java.util.Set;
import java.util.function.BiConsumer;
import java.util.function.BinaryOperator;
import java.util.function.DoubleToIntFunction;
import java.util.function.Function;
import java.util.function.IntUnaryOperator;
import java.util.function.LongToIntFunction;
import java.util.function.ObjDoubleConsumer;
import java.util.function.ObjIntConsumer;
import java.util.function.ObjLongConsumer;
import java.util.function.Predicate;
import java.util.function.Supplier;
import java.util.function.ToIntFunction;
import java.util.stream.Collector;
import java.util.stream.Collector.Characteristics;
import functionalj.stream.collect.CollectorToBooleanPlus;
import functionalj.stream.doublestream.collect.DoubleCollectorToBooleanPlus;
import functionalj.stream.longstream.collect.LongCollectorToBooleanPlus;
import lombok.val;
abstract public class DerivedIntCollectorToBooleanPlus {
final IntCollectorToBooleanPlus collector;
protected DerivedIntCollectorToBooleanPlus(IntCollectorToBooleanPlus collector) {
this.collector = collector;
}
public Supplier supplier() {
return collector.supplier();
}
public BinaryOperator combiner() {
return collector.combiner();
}
public Predicate finisherToBoolean() {
return collector.finisherToBoolean();
}
public Function finisher() {
val finisher = finisherToBoolean();
return accumulated -> {
return finisher.test(accumulated);
};
}
public Set characteristics() {
return collector.characteristics();
}
//== Implementations ==
public static class FromObj
extends DerivedIntCollectorToBooleanPlus
implements CollectorToBooleanPlus {
private final ToIntFunction mapper;
public FromObj(IntCollectorToBooleanPlus collector,
ToIntFunction mapper) {
super(collector);
this.mapper = mapper;
}
@SuppressWarnings("unchecked")
@Override
public BiConsumer accumulator(){
@SuppressWarnings("rawtypes")
val accumulator = (BiConsumer)collector.accumulator();
return (a, s) -> {
val d = mapper.applyAsInt(s);
accumulator.accept(a, d);
};
}
@Override
public Collector collector() {
return this;
}
}
public static class FromInt
extends DerivedIntCollectorToBooleanPlus
implements IntCollectorToBooleanPlus {
private final IntUnaryOperator mapper;
public