All Downloads are FREE. Search and download functionalities are using the official Maven repository.

functionalj.stream.doublestream.collect.DerivedDoubleCollectorToBooleanPlus Maven / Gradle / Ivy

There is a newer version: 1.0.17
Show newest version
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.Predicate;
import java.util.function.Supplier;
import java.util.function.ToDoubleFunction;
import java.util.stream.Collector;
import java.util.stream.Collector.Characteristics;

import functionalj.stream.collect.CollectorToBooleanPlus;
import functionalj.stream.intstream.collect.IntCollectorToBooleanPlus;
import functionalj.stream.longstream.collect.LongCollectorToBooleanPlus;
import lombok.val;

abstract public class DerivedDoubleCollectorToBooleanPlus {
    
    final DoubleCollectorToBooleanPlus collector;
    
    protected DerivedDoubleCollectorToBooleanPlus(DoubleCollectorToBooleanPlus 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 DerivedDoubleCollectorToBooleanPlus
                        implements CollectorToBooleanPlus {
        
        private final ToDoubleFunction mapper;
        
        public FromObj(DoubleCollectorToBooleanPlus 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 DerivedDoubleCollectorToBooleanPlus
                        implements IntCollectorToBooleanPlus {
        
        private final IntToDoubleFunction mapper;
        
        public  FromInt(DoubleCollectorToBooleanPlus collector, 
                                IntToDoubleFunction                       mapper) {
            super(collector);
            this.mapper = mapper;
        }
        
        @SuppressWarnings({ "unchecked", "rawtypes" })
        @Override
        public  ObjIntConsumer intAccumulator() {
            val accumulator = (BiConsumer)collector.accumulator();
            return (a, s) -> {
                val d = mapper.applyAsDouble(s);
                accumulator.accept(a, d);
            };
        }
    }
    
    public static class FromLong 
                        extends DerivedDoubleCollectorToBooleanPlus
                        implements LongCollectorToBooleanPlus {
        
        private final LongToDoubleFunction mapper;
        
        public FromLong(DoubleCollectorToBooleanPlus collector, 
                        LongToDoubleFunction                      mapper) {
            super(collector);
            this.mapper = mapper;
        }
        
        @SuppressWarnings({ "unchecked", "rawtypes" })
        @Override
        public  ObjLongConsumer longAccumulator() {
            val accumulator = (BiConsumer)collector.accumulator();
            return (a, s) -> {
                val d = mapper.applyAsDouble(s);
                accumulator.accept(a, d);
            };
        }
    }
    
    public static class FromDouble 
                        extends DerivedDoubleCollectorToBooleanPlus
                        implements DoubleCollectorToBooleanPlus {
        
        private final DoubleUnaryOperator mapper;
        
        public FromDouble(DoubleCollectorToBooleanPlus collector, 
                          DoubleUnaryOperator                       mapper) {
            super(collector);
            this.mapper = mapper;
        }
        
        @SuppressWarnings({ "unchecked", "rawtypes" })
        @Override
        public  ObjDoubleConsumer doubleAccumulator() {
            val accumulator = (BiConsumer)collector.accumulator();
            return (a, s) -> {
                val d = mapper.applyAsDouble(s);
                accumulator.accept(a, d);
            };
        }
    }
    
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy