All Downloads are FREE. Search and download functionalities are using the official Maven repository.
Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
functionalj.stream.StreamPlusWithCalculate Maven / Gradle / Ivy
package functionalj.stream;
import java.util.function.Consumer;
import java.util.stream.Collector;
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 StreamPlusWithCalculate {
public void forEach(Consumer super DATA> action);
//== Calculate ==
// TODO - Optimize this so the concurrent one can has benefit from the Java implementation
public default RESULT calculate(
Collector collector) {
val collected = new Collected.ByCollector<>(collector);
forEach(each -> {
collected.accumulate(each);
});
val value = collected.finish();
return value;
}
public default
Tuple2
calculate(
Collector collector1,
Collector collector2) {
val collected1 = new Collected.ByCollector<>(collector1);
val collected2 = new Collected.ByCollector<>(collector2);
forEach(each -> {
collected1.accumulate(each);
collected2.accumulate(each);
});
return Tuple.of(
collected1.finish(),
collected2.finish()
);
}
public default
Tuple3
calculate(
Collector collector1,
Collector collector2,
Collector collector3) {
val collected1 = new Collected.ByCollector<>(collector1);
val collected2 = new Collected.ByCollector<>(collector2);
val collected3 = new Collected.ByCollector<>(collector3);
forEach(each -> {
collected1.accumulate(each);
collected2.accumulate(each);
collected3.accumulate(each);
});
return Tuple.of(
collected1.finish(),
collected2.finish(),
collected3.finish()
);
}
public default
Tuple4
calculate(
Collector collector1,
Collector collector2,
Collector collector3,
Collector collector4) {
val collected1 = new Collected.ByCollector<>(collector1);
val collected2 = new Collected.ByCollector<>(collector2);
val collected3 = new Collected.ByCollector<>(collector3);
val collected4 = new Collected.ByCollector<>(collector4);
forEach(each -> {
collected1.accumulate(each);
collected2.accumulate(each);
collected3.accumulate(each);
collected4.accumulate(each);
});
return Tuple.of(
collected1.finish(),
collected2.finish(),
collected3.finish(),
collected4.finish()
);
}
public default
Tuple5
calculate(
Collector collector1,
Collector collector2,
Collector collector3,
Collector collector4,
Collector collector5) {
val collected1 = new Collected.ByCollector<>(collector1);
val collected2 = new Collected.ByCollector<>(collector2);
val collected3 = new Collected.ByCollector<>(collector3);
val collected4 = new Collected.ByCollector<>(collector4);
val collected5 = new Collected.ByCollector<>(collector5);
forEach(each -> {
collected1.accumulate(each);
collected2.accumulate(each);
collected3.accumulate(each);
collected4.accumulate(each);
collected5.accumulate(each);
});
return Tuple.of(
collected1.finish(),
collected2.finish(),
collected3.finish(),
collected4.finish(),
collected5.finish()
);
}
public default
Tuple6
calculate(
Collector collector1,
Collector collector2,
Collector collector3,
Collector collector4,
Collector collector5,
Collector collector6) {
val collected1 = new Collected.ByCollector<>(collector1);
val collected2 = new Collected.ByCollector<>(collector2);
val collected3 = new Collected.ByCollector<>(collector3);
val collected4 = new Collected.ByCollector<>(collector4);
val collected5 = new Collected.ByCollector<>(collector5);
val collected6 = new Collected.ByCollector<>(collector6);
forEach(each -> {
collected1.accumulate(each);
collected2.accumulate(each);
collected3.accumulate(each);
collected4.accumulate(each);
collected5.accumulate(each);
collected6.accumulate(each);
});
return Tuple.of(
collected1.finish(),
collected2.finish(),
collected3.finish(),
collected4.finish(),
collected5.finish(),
collected6.finish()
);
}
}