@@ -61,26 +61,27 @@ public static <K, V> ImmutableMap<K, V> mergeMaps(Map<K, V> m1, Map<K, V> m2) {
6161 }
6262
6363 public static <T > ImmutableList <T > concatLists (List <T > l1 , List <T > l2 ) {
64- return ImmutableList .<T >builder ().addAll (l1 ).addAll (l2 ).build ();
64+ //noinspection UnstableApiUsage
65+ return ImmutableList .<T >builderWithExpectedSize (l1 .size () + l2 .size ()).addAll (l1 ).addAll (l2 ).build ();
6566 }
6667
6768 /**
6869 * This is more efficient than `c.stream().map().collect()` because it does not create the intermediate objects needed
6970 * for the flexible style. Benchmarking has shown this to outperform `stream()`.
7071 *
71- * @param iterable the iterable to map
72+ * @param collection the collection to map
7273 * @param mapper the mapper function
7374 * @param <T> for two
7475 * @param <R> for result
7576 *
7677 * @return a map immutable list of results
7778 */
78- public static <T , R > ImmutableList <R > map (Iterable <? extends T > iterable , Function <? super T , ? extends R > mapper ) {
79- assertNotNull (iterable );
79+ public static <T , R > ImmutableList <R > map (Collection <? extends T > collection , Function <? super T , ? extends R > mapper ) {
80+ assertNotNull (collection );
8081 assertNotNull (mapper );
81- @ SuppressWarnings ("RedundantTypeArguments" )
82- ImmutableList .Builder <R > builder = ImmutableList .<R >builder ( );
83- for (T t : iterable ) {
82+ @ SuppressWarnings ({ "RedundantTypeArguments" , "UnstableApiUsage" } )
83+ ImmutableList .Builder <R > builder = ImmutableList .<R >builderWithExpectedSize ( collection . size () );
84+ for (T t : collection ) {
8485 R r = mapper .apply (t );
8586 builder .add (r );
8687 }
@@ -101,6 +102,7 @@ public static <T> ImmutableList<T> addToList(Collection<? extends T> existing, T
101102 assertNotNull (existing );
102103 assertNotNull (newValue );
103104 int expectedSize = existing .size () + 1 + extraValues .length ;
105+ @ SuppressWarnings ("UnstableApiUsage" )
104106 ImmutableList .Builder <T > newList = ImmutableList .builderWithExpectedSize (expectedSize );
105107 newList .addAll (existing );
106108 newList .add (newValue );
@@ -124,6 +126,7 @@ public static <T> ImmutableSet<T> addToSet(Collection<? extends T> existing, T n
124126 assertNotNull (existing );
125127 assertNotNull (newValue );
126128 int expectedSize = existing .size () + 1 + extraValues .length ;
129+ @ SuppressWarnings ("UnstableApiUsage" )
127130 ImmutableSet .Builder <T > newSet = ImmutableSet .builderWithExpectedSize (expectedSize );
128131 newSet .addAll (existing );
129132 newSet .add (newValue );
0 commit comments