@Test public void convertListWithNameKey() { String key1 = "key1"; String key2 = "key2"; TestObject testObject1 = new TestObject(key1, "something"); TestObject testObject2 = new TestObject(key2, "something"); Map<String, TestObject> mapWithNameKey = DataStructureUtils.mapToValues(List.of(testObject1, testObject2), TestObject::getName); assertTrue(mapWithNameKey.containsKey(key1)); assertTrue(mapWithNameKey.containsKey(key2)); assertEquals(testObject1, mapWithNameKey.get(key1)); assertFalse(mapWithNameKey.containsKey(testObject1)); assertFalse(mapWithNameKey.containsKey(testObject1.getDesc())); }
public static <K, V> Map<K, V> mapToValues(Collection<V> valueCollection, Function<V, K> keyExtractor) { return mapToMap(valueCollection, keyExtractor, Function.identity()); }
DataStructureUtils { public static <K, V> Map<K, V> mapToValues(Collection<V> valueCollection, Function<V, K> keyExtractor) { return mapToMap(valueCollection, keyExtractor, Function.identity()); } }
DataStructureUtils { public static <K, V> Map<K, V> mapToValues(Collection<V> valueCollection, Function<V, K> keyExtractor) { return mapToMap(valueCollection, keyExtractor, Function.identity()); } private  DataStructureUtils(); }
DataStructureUtils { public static <K, V> Map<K, V> mapToValues(Collection<V> valueCollection, Function<V, K> keyExtractor) { return mapToMap(valueCollection, keyExtractor, Function.identity()); } 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> mapToValues(Collection<V> valueCollection, Function<V, K> keyExtractor) { return mapToMap(valueCollection, keyExtractor, Function.identity()); } 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);  }