| 1 | /* | |
| 2 | * Copyright 2014-2026 Grzegorz Piwowarek, https://4comprehension.com/ | |
| 3 | * | |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); | |
| 5 | * you may not use this file except in compliance with the License. | |
| 6 | * You may obtain a copy of the License at | |
| 7 | * | |
| 8 | * https://www.apache.org/licenses/LICENSE-2.0 | |
| 9 | * | |
| 10 | * Unless required by applicable law or agreed to in writing, software | |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, | |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 13 | * See the License for the specific language governing permissions and | |
| 14 | * limitations under the License. | |
| 15 | */ | |
| 16 | package com.pivovarit.collectors; | |
| 17 | ||
| 18 | import java.util.List; | |
| 19 | import java.util.Objects; | |
| 20 | import java.util.function.BiFunction; | |
| 21 | ||
| 22 | /** | |
| 23 | * Represents a grouping of values under a specific key. | |
| 24 | * | |
| 25 | * @param <T> the type of the key | |
| 26 | * @param <V> the type of the values | |
| 27 | * @param key the key of this group, must not be null | |
| 28 | * @param values the list of values, must not be null | |
| 29 | */ | |
| 30 | public record Grouped<T, V>(T key, List<V> values) { | |
| 31 | ||
| 32 | /** | |
| 33 | * Constructs a new {@code Grouped} instance ensuring key and values are not null. | |
| 34 | * | |
| 35 | * @param key the key, must not be null | |
| 36 | * @param values the list of values, must not be null | |
| 37 | */ | |
| 38 | public Grouped { | |
| 39 | Objects.requireNonNull(key, "key cannot be null"); | |
| 40 | Objects.requireNonNull(values, "values cannot be null"); | |
| 41 | } | |
| 42 | ||
| 43 | /** | |
| 44 | * Creates a new {@code Grouped} instance with the given key and values. | |
| 45 | * | |
| 46 | * @param key the key, must not be null | |
| 47 | * @param values the list of values, must not be null | |
| 48 | * @param <T> the type of the key | |
| 49 | * @param <V> the type of the values | |
| 50 | * | |
| 51 | * @return a new {@code Grouped} instance | |
| 52 | */ | |
| 53 | public static <T, V> Grouped<T, V> of(T key, List<V> values) { | |
| 54 |
1
1. of : replaced return value with null for com/pivovarit/collectors/Grouped::of → KILLED |
return new Grouped<>(key, values); |
| 55 | } | |
| 56 | ||
| 57 | /** | |
| 58 | * Transforms the values in this group using the provided mapper function. | |
| 59 | * | |
| 60 | * @param mapper the mapping function, must not be null | |
| 61 | * @param <R> the target type of the mapped values | |
| 62 | * | |
| 63 | * @return a new {@code Grouped} instance with the same key and the values produced by applying | |
| 64 | * {@code mapper} to each element in this group's values | |
| 65 | */ | |
| 66 | public <R> Grouped<T, R> map(BiFunction<? super T, ? super V, ? extends R> mapper) { | |
| 67 | Objects.requireNonNull(mapper, "mapper cannot be null"); | |
| 68 |
1
1. map : replaced return value with null for com/pivovarit/collectors/Grouped::map → KILLED |
return new Grouped<>(key, values.stream() |
| 69 |
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)) |
| 70 |
1
1. lambda$map$1 : replaced return value with null for com/pivovarit/collectors/Grouped::lambda$map$1 → KILLED |
.map(a -> (R) a) |
| 71 | .toList()); | |
| 72 | } | |
| 73 | } | |
Mutations | ||
| 54 |
1.1 |
|
| 68 |
1.1 |
|
| 69 |
1.1 |
|
| 70 |
1.1 |