Class MapEntryUtils


  • public final class MapEntryUtils
    extends java.lang.Object
    Represents an un-modifiable pair of values
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private static java.util.Comparator<java.util.Map.Entry<java.lang.Comparable,​?>> BY_KEY_COMPARATOR  
      private static java.util.function.Supplier CASE_INSENSITIVE_MAP_FACTORY  
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private MapEntryUtils()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static <K extends java.lang.Comparable<K>,​V>
      java.util.Comparator<java.util.Map.Entry<K,​V>>
      byKeyEntryComparator()  
      static <V> java.util.function.Supplier<java.util.NavigableMap<java.lang.String,​V>> caseInsensitiveMap()  
      static <K,​V,​M extends java.util.Map<V,​K>>
      M
      flipMap​(java.util.Map<? extends K,​? extends V> map, java.util.function.Supplier<? extends M> mapCreator, boolean allowDuplicates)
      Flips between keys and values of an input map
      static boolean isEmpty​(java.util.Map<?,​?> m)  
      static boolean isNotEmpty​(java.util.Map<?,​?> m)  
      static <K,​V,​M extends java.util.Map<K,​V>>
      M
      mapValues​(java.util.function.Function<? super V,​? extends K> keyMapper, java.util.function.Supplier<? extends M> mapCreator, java.util.Collection<? extends V> values)
      Creates a map out of a group of values
      static <K,​V,​M extends java.util.Map<K,​V>>
      M
      mapValues​(java.util.function.Function<? super V,​? extends K> keyMapper, java.util.function.Supplier<? extends M> mapCreator, V... values)  
      static int size​(java.util.Map<?,​?> m)  
      static <T> java.util.function.BinaryOperator<T> throwingMerger()  
      static <T,​K,​U>
      java.util.NavigableMap<K,​U>
      toSortedMap​(java.lang.Iterable<? extends T> values, java.util.function.Function<? super T,​? extends K> keyMapper, java.util.function.Function<? super T,​? extends U> valueMapper, java.util.Comparator<? super K> comparator)  
      static <T,​K,​U>
      java.util.stream.Collector<T,​?,​java.util.NavigableMap<K,​U>>
      toSortedMap​(java.util.function.Function<? super T,​? extends K> keyMapper, java.util.function.Function<? super T,​? extends U> valueMapper, java.util.Comparator<? super K> comparator)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • BY_KEY_COMPARATOR

        private static final java.util.Comparator<java.util.Map.Entry<java.lang.Comparable,​?>> BY_KEY_COMPARATOR
      • CASE_INSENSITIVE_MAP_FACTORY

        private static final java.util.function.Supplier CASE_INSENSITIVE_MAP_FACTORY
    • Constructor Detail

      • MapEntryUtils

        private MapEntryUtils()
    • Method Detail

      • byKeyEntryComparator

        public static <K extends java.lang.Comparable<K>,​V> java.util.Comparator<java.util.Map.Entry<K,​V>> byKeyEntryComparator()
        Type Parameters:
        K - The Comparable key type
        V - The associated entry value
        Returns:
        A Comparator for Map.Entry-ies that compares the key values
      • size

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

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

        public static boolean isNotEmpty​(java.util.Map<?,​?> m)
      • caseInsensitiveMap

        public static <V> java.util.function.Supplier<java.util.NavigableMap<java.lang.String,​V>> caseInsensitiveMap()
        Type Parameters:
        V - Type of mapped value
        Returns:
        A Supplier that returns a new NavigableMap whenever its get() method is invoked
      • flipMap

        public static <K,​V,​M extends java.util.Map<V,​K>> M flipMap​(java.util.Map<? extends K,​? extends V> map,
                                                                                     java.util.function.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:
        java.lang.IllegalArgumentException - if allowDuplicates is false and a duplicate value found in the original map.
      • mapValues

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

        public static <K,​V,​M extends java.util.Map<K,​V>> M mapValues​(java.util.function.Function<? super V,​? extends K> keyMapper,
                                                                                       java.util.function.Supplier<? extends M> mapCreator,
                                                                                       java.util.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> java.util.NavigableMap<K,​U> toSortedMap​(java.lang.Iterable<? extends T> values,
                                                                                        java.util.function.Function<? super T,​? extends K> keyMapper,
                                                                                        java.util.function.Function<? super T,​? extends U> valueMapper,
                                                                                        java.util.Comparator<? super K> comparator)
      • toSortedMap

        public static <T,​K,​U> java.util.stream.Collector<T,​?,​java.util.NavigableMap<K,​U>> toSortedMap​(java.util.function.Function<? super T,​? extends K> keyMapper,
                                                                                                                                    java.util.function.Function<? super T,​? extends U> valueMapper,
                                                                                                                                    java.util.Comparator<? super K> comparator)
      • throwingMerger

        public static <T> java.util.function.BinaryOperator<T> throwingMerger()