MCPcopy Index your code
hub / github.com/BruceEckel/OnJava8-Examples / invert

Method invert

onjava/HTMLColors.java:163–174  ·  view source on GitHub ↗
(Map<K, V> map)

Source from the content-addressed store, hash-verified

161 ));
162 // Inversion only works if values are unique:
163 public static <V, K> Map<V, K>
164 invert(Map<K, V> map) {
165 return map.entrySet().stream()
166 .collect(Collectors.toMap(
167 Map.Entry::getValue,
168 Map.Entry::getKey,
169 (v1, v2) -> {
170 throw new IllegalStateException();
171 },
172 LinkedHashMap::new
173 ));
174 }
175 public static final Map<String,Integer>
176 INVMAP = invert(MAP);
177 // Look up RGB value given a name:

Callers 1

HTMLColorsClass · 0.95

Calls 2

streamMethod · 0.45
entrySetMethod · 0.45

Tested by

no test coverage detected