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

functionalj.stream.StreamPlusWithGet Maven / Gradle / Ivy

There is a newer version: 1.0.17
Show newest version
package functionalj.stream;

import java.util.concurrent.atomic.AtomicLong;

import functionalj.tuple.Tuple;
import functionalj.tuple.Tuple2;
import functionalj.tuple.Tuple3;
import functionalj.tuple.Tuple4;
import functionalj.tuple.Tuple5;
import functionalj.tuple.Tuple6;
import lombok.val;

public interface StreamPlusWithGet {

    public IteratorPlus iterator();
    
    //== Get ==
    
    public default  T get(StreamElementProcessor processor) {
        val counter = new AtomicLong(0);
        for (val each : (Iterable)(()->iterator())) {
            val index = counter.getAndIncrement();
            processor.processElement(index, each);
        }
        val count = counter.get();
        return processor.processComplete(count);
    }
    
    public default  Tuple2 get(
                StreamElementProcessor processor1, 
                StreamElementProcessor processor2) {
        val counter = new AtomicLong(0);
        for (val each : (Iterable)(()->iterator())) {
            val index = counter.getAndIncrement();
            processor1.processElement(index, each);
            processor2.processElement(index, each);
        }
        val count = counter.get();
        val value1 = processor1.processComplete(count);
        val value2 = processor2.processComplete(count);
        return Tuple.of(value1, value2);
    }
    
    public default  Tuple3 get(
                StreamElementProcessor processor1, 
                StreamElementProcessor processor2, 
                StreamElementProcessor processor3) {
        val counter = new AtomicLong(0);
        for (val each : (Iterable)(()->iterator())) {
            val index = counter.getAndIncrement();
            processor1.processElement(index, each);
            processor2.processElement(index, each);
            processor3.processElement(index, each);
        }
        val count = counter.get();
        val value1 = processor1.processComplete(count);
        val value2 = processor2.processComplete(count);
        val value3 = processor3.processComplete(count);
        return Tuple.of(value1, value2, value3);
    }
    
    public default  Tuple4 get(
                StreamElementProcessor processor1, 
                StreamElementProcessor processor2, 
                StreamElementProcessor processor3, 
                StreamElementProcessor processor4) {
        val counter = new AtomicLong(0);
        for (val each : (Iterable)(()->iterator())) {
            val index = counter.getAndIncrement();
            processor1.processElement(index, each);
            processor2.processElement(index, each);
            processor3.processElement(index, each);
            processor4.processElement(index, each);
        }
        val count = counter.get();
        val value1 = processor1.processComplete(count);
        val value2 = processor2.processComplete(count);
        val value3 = processor3.processComplete(count);
        val value4 = processor4.processComplete(count);
        return Tuple.of(value1, value2, value3, value4);
    }
    
    public default  Tuple5 get(
                StreamElementProcessor processor1, 
                StreamElementProcessor processor2, 
                StreamElementProcessor processor3, 
                StreamElementProcessor processor4, 
                StreamElementProcessor processor5) {
        val counter = new AtomicLong(0);
        for (val each : (Iterable)(()->iterator())) {
            val index = counter.getAndIncrement();
            processor1.processElement(index, each);
            processor2.processElement(index, each);
            processor3.processElement(index, each);
            processor4.processElement(index, each);
            processor5.processElement(index, each);
        }
        val count = counter.get();
        val value1 = processor1.processComplete(count);
        val value2 = processor2.processComplete(count);
        val value3 = processor3.processComplete(count);
        val value4 = processor4.processComplete(count);
        val value5 = processor5.processComplete(count);
        return Tuple.of(value1, value2, value3, value4, value5);
    }
    
    public default  Tuple6 get(
                StreamElementProcessor processor1, 
                StreamElementProcessor processor2, 
                StreamElementProcessor processor3, 
                StreamElementProcessor processor4, 
                StreamElementProcessor processor5, 
                StreamElementProcessor processor6) {
        val counter = new AtomicLong(0);
        for (val each : (Iterable)(()->iterator())) {
            val index = counter.getAndIncrement();
            processor1.processElement(index, each);
            processor2.processElement(index, each);
            processor3.processElement(index, each);
            processor4.processElement(index, each);
            processor5.processElement(index, each);
            processor6.processElement(index, each);
        }
        val count = counter.get();
        val value1 = processor1.processComplete(count);
        val value2 = processor2.processComplete(count);
        val value3 = processor3.processComplete(count);
        val value4 = processor4.processComplete(count);
        val value5 = processor5.processComplete(count);
        val value6 = processor6.processComplete(count);
        return Tuple.of(value1, value2, value3, value4, value5, value6);
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy