| 1 | package com.pivovarit.collectors; | |
| 2 | ||
| 3 | import java.util.List; | |
| 4 | import java.util.Objects; | |
| 5 | import java.util.function.BiFunction; | |
| 6 | ||
| 7 | /** | |
| 8 | * Represents a grouping of values under a specific key. | |
| 9 | * | |
| 10 | * @param <T> the type of the key | |
| 11 | * @param <V> the type of the values | |
| 12 | * @param key the key of this group, must not be null | |
| 13 | * @param values the list of values, must not be null | |
| 14 | */ | |
| 15 | public record Grouped<T, V>(T key, List<V> values) { | |
| 16 | ||
| 17 | /** | |
| 18 | * Constructs a new {@code Grouped} instance ensuring key and values are not null. | |
| 19 | * | |
| 20 | * @param key the key, must not be null | |
| 21 | * @param values the list of values, must not be null | |
| 22 | */ | |
| 23 | public Grouped { | |
| 24 | Objects.requireNonNull(key, "key cannot be null"); | |
| 25 | Objects.requireNonNull(values, "values cannot be null"); | |
| 26 | } | |
| 27 | ||
| 28 | /** | |
| 29 | * Creates a new {@code Grouped} instance with the given key and values. | |
| 30 | * | |
| 31 | * @param key the key, must not be null | |
| 32 | * @param values the list of values, must not be null | |
| 33 | * @param <T> the type of the key | |
| 34 | * @param <V> the type of the values | |
| 35 | * | |
| 36 | * @return a new {@code Grouped} instance | |
| 37 | */ | |
| 38 | public static <T, V> Grouped<T, V> of(T key, List<V> values) { | |
| 39 |
1
1. of : replaced return value with null for com/pivovarit/collectors/Grouped::of → KILLED |
return new Grouped<>(key, values); |
| 40 | } | |
| 41 | ||
| 42 | /** | |
| 43 | * Transforms the values in this group using the provided mapper function. | |
| 44 | * | |
| 45 | * @param mapper the mapping function, must not be null | |
| 46 | * @param <R> the target type of the mapped values | |
| 47 | * | |
| 48 | * @return a new {@code Grouped} instance with the same key and the values produced by applying | |
| 49 | * {@code mapper} to each element in this group's values | |
| 50 | */ | |
| 51 | public <R> Grouped<T, R> map(BiFunction<? super T, ? super V, ? extends R> mapper) { | |
| 52 | Objects.requireNonNull(mapper, "mapper cannot be null"); | |
| 53 |
1
1. map : replaced return value with null for com/pivovarit/collectors/Grouped::map → KILLED |
return new Grouped<>(key, values.stream() |
| 54 |
1
1. lambda$map$0 : replaced return value with null for com/pivovarit/collectors/Grouped::lambda$map$0 → KILLED |
.map(v -> mapper.apply(key, v)) |
| 55 |
1
1. lambda$map$1 : replaced return value with null for com/pivovarit/collectors/Grouped::lambda$map$1 → KILLED |
.map(a -> (R) a) |
| 56 | .toList()); | |
| 57 | } | |
| 58 | } | |
Mutations | ||
| 39 |
1.1 |
|
| 53 |
1.1 |
|
| 54 |
1.1 |
|
| 55 |
1.1 |