Class MapEntryUtils

    • Method Detail

      • size

        public static int size​(Map<?,​?> m)
      • isEmpty

        public static boolean isEmpty​(Map<?,​?> m)
      • isNotEmpty

        public static boolean isNotEmpty​(Map<?,​?> m)
      • flipMap

        public static <K,​V,​M extends Map<V,​K>> M flipMap​(Map<? extends K,​? extends V> map,
                                                                           Supplier<? extends M> mapCreator,
                                                                           boolean allowDuplicates)
        Flips between keys and values of an input map
        Type Parameters:
        K - Original map key type
        V - Original map value type
        M - Flipped map type
        Parameters:
        map - The original map to flip
        mapCreator - The creator of the target map
        allowDuplicates - Whether to ignore duplicates on flip
        Returns:
        The flipped map result
        Throws:
        IllegalArgumentException - if allowDuplicates is false and a duplicate value found in the original map.
      • mapValues

        @SafeVarargs
        public static <K,​V,​M extends Map<K,​V>> M mapValues​(Function<? super V,​? extends K> keyMapper,
                                                                             Supplier<? extends M> mapCreator,
                                                                             V... values)
      • mapValues

        public static <K,​V,​M extends Map<K,​V>> M mapValues​(Function<? super V,​? extends K> keyMapper,
                                                                             Supplier<? extends M> mapCreator,
                                                                             Collection<? extends V> values)
        Creates a map out of a group of values
        Type Parameters:
        K - The key type
        V - The value type
        M - The result Map type
        Parameters:
        keyMapper - The Function that generates a key for a given value. If the returned key is null then the value is not mapped
        mapCreator - The Supplier used to create/retrieve the result map - provided non-empty group of values
        values - The values to be mapped
        Returns:
        The resulting Map - Note: no validation is made to ensure that 2 (or more) values are not mapped to the same key
      • toSortedMap

        public static <T,​K,​U> NavigableMap<K,​U> toSortedMap​(Iterable<? extends T> values,
                                                                              Function<? super T,​? extends K> keyMapper,
                                                                              Function<? super T,​? extends U> valueMapper,
                                                                              Comparator<? super K> comparator)
      • throwingMerger

        public static <T> BinaryOperator<T> throwingMerger()