Returns an immutable bimap containing the same entries as {@code map}. If {@code map} somehow contains entries with duplicate keys (for example, if it is a {@code SortedMap} whose comparator is not <i>consistent with equals</i>), the results of this method are undefined. <p>The returned {@code BiMa
(Map<? extends K, ? extends V> map)
| 532 | * @throws NullPointerException if any key or value in {@code map} is null |
| 533 | */ |
| 534 | public static <K, V> ImmutableBiMap<K, V> copyOf(Map<? extends K, ? extends V> map) { |
| 535 | if (map instanceof ImmutableBiMap) { |
| 536 | @SuppressWarnings("unchecked") // safe since map is not writable |
| 537 | ImmutableBiMap<K, V> bimap = (ImmutableBiMap<K, V>) map; |
| 538 | // TODO(lowasser): if we need to make a copy of a BiMap because the |
| 539 | // forward map is a view, don't make a copy of the non-view delegate map |
| 540 | if (!bimap.isPartialView()) { |
| 541 | return bimap; |
| 542 | } |
| 543 | } |
| 544 | return copyOf(map.entrySet()); |
| 545 | } |
| 546 | |
| 547 | /** |
| 548 | * Returns an immutable bimap containing the given entries. The returned bimap iterates over |
no test coverage detected