类 Maps


  • public class Maps
    extends java.lang.Object
    Utils method for Map
    • 构造器概要

      构造器 
      构造器 说明
      Maps()  
    • 方法概要

      所有方法 静态方法 具体方法 
      修饰符和类型 方法 说明
      static <K,​R,​V,​U>
      java.util.Map<R,​U>
      convert​(java.util.Map<? extends K,​? extends V> map, java.util.function.Function<? super K,​? extends R> keyMapper, java.util.function.Function<? super V,​? extends U> valueMapper)
      Convert map to new immutable map, with key converted by keyMapper, and value converted by valueMapper.
      static <K,​V,​U>
      java.util.Map<K,​U>
      convert​(java.util.Map<? extends K,​? extends V> map, java.util.function.Function<? super V,​? extends U> valueMapper)
      Convert map to new immutable map, with key not modified, and value converted by function.
      static <K,​V>
      java.util.Map<K,​V>
      filter​(java.util.Map<? extends K,​? extends V> map, java.util.function.BiPredicate<? super K,​? super V> predicate)
      Filter map to new immutable map, contains the entries accepted by predicate.
      static <T,​K,​V>
      java.util.Map<K,​V>
      from​(java.util.Collection<? extends T> elements, java.util.function.Function<? super T,​? extends K> keyRetriever, java.util.function.Function<? super T,​? extends V> valueMaker)
      Create new immutable map from a collection of keys, the values are constructed by valueMaker.
      static <K,​V>
      java.util.Map<K,​V>
      fromKeys​(java.util.Collection<? extends K> keys, java.util.function.Function<? super K,​? extends V> valueMaker)
      Create new immutable map from a collection of keys, the values are constructed by valueMaker.
      static <K,​V>
      java.util.Map<K,​V>
      fromValues​(java.util.Collection<? extends V> values, java.util.function.Function<? super V,​? extends K> keyRetriever)
      Create new immutable map from a collection of values, the values are constructed by keyMaker.
      static <K,​V>
      java.util.Map<K,​V>
      merge​(java.util.Map<? extends K,​? extends V> map1, java.util.Map<? extends K,​? extends V> map2)
      Merge tow maps, to a new immutable map, contains key-value in both map.
      static <V> java.util.Map<java.lang.String,​V> newCaseInsensitiveMap()
      Create a mutable, case insensitive map.
      static <V> java.util.Map<java.lang.String,​V> newCaseInsensitiveMap​(java.util.Map.Entry<java.lang.String,​? extends V>... entries)
      Create a mutable, case insensitive map.
      static <K,​V>
      java.util.HashMap<K,​V>
      newHashMap()
      Create new HashMap.
      static <K,​V>
      java.util.HashMap<K,​V>
      newHashMap​(java.util.Map.Entry<? extends K,​? extends V>... entries)
      Create new HashMap.
      static <K,​V,​R extends java.util.Map<K,​V>>
      R
      newMap​(java.util.function.Supplier<R> supplier, java.util.Map.Entry<? extends K,​? extends V>... entries)
      For easy map creation with initial values.
      static <K,​V>
      java.util.Map<K,​V>
      nullToEmpty​(@Nullable java.util.Map<K,​V> map)
      If map is null, return immutable empty map; else return map self.
      static <K,​V>
      java.util.Map<K,​V>
      of()
      Create new immutable empty Map
      static <K,​V>
      java.util.Map<K,​V>
      of​(java.util.Map.Entry<? extends K,​? extends V> entry)
      Create new immutable Map.
      static <K,​V>
      java.util.Map<K,​V>
      of​(java.util.Map.Entry<? extends K,​? extends V>... entries)
      Create new immutable Map.
      static <K,​V>
      java.util.Map<K,​V>
      of​(java.util.Map.Entry<? extends K,​? extends V> entry1, java.util.Map.Entry<? extends K,​? extends V> entry2)
      Create new immutable Map.
      static <K,​V>
      java.util.Map<K,​V>
      of​(java.util.Map.Entry<? extends K,​? extends V> entry1, java.util.Map.Entry<? extends K,​? extends V> entry2, java.util.Map.Entry<? extends K,​? extends V> entry3)
      Create new immutable Map.
      • 从类继承的方法 java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 构造器详细资料

      • Maps

        public Maps()
    • 方法详细资料

      • nullToEmpty

        public static <K,​V> java.util.Map<K,​V> nullToEmpty​(@Nullable java.util.Map<K,​V> map)
        If map is null, return immutable empty map; else return map self.
        参数:
        map - the map
        返回:
        non-null map
      • newHashMap

        public static <K,​V> java.util.HashMap<K,​V> newHashMap()
        Create new HashMap.
      • newHashMap

        @SafeVarargs
        public static <K,​V> java.util.HashMap<K,​V> newHashMap​(java.util.Map.Entry<? extends K,​? extends V>... entries)
        Create new HashMap.
      • newCaseInsensitiveMap

        public static <V> java.util.Map<java.lang.String,​V> newCaseInsensitiveMap()
        Create a mutable, case insensitive map.
      • newCaseInsensitiveMap

        @SafeVarargs
        public static <V> java.util.Map<java.lang.String,​V> newCaseInsensitiveMap​(java.util.Map.Entry<java.lang.String,​? extends V>... entries)
        Create a mutable, case insensitive map.
      • newMap

        @SafeVarargs
        public static <K,​V,​R extends java.util.Map<K,​V>> R newMap​(java.util.function.Supplier<R> supplier,
                                                                                    java.util.Map.Entry<? extends K,​? extends V>... entries)
        For easy map creation with initial values.
        类型参数:
        K - key type
        V - value type
        参数:
        supplier - the map supplier
        entries - the entries to put into map
        返回:
        the map
      • of

        public static <K,​V> java.util.Map<K,​V> of()
        Create new immutable empty Map
      • of

        public static <K,​V> java.util.Map<K,​V> of​(java.util.Map.Entry<? extends K,​? extends V> entry)
        Create new immutable Map.
      • of

        public static <K,​V> java.util.Map<K,​V> of​(java.util.Map.Entry<? extends K,​? extends V> entry1,
                                                              java.util.Map.Entry<? extends K,​? extends V> entry2)
        Create new immutable Map.
      • of

        public static <K,​V> java.util.Map<K,​V> of​(java.util.Map.Entry<? extends K,​? extends V> entry1,
                                                              java.util.Map.Entry<? extends K,​? extends V> entry2,
                                                              java.util.Map.Entry<? extends K,​? extends V> entry3)
        Create new immutable Map.
      • of

        @SafeVarargs
        public static <K,​V> java.util.Map<K,​V> of​(java.util.Map.Entry<? extends K,​? extends V>... entries)
        Create new immutable Map.
      • convert

        public static <K,​R,​V,​U> java.util.Map<R,​U> convert​(java.util.Map<? extends K,​? extends V> map,
                                                                                   java.util.function.Function<? super K,​? extends R> keyMapper,
                                                                                   java.util.function.Function<? super V,​? extends U> valueMapper)
        Convert map to new immutable map, with key converted by keyMapper, and value converted by valueMapper.
        类型参数:
        K - the key type
        R - the target key type
        V - the original value type
        U - the target value type
        参数:
        map - the original map
        valueMapper - the function to convert map value
        返回:
        new map
      • convert

        public static <K,​V,​U> java.util.Map<K,​U> convert​(java.util.Map<? extends K,​? extends V> map,
                                                                           java.util.function.Function<? super V,​? extends U> valueMapper)
        Convert map to new immutable map, with key not modified, and value converted by function.
        类型参数:
        K - the key type
        V - the original value type
        U - the target value type
        参数:
        map - the original map
        valueMapper - the function to convert map value
        返回:
        new map
      • filter

        public static <K,​V> java.util.Map<K,​V> filter​(java.util.Map<? extends K,​? extends V> map,
                                                                  java.util.function.BiPredicate<? super K,​? super V> predicate)
        Filter map to new immutable map, contains the entries accepted by predicate.
        类型参数:
        K - the key type
        V - the value type
        参数:
        map - the origin map
        predicate - the predicate to filter map entries
        返回:
        the new map
      • merge

        public static <K,​V> java.util.Map<K,​V> merge​(java.util.Map<? extends K,​? extends V> map1,
                                                                 java.util.Map<? extends K,​? extends V> map2)
        Merge tow maps, to a new immutable map, contains key-value in both map. If map1 and map2 contains the same key, the value from map2 will be used.
        类型参数:
        K - map key type
        V - map value type
        参数:
        map1 - map1
        map2 - map2
        返回:
        new map
      • from

        public static <T,​K,​V> java.util.Map<K,​V> from​(java.util.Collection<? extends T> elements,
                                                                        java.util.function.Function<? super T,​? extends K> keyRetriever,
                                                                        java.util.function.Function<? super T,​? extends V> valueMaker)
        Create new immutable map from a collection of keys, the values are constructed by valueMaker.
        类型参数:
        K - key type
        V - value type
        参数:
        elements - the key collections
        keyRetriever - to get key from elements
        valueMaker - to make value from elements
        返回:
        new map
      • fromKeys

        public static <K,​V> java.util.Map<K,​V> fromKeys​(java.util.Collection<? extends K> keys,
                                                                    java.util.function.Function<? super K,​? extends V> valueMaker)
        Create new immutable map from a collection of keys, the values are constructed by valueMaker.
        类型参数:
        K - key type
        V - value type
        参数:
        keys - the key collections
        valueMaker - to make value from key
        返回:
        new map
      • fromValues

        public static <K,​V> java.util.Map<K,​V> fromValues​(java.util.Collection<? extends V> values,
                                                                      java.util.function.Function<? super V,​? extends K> keyRetriever)
        Create new immutable map from a collection of values, the values are constructed by keyMaker.
        类型参数:
        K - key type
        V - value type
        参数:
        values - the value collections
        keyRetriever - to get key from value
        返回:
        new map