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

Method immutableEnumMap

guava/src/com/google/common/collect/Maps.java:133–158  ·  guava/src/com/google/common/collect/Maps.java::Maps.immutableEnumMap

Returns an immutable map instance containing the given entries. Internally, the returned map will be backed by an {@link EnumMap}. <p>The iteration order of the returned map follows the enum's iteration order, not the order in which the elements appear in the given map. @param map the map to make

(
      Map<K, ? extends V> map)

Source from the content-addressed store, hash-verified

131 * @since 14.0
132 */
133 public static <K extends Enum<K>, V> ImmutableMap<K, V> immutableEnumMap(
134 Map<K, ? extends V> map) {
135 if (map instanceof ImmutableEnumMap) {
136 @SuppressWarnings(class="st">"unchecked") class="cm">// safe covariant cast
137 ImmutableEnumMap<K, V> result = (ImmutableEnumMap<K, V>) map;
138 return result;
139 }
140 Iterator<? extends Entry<K, ? extends V>> entryItr = map.entrySet().iterator();
141 if (!entryItr.hasNext()) {
142 return ImmutableMap.of();
143 }
144 Entry<K, ? extends V> entry1 = entryItr.next();
145 K key1 = entry1.getKey();
146 V value1 = entry1.getValue();
147 checkEntryNotNull(key1, value1);
148 class="cm">// Do something that works for j2cl, where we can't call getDeclaredClass():
149 EnumMap<K, V> enumMap = new EnumMap<>(singletonMap(key1, value1));
150 while (entryItr.hasNext()) {
151 Entry<K, ? extends V> entry = entryItr.next();
152 K key = entry.getKey();
153 V value = entry.getValue();
154 checkEntryNotNull(key, value);
155 enumMap.put(key, value);
156 }
157 return ImmutableEnumMap.asImmutable(enumMap);
158 }
159
160 /**
161 * Returns a {@link Collector} that accumulates elements into an {@code ImmutableMap} whose keys

Callers 7

createMethod · 0.45
testIteratesOnceMethod · 0.45
createMethod · 0.45

Calls 10

ofMethod · 0.95
asImmutableMethod · 0.95
iteratorMethod · 0.65
entrySetMethod · 0.65
nextMethod · 0.65
getKeyMethod · 0.65
getValueMethod · 0.65
putMethod · 0.65
hasNextMethod · 0.45
checkEntryNotNullMethod · 0.45

Tested by 7

createMethod · 0.36
testIteratesOnceMethod · 0.36
createMethod · 0.36