/** * Return a collector that creates a LinkedHashMap using the given key and value functions. * This collector assumes the elements being collected are distinct. * * @param <S> Type of the objects being collected * @param <K> Type of the keys * @param <V> Type of the values * @param keyMapper Mapping function for the key * @param valueMapper Mapping function for the value * * @return a collector that creates a LinkedHashMap using the given key and value functions. * @throws IllegalStateException if multiple values are associated with the same key * @see Collectors#toMap(Function, Function, BinaryOperator, java.util.function.Supplier) */ public static <S, K, V> Collector<S, ?, LinkedHashMap<K, V>> toLinkedMap( Function<? super S, ? extends K> keyMapper, Function<? super S, ? extends V> valueMapper ) { return Collectors.toMap(keyMapper, valueMapper, StreamUtils.throwingMerger(), LinkedHashMap::new); }
/** * Return a collector that creates a LinkedHashMap dictionary using the given key function. * This collector assumes the elements being collected are distinct. * * @param <S> Type of the objects being collected and the values of the dictionary / map * @param <K> Type of the keys * @param keyMapper Mapping function for the key * * @return a collector that creates a LinkedHashMap dictionary using the given key function. * @throws IllegalStateException if multiple values are associated with the same key * @see Collectors#toMap(Function, Function, BinaryOperator, java.util.function.Supplier) */ public static <S, K> Collector<S, ?, LinkedHashMap<K, S>> toLinkedDictionary( Function<? super S, ? extends K> keyMapper ) { return Collectors.toMap(keyMapper, Function.identity(), StreamUtils.throwingMerger(), LinkedHashMap::new); }
/** * Return a collector that creates a {@link java.util.Map} using the given key and value functions. * This collector assumes the elements being collected are distinct. * <p> * The concrete type of the {@link java.util.Map} being created is given by a {@link java.util.function.Supplier}. * * @param <S> Type of the objects being collected * @param <K> Type of the keys * @param <V> Type of the values * @param <M> The type of Map being collected into * @param keyMapper Mapping function for the key * @param valueMapper Mapping function for the value * @param mapSupplier A {@link java.util.function.Supplier} which provides a new, empty {@link java.util.Map} into * which the results will be inserted * * @return a collector that creates a {@link java.util.Map} using the given key and value functions * @throws IllegalStateException if multiple values are associated with the same key * @see Collectors#toMap(Function, Function, BinaryOperator, java.util.function.Supplier) */ public static <S, K, V, M extends Map<K, V>> Collector<S, ?, M> toMap( Function<? super S, ? extends K> keyMapper, Function<? super S, ? extends V> valueMapper, Supplier<M> mapSupplier ) { return Collectors.toMap(keyMapper, valueMapper, StreamUtils.throwingMerger(), mapSupplier); }
/** * Return a collector that creates a dictionary using the given key function and the given map supplier. * This collector assumes the elements being collected are distinct. * * @param <S> Type of the objects being collected and the values of the dictionary / map * @param <K> Type of the keys * @param <M> The type of Map being collected into * @param keyMapper Mapping function for the key * @param mapSupplier A {@link java.util.function.Supplier} which provides a new, empty {@link java.util.Map} into * which the results will be inserted * * @return a {@link java.util.stream.Collector} that creates a dictionary using the given * {@link java.util.function.Function key function} and the given {@link java.util.function.Supplier map supplier} * @throws IllegalStateException if multiple values are associated with the same key * @see Collectors#toMap(Function, Function, BinaryOperator, java.util.function.Supplier) */ public static <S, K, M extends Map<K, S>> Collector<S, ?, M> toDictionary( Function<? super S, ? extends K> keyMapper, Supplier<M> mapSupplier ) { return Collectors.toMap(keyMapper, Function.identity(), StreamUtils.throwingMerger(), mapSupplier); }