@Test void testAsHashMapWithNull() { List<String> strings = Arrays.asList("1", "2", "3"); assertEquals(Collections.EMPTY_MAP, CollectionUtil.asHashMap(null, null), "Calling with null should result in an empty map"); assertEquals(Collections.EMPTY_MAP, CollectionUtil.asHashMap(Collections.emptyList(), null), "Calling with an empty list shall result in an empty map"); assertEquals(Collections.EMPTY_MAP, CollectionUtil.asHashMap(strings, null), "Calling with a list and no extractor shall result in an empty map"); }
public static <K, V> Map<K, V> asHashMap(List<V> list, ListExtractor<K, V> extractor) { if (list == null || extractor == null || list.isEmpty()) { return Collections.emptyMap(); } Map<K, V> map = new LinkedHashMap<>(list.size()); for (V node : list) { map.put(extractor.extractKey(node), extractor.extractValue(node)); } return map; }
CollectionUtil { public static <K, V> Map<K, V> asHashMap(List<V> list, ListExtractor<K, V> extractor) { if (list == null || extractor == null || list.isEmpty()) { return Collections.emptyMap(); } Map<K, V> map = new LinkedHashMap<>(list.size()); for (V node : list) { map.put(extractor.extractKey(node), extractor.extractValue(node)); } return map; } }
CollectionUtil { public static <K, V> Map<K, V> asHashMap(List<V> list, ListExtractor<K, V> extractor) { if (list == null || extractor == null || list.isEmpty()) { return Collections.emptyMap(); } Map<K, V> map = new LinkedHashMap<>(list.size()); for (V node : list) { map.put(extractor.extractKey(node), extractor.extractValue(node)); } return map; } private  CollectionUtil(); }
CollectionUtil { public static <K, V> Map<K, V> asHashMap(List<V> list, ListExtractor<K, V> extractor) { if (list == null || extractor == null || list.isEmpty()) { return Collections.emptyMap(); } Map<K, V> map = new LinkedHashMap<>(list.size()); for (V node : list) { map.put(extractor.extractKey(node), extractor.extractValue(node)); } return map; } private  CollectionUtil(); static T getFirstOrNull(List<T> list); static Map<K, V> asHashMap(List<V> list, ListExtractor<K, V> extractor); }
CollectionUtil { public static <K, V> Map<K, V> asHashMap(List<V> list, ListExtractor<K, V> extractor) { if (list == null || extractor == null || list.isEmpty()) { return Collections.emptyMap(); } Map<K, V> map = new LinkedHashMap<>(list.size()); for (V node : list) { map.put(extractor.extractKey(node), extractor.extractValue(node)); } return map; } private  CollectionUtil(); static T getFirstOrNull(List<T> list); static Map<K, V> asHashMap(List<V> list, ListExtractor<K, V> extractor);  }