Package graphql.collect
Class ImmutableKit
java.lang.Object
graphql.collect.ImmutableKit
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> com.google.common.collect.ImmutableList
<T> addToList
(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> static <T> com.google.common.collect.ImmutableSet
<T> addToSet
(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
(List<T> l1, List<T> l2) static <T> com.google.common.collect.ImmutableList
<T> static <K,
V> com.google.common.collect.ImmutableMap <K, V> emptyMap()
static <T> com.google.common.collect.ImmutableList
<T> filter
(Collection<? extends T> collection, Predicate<? super T> filter) This is more efficient than `c.stream().filter().collect()` because it does not create the intermediate objects needed for the flexible style.static <T,
R> com.google.common.collect.ImmutableList <R> filterAndMap
(Collection<? extends T> collection, Predicate<? super T> filter, Function<? super T, ? extends R> mapper) This is more efficient than `c.stream().filter().map().collect()` because it does not create the intermediate objects needed for the flexible style.static <T> com.google.common.collect.ImmutableList
<T> flatMapList
(Collection<List<T>> listLists) static <T,
R> com.google.common.collect.ImmutableList <R> map
(Collection<? extends T> collection, 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
(Collection<? extends T> collection, 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
(@Nullable Collection<T> collection)
-
Constructor Details
-
ImmutableKit
public ImmutableKit()
-
-
Method Details
-
emptyList
public static <T> com.google.common.collect.ImmutableList<T> emptyList() -
nonNullCopyOf
public static <T> com.google.common.collect.ImmutableList<T> nonNullCopyOf(@Nullable 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(Map<K, V> existing, K newKey, V newVal) -
concatLists
-
map
public static <T,R> com.google.common.collect.ImmutableList<R> map(Collection<? extends T> collection, 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
-
filter
public static <T> com.google.common.collect.ImmutableList<T> filter(Collection<? extends T> collection, Predicate<? super T> filter) This is more efficient than `c.stream().filter().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 two- Parameters:
collection
- the collection to mapfilter
- the filter predicate- Returns:
- a map immutable list of results
-
filterAndMap
public static <T,R> com.google.common.collect.ImmutableList<R> filterAndMap(Collection<? extends T> collection, Predicate<? super T> filter, Function<? super T, ? extends R> mapper) This is more efficient than `c.stream().filter().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 mapfilter
- the filter predicatemapper
- the mapper function- Returns:
- a map immutable list of results
-
flatMapList
public static <T> com.google.common.collect.ImmutableList<T> flatMapList(Collection<List<T>> listLists) -
mapAndDropNulls
public static <T,R> com.google.common.collect.ImmutableList<R> mapAndDropNulls(Collection<? extends T> collection, 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(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(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.
-