@Test public void convertListWithObjectKey() { String key1 = "key1"; String key2 = "key2"; TestObject testObject1 = new TestObject(key1, "something"); TestObject testObject2 = new TestObject(key2, "something"); Map<TestObject, String> mapWithObjectKey = DataStructureUtils.mapToKeys(List.of(testObject1, testObject2), TestObject::getName); assertTrue(mapWithObjectKey.containsKey(testObject1)); assertTrue(mapWithObjectKey.containsKey(testObject2)); assertEquals(key1, mapWithObjectKey.get(testObject1)); assertFalse(mapWithObjectKey.containsKey(key1)); }
public static <K, V> Map<K, V> mapToKeys(Collection<K> valueCollection, Function<K, V> valueExtractor) { return mapToMap(valueCollection, Function.identity(), valueExtractor); }
DataStructureUtils { public static <K, V> Map<K, V> mapToKeys(Collection<K> valueCollection, Function<K, V> valueExtractor) { return mapToMap(valueCollection, Function.identity(), valueExtractor); } }
DataStructureUtils { public static <K, V> Map<K, V> mapToKeys(Collection<K> valueCollection, Function<K, V> valueExtractor) { return mapToMap(valueCollection, Function.identity(), valueExtractor); } private  DataStructureUtils(); }
DataStructureUtils { public static <K, V> Map<K, V> mapToKeys(Collection<K> valueCollection, Function<K, V> valueExtractor) { return mapToMap(valueCollection, Function.identity(), valueExtractor); } private  DataStructureUtils(); static Map<K, V> mapToValues(Collection<V> valueCollection, Function<V, K> keyExtractor); static Map<K, V> mapToKeys(Collection<K> valueCollection, Function<K, V> valueExtractor); static Map<K, V> mapToMap(Collection<C> valueCollection, Function<C, K> keyExtractor, Function<C, V> valueExtractor); }
DataStructureUtils { public static <K, V> Map<K, V> mapToKeys(Collection<K> valueCollection, Function<K, V> valueExtractor) { return mapToMap(valueCollection, Function.identity(), valueExtractor); } private  DataStructureUtils(); static Map<K, V> mapToValues(Collection<V> valueCollection, Function<V, K> keyExtractor); static Map<K, V> mapToKeys(Collection<K> valueCollection, Function<K, V> valueExtractor); static Map<K, V> mapToMap(Collection<C> valueCollection, Function<C, K> keyExtractor, Function<C, V> valueExtractor);  }