|
23 | 23 | import java.util.TreeMap;
|
24 | 24 | import java.util.function.BiConsumer;
|
25 | 25 | import java.util.function.BiFunction;
|
| 26 | +import java.util.function.BinaryOperator; |
26 | 27 | import java.util.function.Function;
|
27 | 28 | import java.util.function.Predicate;
|
28 | 29 | import java.util.stream.Stream;
|
@@ -475,14 +476,44 @@ public <T> List<T> toList(Function<ColumnInfo, T> mapper) {
|
475 | 476 | return columnInfos.values().stream().map(mapper).toList();
|
476 | 477 | }
|
477 | 478 |
|
| 479 | + /** |
| 480 | + * Performs a {@link Stream#reduce(Object, BiFunction, BinaryOperator)} on {@link ColumnInfo} and |
| 481 | + * {@link AggregatePath} to reduce the results into a single {@code T} return value. |
| 482 | + * <p> |
| 483 | + * If {@code ColumnInfos} is empty, then {@code identity} is returned. Without invoking {@code combiner}. The |
| 484 | + * {@link BinaryOperator combiner} is called with the current state (or initial {@code identity}) and the |
| 485 | + * accumulated {@code T} state to combine both into a single return value. |
| 486 | + * |
| 487 | + * @param identity the identity (initial) value for the combiner function. |
| 488 | + * @param accumulator an associative, non-interfering (free of side effects), stateless function for incorporating |
| 489 | + * an additional element into a result. |
| 490 | + * @param combiner an associative, non-interfering, stateless function for combining two values, which must be |
| 491 | + * compatible with the {@code accumulator} function. |
| 492 | + * @return result of the function. |
| 493 | + * @param <T> type of the result. |
| 494 | + * @since 3.5 |
| 495 | + */ |
| 496 | + public <T> T reduce(T identity, BiFunction<AggregatePath, ColumnInfo, T> accumulator, BinaryOperator<T> combiner) { |
| 497 | + |
| 498 | + T result = identity; |
| 499 | + |
| 500 | + for (Map.Entry<AggregatePath, ColumnInfo> entry : columnInfos.entrySet()) { |
| 501 | + |
| 502 | + T mapped = accumulator.apply(entry.getKey(), entry.getValue()); |
| 503 | + result = combiner.apply(result, mapped); |
| 504 | + } |
| 505 | + |
| 506 | + return result; |
| 507 | + } |
| 508 | + |
478 | 509 | public void forEach(BiConsumer<AggregatePath, ColumnInfo> consumer) {
|
479 | 510 | columnInfos.forEach(consumer);
|
480 | 511 | }
|
481 | 512 |
|
482 |
| - public <T> T any(BiFunction<AggregatePath, ColumnInfo, T> consumer) { |
| 513 | + public <T> T any(BiFunction<AggregatePath, ColumnInfo, T> mapper) { |
483 | 514 |
|
484 | 515 | Map.Entry<AggregatePath, ColumnInfo> any = columnInfos.entrySet().iterator().next();
|
485 |
| - return consumer.apply(any.getKey(), any.getValue()); |
| 516 | + return mapper.apply(any.getKey(), any.getValue()); |
486 | 517 | }
|
487 | 518 |
|
488 | 519 | public ColumnInfo get(AggregatePath path) {
|
|
0 commit comments