public final class ImmutableKit
extends java.lang.Object
| Constructor and Description |
|---|
ImmutableKit() |
| Modifier and Type | Method and Description |
|---|---|
static <T> com.google.common.collect.ImmutableList<T> |
addToList(java.util.Collection<? extends T> existing,
T newValue,
T... extraValues)
This constructs a new Immutable list from an existing collection and adds a new element to it.
|
static <K,V> com.google.common.collect.ImmutableMap<K,V> |
addToMap(java.util.Map<K,V> existing,
K newKey,
V newVal) |
static <T> com.google.common.collect.ImmutableList<T> |
concatLists(java.util.List<T> l1,
java.util.List<T> l2) |
static <T> com.google.common.collect.ImmutableList<T> |
emptyList() |
static <K,V> com.google.common.collect.ImmutableMap<K,V> |
emptyMap() |
static <T,R> com.google.common.collect.ImmutableList<R> |
map(java.lang.Iterable<? extends T> iterable,
java.util.function.Function<? super T,? extends R> mapper)
This is more efficient than `c.stream().map().collect()` because it does not create the intermediate objects needed
for the flexible style.
|
static <K,V> com.google.common.collect.ImmutableMap<K,V> |
mergeMaps(java.util.Map<K,V> m1,
java.util.Map<K,V> m2) |
static <T> com.google.common.collect.ImmutableList<T> |
nonNullCopyOf(java.util.Collection<T> collection) |
static <K,V> com.google.common.collect.ImmutableMap<K,com.google.common.collect.ImmutableList<V>> |
toImmutableMapOfLists(java.util.Map<K,java.util.List<V>> startingMap)
ImmutableMaps are hard to build via
Map.computeIfAbsent(Object, Function) style. |
public static <T> com.google.common.collect.ImmutableList<T> emptyList()
public static <T> com.google.common.collect.ImmutableList<T> nonNullCopyOf(java.util.Collection<T> collection)
public static <K,V> com.google.common.collect.ImmutableMap<K,V> emptyMap()
public static <K,V> com.google.common.collect.ImmutableMap<K,com.google.common.collect.ImmutableList<V>> toImmutableMapOfLists(java.util.Map<K,java.util.List<V>> startingMap)
Map.computeIfAbsent(Object, Function) style. This methods
allows you to take a mutable map with mutable list of keys and make it immutable.
This of course has a cost - if the map is very large you will be using more memory. But for static maps that live a long life it maybe be worth it.
K - for keyV - for victorystartingMap - the starting input mappublic static <K,V> com.google.common.collect.ImmutableMap<K,V> addToMap(java.util.Map<K,V> existing,
K newKey,
V newVal)
public static <K,V> com.google.common.collect.ImmutableMap<K,V> mergeMaps(java.util.Map<K,V> m1,
java.util.Map<K,V> m2)
public static <T> com.google.common.collect.ImmutableList<T> concatLists(java.util.List<T> l1,
java.util.List<T> l2)
public static <T,R> com.google.common.collect.ImmutableList<R> map(java.lang.Iterable<? extends T> iterable,
java.util.function.Function<? super T,? extends R> mapper)
T - for twoR - for resultiterable - the iterable to mapmapper - the mapper functionpublic static <T> com.google.common.collect.ImmutableList<T> addToList(java.util.Collection<? extends T> existing,
T newValue,
T... extraValues)
T - for twoexisting - the existing collectionnewValue - the new value to addextraValues - more values to add