1269 remappingFunction.apply(oldValue, value);
1270 if (newValue == null) {
1271 remove(key);
1272 } else {
1273 put(key, newValue);
1274 }
1275 return newValue;
1276 }
1277
1278 /**
1279 * Returns an immutable map containing zero mappings.
1280 * See <a href="#immutable">Immutable Map Static Factory Methods</a> for details.
1281 *
1282 * @param <K> the {@code Map}'s key type
1283 * @param <V> the {@code Map}'s value type
1284 * @return an empty {@code Map}
1285 *
1286 * @since 9
1287 */
1288 static <K, V> Map<K, V> of() {
1289 return ImmutableCollections.Map0.instance();
1290 }
1291
1292 /**
1293 * Returns an immutable map containing a single mapping.
1294 * See <a href="#immutable">Immutable Map Static Factory Methods</a> for details.
1295 *
1296 * @param <K> the {@code Map}'s key type
1297 * @param <V> the {@code Map}'s value type
1298 * @param k1 the mapping's key
1299 * @param v1 the mapping's value
1300 * @return a {@code Map} containing the specified mapping
1301 * @throws NullPointerException if the key or the value is {@code null}
1302 *
1303 * @since 9
1304 */
1305 static <K, V> Map<K, V> of(K k1, V v1) {
1306 return new ImmutableCollections.Map1<>(k1, v1);
1307 }
1308
1309 /**
1586 * entry(3, "c"),
1587 * ...
1588 * entry(26, "z"));
1589 * }</pre>
1590 *
1591 * @param <K> the {@code Map}'s key type
1592 * @param <V> the {@code Map}'s value type
1593 * @param entries {@code Map.Entry}s containing the keys and values from which the map is populated
1594 * @return a {@code Map} containing the specified mappings
1595 * @throws IllegalArgumentException if there are any duplicate keys
1596 * @throws NullPointerException if any entry, key, or value is {@code null}, or if
1597 * the {@code entries} array is {@code null}
1598 *
1599 * @see Map#entry Map.entry()
1600 * @since 9
1601 */
1602 @SafeVarargs
1603 @SuppressWarnings("varargs")
1604 static <K, V> Map<K, V> ofEntries(Entry<? extends K, ? extends V>... entries) {
1605 if (entries.length == 0) { // implicit null check of entries
1606 return ImmutableCollections.Map0.instance();
1607 } else if (entries.length == 1) {
1608 return new ImmutableCollections.Map1<>(entries[0].getKey(),
1609 entries[0].getValue());
1610 } else {
1611 Object[] kva = new Object[entries.length << 1];
1612 int a = 0;
1613 for (Entry<? extends K, ? extends V> entry : entries) {
1614 kva[a++] = entry.getKey();
1615 kva[a++] = entry.getValue();
1616 }
1617 return new ImmutableCollections.MapN<>(kva);
1618 }
1619 }
1620
1621 /**
1622 * Returns an immutable {@link Entry} containing the given key and value.
1623 * These entries are suitable for populating {@code Map} instances using the
1624 * {@link Map#ofEntries Map.ofEntries()} method.
1625 * The {@code Entry} instances created by this method have the following characteristics:
1626 *
|
1269 remappingFunction.apply(oldValue, value);
1270 if (newValue == null) {
1271 remove(key);
1272 } else {
1273 put(key, newValue);
1274 }
1275 return newValue;
1276 }
1277
1278 /**
1279 * Returns an immutable map containing zero mappings.
1280 * See <a href="#immutable">Immutable Map Static Factory Methods</a> for details.
1281 *
1282 * @param <K> the {@code Map}'s key type
1283 * @param <V> the {@code Map}'s value type
1284 * @return an empty {@code Map}
1285 *
1286 * @since 9
1287 */
1288 static <K, V> Map<K, V> of() {
1289 return ImmutableCollections.emptyMap();
1290 }
1291
1292 /**
1293 * Returns an immutable map containing a single mapping.
1294 * See <a href="#immutable">Immutable Map Static Factory Methods</a> for details.
1295 *
1296 * @param <K> the {@code Map}'s key type
1297 * @param <V> the {@code Map}'s value type
1298 * @param k1 the mapping's key
1299 * @param v1 the mapping's value
1300 * @return a {@code Map} containing the specified mapping
1301 * @throws NullPointerException if the key or the value is {@code null}
1302 *
1303 * @since 9
1304 */
1305 static <K, V> Map<K, V> of(K k1, V v1) {
1306 return new ImmutableCollections.Map1<>(k1, v1);
1307 }
1308
1309 /**
1586 * entry(3, "c"),
1587 * ...
1588 * entry(26, "z"));
1589 * }</pre>
1590 *
1591 * @param <K> the {@code Map}'s key type
1592 * @param <V> the {@code Map}'s value type
1593 * @param entries {@code Map.Entry}s containing the keys and values from which the map is populated
1594 * @return a {@code Map} containing the specified mappings
1595 * @throws IllegalArgumentException if there are any duplicate keys
1596 * @throws NullPointerException if any entry, key, or value is {@code null}, or if
1597 * the {@code entries} array is {@code null}
1598 *
1599 * @see Map#entry Map.entry()
1600 * @since 9
1601 */
1602 @SafeVarargs
1603 @SuppressWarnings("varargs")
1604 static <K, V> Map<K, V> ofEntries(Entry<? extends K, ? extends V>... entries) {
1605 if (entries.length == 0) { // implicit null check of entries
1606 return ImmutableCollections.emptyMap();
1607 } else if (entries.length == 1) {
1608 return new ImmutableCollections.Map1<>(entries[0].getKey(),
1609 entries[0].getValue());
1610 } else {
1611 Object[] kva = new Object[entries.length << 1];
1612 int a = 0;
1613 for (Entry<? extends K, ? extends V> entry : entries) {
1614 kva[a++] = entry.getKey();
1615 kva[a++] = entry.getValue();
1616 }
1617 return new ImmutableCollections.MapN<>(kva);
1618 }
1619 }
1620
1621 /**
1622 * Returns an immutable {@link Entry} containing the given key and value.
1623 * These entries are suitable for populating {@code Map} instances using the
1624 * {@link Map#ofEntries Map.ofEntries()} method.
1625 * The {@code Entry} instances created by this method have the following characteristics:
1626 *
|