functionalj.stream.longstream.collect.DerivedLongCollectorToLongPlus 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.longstream.collect;
import java.util.Set;
import java.util.function.BiConsumer;
import java.util.function.BinaryOperator;
import java.util.function.DoubleToLongFunction;
import java.util.function.Function;
import java.util.function.IntToLongFunction;
import java.util.function.LongUnaryOperator;
import java.util.function.ObjDoubleConsumer;
import java.util.function.ObjIntConsumer;
import java.util.function.ObjLongConsumer;
import java.util.function.Supplier;
import java.util.function.ToLongFunction;
import java.util.stream.Collector;
import java.util.stream.Collector.Characteristics;
import functionalj.stream.collect.CollectorToLongPlus;
import functionalj.stream.doublestream.collect.DoubleCollectorToLongPlus;
import functionalj.stream.intstream.collect.IntCollectorToLongPlus;
import lombok.val;
abstract public class DerivedLongCollectorToLongPlus {
final LongCollectorToLongPlus collector;
protected DerivedLongCollectorToLongPlus(LongCollectorToLongPlus collector) {
this.collector = collector;
}
public Supplier supplier() {
return collector.supplier();
}
public BinaryOperator combiner() {
return collector.combiner();
}
public ToLongFunction finisherToLong() {
return collector.finisherToLong();
}
public Function finisher() {
val finisher = finisherToLong();
return accumulated -> {
return finisher.applyAsLong(accumulated);
};
}
public Set characteristics() {
return collector.characteristics();
}
//== Implementations ==
public static class FromObj
extends DerivedLongCollectorToLongPlus
implements CollectorToLongPlus {
private final ToLongFunction mapper;
public FromObj(LongCollectorToLongPlus collector,
ToLongFunction 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.applyAsLong(s);
accumulator.accept(a, d);
};
}
@Override
public Collector collector() {
return this;
}
}
public static class FromInt
extends DerivedLongCollectorToLongPlus
implements IntCollectorToLongPlus {
private final IntToLongFunction mapper;
public