mirror of
https://github.com/google/nomulus.git
synced 2025-07-22 02:36:03 +02:00
Make ImmutableMap Stream collect()ion nicer (#654)
This adds an entriesToImmutableMap() collector that can be used in place of toImmutableMap(Map.Entry::getkey, Map.Entry::getValue()). It also fixes up some existing calls that use toImmutableMap() when terser alternatives exist.
This commit is contained in:
parent
660b2af990
commit
d0149d75c9
15 changed files with 49 additions and 54 deletions
|
@ -33,6 +33,7 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.SortedMap;
|
||||
import java.util.stream.Collector;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
/** Utility methods related to collections. */
|
||||
|
@ -148,4 +149,11 @@ public class CollectionUtils {
|
|||
}
|
||||
return shards.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a {@link Collector} that accumulates {@link Map.Entry}s into an {@code ImmutableMap}.
|
||||
*/
|
||||
public static <K, V> Collector<Map.Entry<K, V>, ?, ImmutableMap<K, V>> entriesToImmutableMap() {
|
||||
return ImmutableMap.toImmutableMap(Map.Entry::getKey, Map.Entry::getValue);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue