functionalj.stream.doublestream.collect.DerivedDoubleCollectorToIntPlus 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.doublestream.collect;
import java.util.Set;
import java.util.function.BiConsumer;
import java.util.function.BinaryOperator;
import java.util.function.DoubleUnaryOperator;
import java.util.function.Function;
import java.util.function.IntToDoubleFunction;
import java.util.function.LongToDoubleFunction;
import java.util.function.ObjDoubleConsumer;
import java.util.function.ObjIntConsumer;
import java.util.function.ObjLongConsumer;
import java.util.function.Supplier;
import java.util.function.ToDoubleFunction;
import java.util.function.ToIntFunction;
import java.util.stream.Collector;
import java.util.stream.Collector.Characteristics;
import functionalj.stream.collect.CollectorToIntPlus;
import functionalj.stream.intstream.collect.IntCollectorToIntPlus;
import functionalj.stream.longstream.collect.LongCollectorToIntPlus;
import lombok.val;
abstract public class DerivedDoubleCollectorToIntPlus {
final DoubleCollectorToIntPlus collector;
protected DerivedDoubleCollectorToIntPlus(DoubleCollectorToIntPlus collector) {
this.collector = collector;
}
public Supplier supplier() {
return collector.supplier();
}
public BinaryOperator combiner() {
return collector.combiner();
}
public ToIntFunction finisherToInt() {
return collector.finisherToInt();
}
public Function finisher() {
val finisher = finisherToInt();
return accumulated -> {
return finisher.applyAsInt(accumulated);
};
}
public Set characteristics() {
return collector.characteristics();
}
//== Implementations ==
public static class FromObj
extends DerivedDoubleCollectorToIntPlus
implements CollectorToIntPlus {
private final ToDoubleFunction mapper;
public FromObj(DoubleCollectorToIntPlus collector,
ToDoubleFunction 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.applyAsDouble(s);
accumulator.accept(a, d);
};
}
@Override
public Collector collector() {
return this;
}
}
public static class FromInt
extends DerivedDoubleCollectorToIntPlus
implements IntCollectorToIntPlus {
private final IntToDoubleFunction mapper;
public