Returns an immutable map instance containing the given entries. Internally, the returned map will be backed by an EnumMap. 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)
| 136 | */ |
| 137 | |
| 138 | @GwtCompatible(serializable = true) |
| 139 | @Beta |
| 140 | public static <K extends Enum<K>, V> ImmutableMap<K, V> immutableEnumMap(Map<K, ? extends V> map) { |
| 141 | if (map instanceof ImmutableEnumMap) { |
| 142 | |
| 143 | @SuppressWarnings("unchecked") // safe covariant cast |
| 144 | ImmutableEnumMap<K, V> result = (ImmutableEnumMap<K, V>) map; |
| 145 | return result; |
| 146 | } else if (map.isEmpty()) { |
| 147 | return ImmutableMap.of(); |
| 148 | } else { |
| 149 | for (Map.Entry<K, ? extends V> entry : map.entrySet()) { |
| 150 | checkNotNull(entry.getKey()); |
| 151 | checkNotNull(entry.getValue()); |
| 152 | } |
| 153 | return ImmutableEnumMap.asImmutable(new EnumMap<K, V>(map)); |
| 154 | } |
| 155 | } |
| 156 | |
| 157 | /** |
| 158 | * Creates a <i>mutable</i>, empty {@code HashMap} instance. |
nothing calls this directly
no test coverage detected