1313import static graphql .Assert .assertNotNull ;
1414
1515@ Internal
16+ @ SuppressWarnings ({"UnstableApiUsage" })
1617public final class ImmutableKit {
1718
1819 public static <T > ImmutableList <T > emptyList () {
@@ -32,7 +33,6 @@ public static <K, V> ImmutableMap<K, V> addToMap(Map<K, V> existing, K newKey, V
3233 }
3334
3435 public static <T > ImmutableList <T > concatLists (List <T > l1 , List <T > l2 ) {
35- //noinspection UnstableApiUsage
3636 return ImmutableList .<T >builderWithExpectedSize (l1 .size () + l2 .size ()).addAll (l1 ).addAll (l2 ).build ();
3737 }
3838
@@ -50,8 +50,7 @@ public static <T> ImmutableList<T> concatLists(List<T> l1, List<T> l2) {
5050 public static <T , R > ImmutableList <R > map (Collection <? extends T > collection , Function <? super T , ? extends R > mapper ) {
5151 assertNotNull (collection );
5252 assertNotNull (mapper );
53- @ SuppressWarnings ({"RedundantTypeArguments" , "UnstableApiUsage" })
54- ImmutableList .Builder <R > builder = ImmutableList .<R >builderWithExpectedSize (collection .size ());
53+ ImmutableList .Builder <R > builder = ImmutableList .builderWithExpectedSize (collection .size ());
5554 for (T t : collection ) {
5655 R r = mapper .apply (t );
5756 builder .add (r );
@@ -60,21 +59,22 @@ public static <T, R> ImmutableList<R> map(Collection<? extends T> collection, Fu
6059 }
6160
6261 /**
63- * This will map an iterable of items but drop any that are null from the mapped list
64- *
62+ * This will map a collection of items but drop any that are null from the input.
6563 * This is more efficient than `c.stream().map().collect()` because it does not create the intermediate objects needed
6664 * for the flexible style. Benchmarking has shown this to outperform `stream()`.
6765 *
68- * @param iterable the iterable to map
66+ * @param collection the collection to map
6967 * @param mapper the mapper function
7068 * @param <T> for two
7169 * @param <R> for result
7270 *
7371 * @return a map immutable list of results
7472 */
75- public static <T , R > ImmutableList <R > mapAndDropNulls (Iterable <? extends T > iterable , Function <? super T , ? extends R > mapper ) {
76- ImmutableList .Builder <R > builder = ImmutableList .builder ();
77- for (T t : iterable ) {
73+ public static <T , R > ImmutableList <R > mapAndDropNulls (Collection <? extends T > collection , Function <? super T , ? extends R > mapper ) {
74+ assertNotNull (collection );
75+ assertNotNull (mapper );
76+ ImmutableList .Builder <R > builder = ImmutableList .builderWithExpectedSize (collection .size ());
77+ for (T t : collection ) {
7878 R r = mapper .apply (t );
7979 if (r != null ) {
8080 builder .add (r );
@@ -83,7 +83,6 @@ public static <T, R> ImmutableList<R> mapAndDropNulls(Iterable<? extends T> iter
8383 return builder .build ();
8484 }
8585
86-
8786 /**
8887 * This constructs a new Immutable list from an existing collection and adds a new element to it.
8988 *
@@ -99,7 +98,6 @@ public static <T> ImmutableList<T> addToList(Collection<? extends T> existing, T
9998 assertNotNull (existing );
10099 assertNotNull (newValue );
101100 int expectedSize = existing .size () + 1 + extraValues .length ;
102- @ SuppressWarnings ("UnstableApiUsage" )
103101 ImmutableList .Builder <T > newList = ImmutableList .builderWithExpectedSize (expectedSize );
104102 newList .addAll (existing );
105103 newList .add (newValue );
@@ -124,7 +122,6 @@ public static <T> ImmutableSet<T> addToSet(Collection<? extends T> existing, T n
124122 assertNotNull (existing );
125123 assertNotNull (newValue );
126124 int expectedSize = existing .size () + 1 + extraValues .length ;
127- @ SuppressWarnings ("UnstableApiUsage" )
128125 ImmutableSet .Builder <T > newSet = ImmutableSet .builderWithExpectedSize (expectedSize );
129126 newSet .addAll (existing );
130127 newSet .add (newValue );
0 commit comments