MCPcopy
hub / github.com/google/guava / copyOf

Method copyOf

guava/src/com/google/common/collect/ImmutableMap.java:687–713  ·  guava/src/com/google/common/collect/ImmutableMap.java::ImmutableMap.copyOf

Returns an immutable map containing the same entries as {@code map}. The returned map iterates over entries in the same order as the {@code entrySet} of the original map. If {@code map} somehow contains entries with duplicate keys (for example, if it is a {@code SortedMap} whose comparator is not <i

(Map<? extends K, ? extends V> map)

Source from the content-addressed store, hash-verified

685 * @throws NullPointerException if any key or value in {@code map} is null
686 */
687 public static <K, V> ImmutableMap<K, V> copyOf(Map<? extends K, ? extends V> map) {
688 if ((map instanceof ImmutableMap) && !(map instanceof SortedMap)) {
689 @SuppressWarnings(class="st">"unchecked") class="cm">// safe since map is not writable
690 ImmutableMap<K, V> kvMap = (ImmutableMap<K, V>) map;
691 if (!kvMap.isPartialView()) {
692 return kvMap;
693 }
694 } else if (map instanceof EnumMap) {
695 EnumMap<?, ? extends V> clone = ((EnumMap<?, ? extends V>) map).clone();
696 for (Entry<?, ?> entry : clone.entrySet()) {
697 checkEntryNotNull(entry.getKey(), entry.getValue());
698 }
699 ImmutableMap<?, ? extends V> untypedResult = ImmutableEnumMap.asImmutable(clone);
700 /*
701 * The result has the same type argument we started with. We just couldn't express EnumMap<K,
702 * ...> or ImmutableEnumMap<K, ...> along the way because our own <K> isn't <K extends
703 * Enum<K>>.
704 *
705 * We are also performing a covariant cast, potentially from ImmutableMap<K, Sub> to
706 * ImmutableMap<K, Super>. That is safe because no one can add elements to the map.
707 */
708 @SuppressWarnings(class="st">"unchecked")
709 ImmutableMap<K, V> result = (ImmutableMap<K, V>) untypedResult;
710 return result;
711 }
712 return copyOf(map.entrySet());
713 }
714
715 /**
716 * Returns an immutable map containing the specified entries. The returned map iterates over

Callers 15

getAllMethod · 0.95
getAllMethod · 0.95
getAllPresentMethod · 0.95
columnMapMethod · 0.95
rowMapMethod · 0.95
SparseImmutableTableMethod · 0.95
columnMapMethod · 0.95
rowMapMethod · 0.95
getClassPathEntriesMethod · 0.95
getTypeMappingsMethod · 0.95
ofImmutableMethod · 0.95
ofImmutableMethod · 0.95

Calls 10

asImmutableMethod · 0.95
toArrayMethod · 0.95
ofMethod · 0.95
fromEntriesMethod · 0.95
entrySetMethod · 0.65
getKeyMethod · 0.65
getValueMethod · 0.65
isPartialViewMethod · 0.45
cloneMethod · 0.45
checkEntryNotNullMethod · 0.45

Tested by

no test coverage detected