Package graphql.collect
Class ImmutableKit
- java.lang.Object
-
- graphql.collect.ImmutableKit
-
public final class ImmutableKit extends java.lang.Object
-
-
Constructor Summary
Constructors Constructor Description ImmutableKit()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method 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.ImmutableSet<T>
addToSet(java.util.Collection<? extends T> existing, T newValue, T... extraValues)
This constructs a new Immutable set from an existing collection and adds a new element to it.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.util.Collection<? extends T> collection, 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 <T,R>
com.google.common.collect.ImmutableList<R>mapAndDropNulls(java.util.Collection<? extends T> collection, java.util.function.Function<? super T,? extends R> mapper)
This will map a collection of items but drop any that are null from the input.static <T> com.google.common.collect.ImmutableList<T>
nonNullCopyOf(java.util.Collection<T> collection)
-
-
-
Method Detail
-
emptyList
public static <T> com.google.common.collect.ImmutableList<T> emptyList()
-
nonNullCopyOf
public static <T> com.google.common.collect.ImmutableList<T> nonNullCopyOf(java.util.Collection<T> collection)
-
emptyMap
public static <K,V> com.google.common.collect.ImmutableMap<K,V> emptyMap()
-
addToMap
public static <K,V> com.google.common.collect.ImmutableMap<K,V> addToMap(java.util.Map<K,V> existing, K newKey, V newVal)
-
concatLists
public static <T> com.google.common.collect.ImmutableList<T> concatLists(java.util.List<T> l1, java.util.List<T> l2)
-
map
public static <T,R> com.google.common.collect.ImmutableList<R> map(java.util.Collection<? extends T> collection, 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. Benchmarking has shown this to outperform `stream()`.- Type Parameters:
T
- for twoR
- for result- Parameters:
collection
- the collection to mapmapper
- the mapper function- Returns:
- a map immutable list of results
-
mapAndDropNulls
public static <T,R> com.google.common.collect.ImmutableList<R> mapAndDropNulls(java.util.Collection<? extends T> collection, java.util.function.Function<? super T,? extends R> mapper)
This will map a collection of items but drop any that are null from the input. This is more efficient than `c.stream().map().collect()` because it does not create the intermediate objects needed for the flexible style. Benchmarking has shown this to outperform `stream()`.- Type Parameters:
T
- for twoR
- for result- Parameters:
collection
- the collection to mapmapper
- the mapper function- Returns:
- a map immutable list of results
-
addToList
@SafeVarargs public 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.- Type Parameters:
T
- for two- Parameters:
existing
- the existing collectionnewValue
- the new value to addextraValues
- more values to add- Returns:
- an Immutable list with the extra items.
-
addToSet
@SafeVarargs public static <T> com.google.common.collect.ImmutableSet<T> addToSet(java.util.Collection<? extends T> existing, T newValue, T... extraValues)
This constructs a new Immutable set from an existing collection and adds a new element to it.- Type Parameters:
T
- for two- Parameters:
existing
- the existing collectionnewValue
- the new value to addextraValues
- more values to add- Returns:
- an Immutable Set with the extra items.
-
-