Class Maps

java.lang.Object
com.landawn.abacus.util.Maps

public final class Maps extends Object

Note: This class includes codes copied from Apache Commons Lang, Google Guava and other open source projects under the Apache License 2.0. The methods copied from other libraries/frameworks/projects may be modified in this class.

See Also:
  • Method Details

    • create

      public static <T, K> Map<K,T> create(Collection<? extends T> c, Function<? super T,? extends K> keyMapper)
      Type Parameters:
      T -
      K - the key type
      Parameters:
      c -
      keyMapper -
      Returns:
    • create

      public static <T, K, V> Map<K,V> create(Collection<? extends T> c, Function<? super T,? extends K> keyMapper, Function<? super T,? extends V> valueExtractor)
      Type Parameters:
      T -
      K - the key type
      V - the value type
      Parameters:
      c -
      keyMapper -
      valueExtractor -
      Returns:
    • create

      public static <T, K, V, M extends Map<K, V>> M create(Collection<? extends T> c, Function<? super T,? extends K> keyMapper, Function<? super T,? extends V> valueExtractor, IntFunction<? extends M> mapSupplier)
      Type Parameters:
      T -
      K - the key type
      V - the value type
      M -
      Parameters:
      c -
      keyMapper -
      valueExtractor -
      mapSupplier -
      Returns:
    • create

      public static <T, K, V, M extends Map<K, V>> M create(Collection<? extends T> c, Function<? super T,? extends K> keyMapper, Function<? super T,? extends V> valueExtractor, BinaryOperator<V> mergeFunction, IntFunction<? extends M> mapSupplier)
      Type Parameters:
      T -
      K -
      V -
      M -
      Parameters:
      c -
      keyMapper -
      valueExtractor -
      mergeFunction -
      mapSupplier -
      Returns:
    • create

      public static <T, K> Map<K,T> create(Iterator<? extends T> iter, Function<? super T,K> keyMapper)
      Type Parameters:
      T -
      K - the key type
      Parameters:
      iter -
      keyMapper -
      Returns:
    • create

      public static <T, K, V> Map<K,V> create(Iterator<? extends T> iter, Function<? super T,K> keyMapper, Function<? super T,? extends V> valueExtractor)
      Type Parameters:
      T -
      K - the key type
      V - the value type
      Parameters:
      iter -
      keyMapper -
      valueExtractor -
      Returns:
    • create

      public static <T, K, V, M extends Map<K, V>> M create(Iterator<? extends T> iter, Function<? super T,K> keyMapper, Function<? super T,? extends V> valueExtractor, Supplier<? extends M> mapSupplier)
      Type Parameters:
      T -
      K - the key type
      V - the value type
      M -
      Parameters:
      iter -
      keyMapper -
      valueExtractor -
      mapSupplier -
      Returns:
    • create

      public static <T, K, V, M extends Map<K, V>> M create(Iterator<? extends T> iter, Function<? super T,K> keyMapper, Function<? super T,? extends V> valueExtractor, BinaryOperator<V> mergeFunction, Supplier<? extends M> mapSupplier)
      Type Parameters:
      T -
      K -
      V -
      M -
      Parameters:
      iter -
      keyMapper -
      valueExtractor -
      mergeFunction -
      mapSupplier -
      Returns:
    • create

      public static <K, V, V2> Map<K,V2> create(Map<? extends K,? extends V> map, Function<? super V,V2> valueMapper)
      Type Parameters:
      K -
      V -
      V2 -
      Parameters:
      map -
      valueMapper -
      Returns:
    • create

      public static <K, V, V2, M extends Map<K, V2>> M create(Map<? extends K,? extends V> map, Function<? super V,V2> valueMapper, IntFunction<? extends M> mapSupplier)
      Type Parameters:
      K -
      V -
      V2 -
      M -
      Parameters:
      map -
      valueMapper -
      mapSupplier -
      Returns:
    • newMap

      @Deprecated public static <T, K> Map<K,T> newMap(Collection<? extends T> c, Function<? super T,? extends K> keyMapper)
      Deprecated.
      Use #create(Collection<? extends T>,Function<? super T, ? extends K>) instead
      Type Parameters:
      T -
      K - the key type
      Parameters:
      c -
      keyMapper -
      Returns:
    • newMap

      @Deprecated public static <T, K, V> Map<K,V> newMap(Collection<? extends T> c, Function<? super T,? extends K> keyMapper, Function<? super T,? extends V> valueExtractor)
      Deprecated.
      Use #create(Collection<? extends T>,Function<? super T, ? extends K>,Function<? super T, ? extends V>) instead
      Type Parameters:
      T -
      K - the key type
      V - the value type
      Parameters:
      c -
      keyMapper -
      valueExtractor -
      Returns:
    • newMap

      @Deprecated public static <T, K, V, M extends Map<K, V>> M newMap(Collection<? extends T> c, Function<? super T,? extends K> keyMapper, Function<? super T,? extends V> valueExtractor, IntFunction<? extends M> mapSupplier)
      Deprecated.
      Use #create(Collection<? extends T>,Function<? super T, ? extends K>,Function<? super T, ? extends V>,IntFunction<? extends M>) instead
      Type Parameters:
      T -
      K - the key type
      V - the value type
      M -
      Parameters:
      c -
      keyMapper -
      valueExtractor -
      mapSupplier -
      Returns:
    • newMap

      @Deprecated public static <T, K, V, M extends Map<K, V>> M newMap(Collection<? extends T> c, Function<? super T,? extends K> keyMapper, Function<? super T,? extends V> valueExtractor, BinaryOperator<V> mergeFunction, IntFunction<? extends M> mapSupplier)
      Deprecated.
      Use #create(Collection<? extends T>,Function<? super T, ? extends K>,Function<? super T, ? extends V>,BinaryOperator<V>,IntFunction<? extends M>) instead
      Type Parameters:
      T -
      K -
      V -
      M -
      Parameters:
      c -
      keyMapper -
      valueExtractor -
      mergeFunction -
      mapSupplier -
      Returns:
    • newMap

      @Deprecated public static <T, K> Map<K,T> newMap(Iterator<? extends T> iter, Function<? super T,K> keyMapper)
      Deprecated.
      Use #create(Iterator<? extends T>,Throwables.Function<? super T, K, E>) instead
      Type Parameters:
      T -
      K - the key type
      Parameters:
      iter -
      keyMapper -
      Returns:
    • newMap

      @Deprecated public static <T, K, V> Map<K,V> newMap(Iterator<? extends T> iter, Function<? super T,K> keyMapper, Function<? super T,? extends V> valueExtractor)
      Deprecated.
      Use #create(Iterator<? extends T>,Throwables.Function<? super T, K, E>,Function<? super T, ? extends V>) instead
      Type Parameters:
      T -
      K - the key type
      V - the value type
      Parameters:
      iter -
      keyMapper -
      valueExtractor -
      Returns:
    • newMap

      @Deprecated public static <T, K, V, M extends Map<K, V>> M newMap(Iterator<? extends T> iter, Function<? super T,K> keyMapper, Function<? super T,? extends V> valueExtractor, Supplier<? extends M> mapSupplier)
      Deprecated.
      Use #create(Iterator<? extends T>,Throwables.Function<? super T, K, E>,Function<? super T, ? extends V>,Supplier<? extends M>) instead
      Type Parameters:
      T -
      K - the key type
      V - the value type
      M -
      Parameters:
      iter -
      keyMapper -
      valueExtractor -
      mapSupplier -
      Returns:
    • newMap

      @Deprecated public static <T, K, V, M extends Map<K, V>> M newMap(Iterator<? extends T> iter, Function<? super T,K> keyMapper, Function<? super T,? extends V> valueExtractor, BinaryOperator<V> mergeFunction, Supplier<? extends M> mapSupplier)
      Deprecated.
      Use #create(Iterator<? extends T>,Throwables.Function<? super T, K, E>,Function<? super T, ? extends V>,BinaryOperator<V>,Supplier<? extends M>) instead
      Type Parameters:
      T -
      K -
      V -
      M -
      Parameters:
      iter -
      keyMapper -
      valueExtractor -
      mergeFunction -
      mapSupplier -
      Returns:
    • newEntry

      @Deprecated public static <K, V> Map.Entry<K,V> newEntry(K key, V value)
      Deprecated.
      replaced by CommonUtil.newEntry(Object, Object)
      Type Parameters:
      K -
      V -
      Parameters:
      key -
      value -
      Returns:
    • newImmutableEntry

      @Deprecated public static <K, V> ImmutableEntry<K,V> newImmutableEntry(K key, V value)
      Deprecated.
      replaced by CommonUtil.newImmutableEntry(Object, Object)
      Type Parameters:
      K -
      V -
      Parameters:
      key -
      value -
      Returns:
    • zip

      public static <K, V> Map<K,V> zip(Collection<? extends K> keys, Collection<? extends V> values)
      Type Parameters:
      K -
      V -
      Parameters:
      keys -
      values -
      Returns:
    • zip

      public static <K, V, M extends Map<K, V>> Map<K,V> zip(Collection<? extends K> keys, Collection<? extends V> values, IntFunction<? extends M> mapSupplier)
      Type Parameters:
      K -
      V -
      M -
      Parameters:
      keys -
      values -
      mapSupplier -
      Returns:
    • zip

      public static <K, V, M extends Map<K, V>> Map<K,V> zip(Collection<? extends K> keys, Collection<? extends V> values, BinaryOperator<V> mergeFunction, IntFunction<? extends M> mapSupplier)
      Type Parameters:
      K -
      V -
      M -
      Parameters:
      keys -
      values -
      mergeFunction -
      mapSupplier -
      Returns:
    • get

      public static <K, V> u.Nullable<V> get(Map<K,? extends V> map, K key)
      Type Parameters:
      K - the key type
      V - the value type
      Parameters:
      map -
      key -
      Returns:
    • getOrDefault

      public static <K, V> V getOrDefault(Map<K,? extends V> map, K key, V defaultValue)
      Returns the value to which the specified key is mapped, or defaultValue if this map contains no mapping for the key.
      Type Parameters:
      K - the key type
      V - the value type
      Parameters:
      map -
      key -
      defaultValue -
      Returns:
    • getOrDefaultIfNull

      public static <K, V> V getOrDefaultIfNull(Map<K,? extends V> map, K key, V defaultForNull)
      Returns the value to which the specified key is mapped if it's not null, or defaultForNull if this map contains no mapping for the key or it's null.
      Type Parameters:
      K -
      V -
      Parameters:
      map -
      key -
      defaultForNull - to return if the specified map doesn't contain the specified key or the mapped value is null.
      Returns:
    • getBoolean

      public static <K> u.OptionalBoolean getBoolean(Map<? super K,?> map, K key)
      Returns an empty OptionalBoolean if the specified map is empty, or no value found by the specified key, or the value is null.
      Type Parameters:
      K -
      Parameters:
      map -
      key -
      Returns:
    • getBoolean

      public static <K> boolean getBoolean(Map<? super K,?> map, K key, boolean defaultForNull)
      Returns the mapped boolean or a boolean converted from String. defaultForNull is returned if the specified map doesn't contain the specified key or the mapped value is null.
      Type Parameters:
      K -
      Parameters:
      map -
      key -
      defaultForNull - to return if the specified map doesn't contain the specified key or the mapped value is null.
      Returns:
    • getChar

      public static <K> u.OptionalChar getChar(Map<? super K,?> map, K key)
      Returns an empty OptionalChar if the specified map is empty, or no value found by the specified key, or the value is null.
      Type Parameters:
      K -
      Parameters:
      map -
      key -
      Returns:
    • getChar

      public static <K> char getChar(Map<? super K,?> map, K key, char defaultForNull)
      Returns the mapped char or a char converted from String. defaultForNull is returned if the specified map doesn't contain the specified key or the mapped value is null.
      Type Parameters:
      K -
      Parameters:
      map -
      key -
      defaultForNull - to return if the specified map doesn't contain the specified key or the mapped value is null.
      Returns:
    • getByte

      public static <K> u.OptionalByte getByte(Map<? super K,?> map, K key)
      Returns an empty OptionalByte if the specified map is empty, or no value found by the specified key, or the value is null.
      Type Parameters:
      K -
      Parameters:
      map -
      key -
      Returns:
    • getByte

      public static <K> byte getByte(Map<? super K,?> map, K key, byte defaultForNull)
      Returns the mapped byte or a byte converted from String. defaultForNull is returned if the specified map doesn't contain the specified key or the mapped value is null.
      Type Parameters:
      K -
      Parameters:
      map -
      key -
      defaultForNull - to return if the specified map doesn't contain the specified key or the mapped value is null.
      Returns:
    • getShort

      public static <K> u.OptionalShort getShort(Map<? super K,?> map, K key)
      Returns an empty OptionalShort if the specified map is empty, or no value found by the specified key, or the value is null.
      Type Parameters:
      K -
      Parameters:
      map -
      key -
      Returns:
    • getShort

      public static <K> short getShort(Map<? super K,?> map, K key, short defaultForNull)
      Returns the mapped short or a short converted from String. defaultForNull is returned if the specified map doesn't contain the specified key or the mapped value is null.
      Type Parameters:
      K -
      Parameters:
      map -
      key -
      defaultForNull - to return if the specified map doesn't contain the specified key or the mapped value is null.
      Returns:
    • getInt

      public static <K> u.OptionalInt getInt(Map<? super K,?> map, K key)
      Returns an empty OptionalInt if the specified map is empty, or no value found by the specified key, or the value is null.
      Type Parameters:
      K -
      Parameters:
      map -
      key -
      Returns:
    • getInt

      public static <K> int getInt(Map<? super K,?> map, K key, int defaultForNull)
      Returns the mapped integer or an integer converted from String. defaultForNull is returned if the specified map doesn't contain the specified key or the mapped value is null.
      Type Parameters:
      K -
      Parameters:
      map -
      key -
      defaultForNull - to return if the specified map doesn't contain the specified key or the mapped value is null.
      Returns:
    • getLong

      public static <K> u.OptionalLong getLong(Map<? super K,?> map, K key)
      Returns an empty OptionalLong if the specified map is empty, or no value found by the specified key, or the value is null.
      Type Parameters:
      K -
      Parameters:
      map -
      key -
      Returns:
    • getLong

      public static <K> long getLong(Map<? super K,?> map, K key, long defaultForNull)
      Returns the mapped long or a long converted from String. defaultForNull is returned if the specified map doesn't contain the specified key or the mapped value is null.
      Type Parameters:
      K -
      Parameters:
      map -
      key -
      defaultForNull - to return if the specified map doesn't contain the specified key or the mapped value is null.
      Returns:
    • getFloat

      public static <K> u.OptionalFloat getFloat(Map<? super K,?> map, K key)
      Returns an empty OptionalFloat if the specified map is empty, or no value found by the specified key, or the value is null.
      Type Parameters:
      K -
      Parameters:
      map -
      key -
      Returns:
    • getFloat

      public static <K> float getFloat(Map<? super K,?> map, K key, float defaultForNull)
      Returns the mapped float or a float converted from String. defaultForNull is returned if the specified map doesn't contain the specified key or the mapped value is null.
      Type Parameters:
      K -
      Parameters:
      map -
      key -
      defaultForNull - to return if the specified map doesn't contain the specified key or the mapped value is null.
      Returns:
    • getDouble

      public static <K> u.OptionalDouble getDouble(Map<? super K,?> map, K key)
      Returns an empty OptionalDouble if the specified map is empty, or no value found by the specified key, or the value is null.
      Type Parameters:
      K -
      Parameters:
      map -
      key -
      Returns:
    • getDouble

      public static <K> double getDouble(Map<? super K,?> map, K key, double defaultForNull)
      Returns the mapped double or a double converted from String. defaultForNull is returned if the specified map doesn't contain the specified key or the mapped value is null.
      Type Parameters:
      K -
      Parameters:
      map -
      key -
      defaultForNull - to return if the specified map doesn't contain the specified key or the mapped value is null.
      Returns:
    • getString

      public static <K> u.Optional<String> getString(Map<? super K,?> map, K key)
      Returns an empty Optional<String> if the specified map is empty, or no value found by the specified key, or the value is null.
      Type Parameters:
      K -
      Parameters:
      map -
      key -
      Returns:
    • getString

      public static <K> String getString(Map<? super K,?> map, K key, String defaultForNull)
      Returns the mapped String or a String converted from N.toString(value). defaultForNull is returned if the specified map doesn't contain the specified key or the mapped value is null.
      Type Parameters:
      K -
      Parameters:
      map -
      key -
      defaultForNull - to return if the specified map doesn't contain the specified key or the mapped value is null.
      Returns:
    • get

      public static <K, T> u.Optional<T> get(Map<? super K,?> map, K key, Class<? extends T> targetType)
      Returns an empty Optional<String> if the specified map is empty, or no value found by the specified key, or the value is null.
      Node: To follow one of general design rules in Abacus, if there is a conversion behind when the source value is not assignable to the target type, put the targetType to last parameter of the method. Otherwise, put the targetTpye to the first parameter of the method.
      Type Parameters:
      K -
      T -
      Parameters:
      map -
      key -
      targetType -
      Returns:
    • get

      public static <K, T> u.Optional<T> get(Map<? super K,?> map, K key, com.landawn.abacus.type.Type<? extends T> targetType)
      Returns an empty Optional<String> if the specified map is empty, or no value found by the specified key, or the value is null.
      Node: To follow one of general design rules in Abacus, if there is a conversion behind when the source value is not assignable to the target type, put the targetType to last parameter of the method. Otherwise, put the targetTpye to the first parameter of the method.
      Type Parameters:
      K -
      T -
      Parameters:
      map -
      key -
      targetType -
      Returns:
    • get

      public static <K, T> T get(Map<? super K,?> map, K key, T defaultForNull)
      Returns the mapped T or a T converted from N.valueOf((Class<T>) defaultForNull.getClass(), N.stringOf(val)). defaultForNull is returned if the specified map doesn't contain the specified key or the mapped value is null.
      Type Parameters:
      K -
      T -
      Parameters:
      map -
      key -
      defaultForNull - to return if the specified map doesn't contain the specified key or the mapped value is null.
      Returns:
    • getOrEmptyList

      public static <K, E, V extends List<E>> List<E> getOrEmptyList(Map<K,V> map, K key)
      Returns the value to which the specified key is mapped, or an empty immutable List if this map contains no mapping for the key.
      Type Parameters:
      K - the key type
      E -
      V - the value type
      Parameters:
      map -
      key -
      Returns:
    • getOrEmptySet

      public static <K, E, V extends Set<E>> Set<E> getOrEmptySet(Map<K,V> map, K key)
      Returns the value to which the specified key is mapped, or an empty immutable Set if this map contains no mapping for the key.
      Type Parameters:
      K - the key type
      E -
      V - the value type
      Parameters:
      map -
      key -
      Returns:
    • getAndPutListIfAbsent

      public static <K, E> List<E> getAndPutListIfAbsent(Map<K,List<E>> map, K key)
      Returns the value associated with the specified key if it exists in the specified map contains, or the new put List if it's absent.
      Type Parameters:
      K - the key type
      E -
      Parameters:
      map -
      key -
      Returns:
    • getAndPutSetIfAbsent

      public static <K, E> Set<E> getAndPutSetIfAbsent(Map<K,Set<E>> map, K key)
      Returns the value associated with the specified key if it exists in the specified map contains, or the new put Set if it's absent.
      Type Parameters:
      K - the key type
      E -
      Parameters:
      map -
      key -
      Returns:
    • getAndPutLinkedHashSetIfAbsent

      public static <K, E> Set<E> getAndPutLinkedHashSetIfAbsent(Map<K,Set<E>> map, K key)
      Returns the value associated with the specified key if it exists in the specified map contains, or the new put Set if it's absent.
      Type Parameters:
      K - the key type
      E -
      Parameters:
      map -
      key -
      Returns:
    • getAndPutMapIfAbsent

      public static <K, KK, VV> Map<KK,VV> getAndPutMapIfAbsent(Map<K,Map<KK,VV>> map, K key)
      Returns the value associated with the specified key if it exists in the specified map contains, or the new put Map if it's absent.
      Type Parameters:
      K - the key type
      KK -
      VV -
      Parameters:
      map -
      key -
      Returns:
    • getIfPresentForEach

      public static <K, V> List<V> getIfPresentForEach(Map<K,? extends V> map, Collection<?> keys)
      Returns a list of values of the keys which exist in the specified Map. If the key dosn't exist in the Map, No value will be added into the returned list.
      Type Parameters:
      K - the key type
      V - the value type
      Parameters:
      map -
      keys -
      Returns:
    • getOrDefaultForEach

      public static <K, V> List<V> getOrDefaultForEach(Map<K,V> map, Collection<?> keys, V defaultValue)
      Gets the or default for each.
      Type Parameters:
      K - the key type
      V - the value type
      Parameters:
      map -
      keys -
      defaultValue -
      Returns:
    • getOrDefaultIfNullForEach

      public static <K, V> List<V> getOrDefaultIfNullForEach(Map<K,V> map, Collection<?> keys, V defaultValue)
      Type Parameters:
      K -
      V -
      Parameters:
      map -
      keys -
      defaultValue -
      Returns:
    • getByPath

      public static <T> T getByPath(Map<?,?> map, String path)
      Recursively get the values from the specified map by path. For example:
       
              Map map = N.asMap("key1", "val1");
              assertEquals("val1", Maps.getByPath(map, "key1"));
          
              map = N.asMap("key1", N.asList("val1"));
              assertEquals("val1", Maps.getByPath(map, "key1[0]"));
          
              map = N.asMap("key1", N.asSet("val1"));
              assertEquals("val1", Maps.getByPath(map, "key1[0]"));
          
              map = N.asMap("key1", N.asList(N.asLinkedHashSet("val1", "val2")));
              assertEquals("val2", Maps.getByPath(map, "key1[0][1]"));
          
              map = N.asMap("key1", N.asSet(N.asList(N.asSet("val1"))));
              assertEquals("val1", Maps.getByPath(map, "key1[0][0][0]"));
          
              map = N.asMap("key1", N.asList(N.asLinkedHashSet("val1", N.asMap("key2", "val22"))));
              assertEquals("val22", Maps.getByPath(map, "key1[0][1].key2"));
          
              map = N.asMap("key1", N.asList(N.asLinkedHashSet("val1", N.asMap("key2", N.asList("val22", N.asMap("key3", "val33"))))));
              assertEquals("val33", Maps.getByPath(map, "key1[0][1].key2[1].key3"));
          
              map = N.asMap("key1", N.asList(N.asLinkedHashSet("val1", N.asMap("key2", N.asList("val22", N.asMap("key3", "val33"))))));
              assertNull(Maps.getByPath(map, "key1[0][2].key2[1].key3"));
       
       
      Type Parameters:
      T -
      Parameters:
      map -
      path -
      Returns:
      null if there is no value found by the specified path.
    • getByPath

      public static <T> T getByPath(Map<?,?> map, String path, Class<? extends T> targetType)
      Type Parameters:
      T -
      Parameters:
      map -
      path -
      targetType -
      Returns:
      null if there is no value found by the specified path.
    • getByPathOrDefault

      public static <T> T getByPathOrDefault(Map<?,?> map, String path, T defaultValue)
      Type Parameters:
      T -
      Parameters:
      map -
      path -
      defaultValue -
      Returns:
      defaultValue if there is no value found by the specified path.
      See Also:
    • getByPathIfPresent

      public static <T> u.Nullable<T> getByPathIfPresent(Map<?,?> map, String path)
      Type Parameters:
      T -
      Parameters:
      map -
      path -
      Returns:
      an empty Nullable if there is no value found by the specified path.
    • getByPathIfPresent

      public static <T> u.Nullable<T> getByPathIfPresent(Map<?,?> map, String path, Class<? extends T> targetType)
      Type Parameters:
      T -
      Parameters:
      map -
      path -
      targetType -
      Returns:
      an empty Nullable if there is no value found by the specified path.
    • contains

      public static boolean contains(Map<?,?> map, Map.Entry<?,?> entry)
      Check if the specified Map contains the specified Entry.
      Parameters:
      map -
      entry -
      Returns:
    • contains

      public static boolean contains(Map<?,?> map, Object key, Object value)
      Parameters:
      map -
      key -
      value -
      Returns:
    • intersection

      public static <K, V> Map<K,V> intersection(Map<K,V> map, Map<? extends K,? extends V> map2)
      Type Parameters:
      K - the key type
      V - the value type
      Parameters:
      map -
      map2 -
      Returns:
    • difference

      public static <K, V> Map<K,Pair<V,u.Nullable<V>>> difference(Map<K,V> map, Map<K,V> map2)
      Type Parameters:
      K - the key type
      V - the value type
      Parameters:
      map -
      map2 -
      Returns:
    • symmetricDifference

      public static <K, V> Map<K,Pair<u.Nullable<V>,u.Nullable<V>>> symmetricDifference(Map<K,V> map, Map<K,V> map2)
      Type Parameters:
      K - the key type
      V - the value type
      Parameters:
      map -
      map2 -
      Returns:
    • putIfAbsent

      public static <K, V> V putIfAbsent(Map<K,V> map, K key, V value)
      Put if absent.
      Type Parameters:
      K - the key type
      V - the value type
      Parameters:
      map -
      key -
      value -
      Returns:
    • putIfAbsent

      public static <K, V> V putIfAbsent(Map<K,V> map, K key, Supplier<V> supplier)
      Put if absent.
      Type Parameters:
      K - the key type
      V - the value type
      Parameters:
      map -
      key -
      supplier -
      Returns:
    • remove

      public static <K, V> boolean remove(Map<K,V> map, Map.Entry<?,?> entry)
      Removes the specified entry.
      Type Parameters:
      K - the key type
      V - the value type
      Parameters:
      map -
      entry -
      Returns:
    • remove

      public static <K, V> boolean remove(Map<K,V> map, Object key, Object value)
      Type Parameters:
      K - the key type
      V - the value type
      Parameters:
      map -
      key -
      value -
      Returns:
    • removeKeys

      public static boolean removeKeys(Map<?,?> map, Collection<?> keysToRemove)
      Removes the keys.
      Parameters:
      map -
      keysToRemove -
      Returns:
      true if any key/value was removed, otherwise false.
    • removeEntries

      public static boolean removeEntries(Map<?,?> map, Map<?,?> entriesToRemove)
      The the entries from the specified Map.
      Parameters:
      map -
      entriesToRemove -
      Returns:
      true if any key/value was removed, otherwise false.
    • removeIf

      public static <K, V, E extends Exception> boolean removeIf(Map<K,V> map, Throwables.Predicate<? super Map.Entry<K,V>,E> filter) throws E
      Removes entries from the specified map by the the specified filter.
      Type Parameters:
      K - the key type
      V - the value type
      E -
      Parameters:
      map -
      filter -
      Returns:
      true if there are one or more than one entries removed from the specified map.
      Throws:
      E - the e
    • removeIfKey

      public static <K, V, E extends Exception> boolean removeIfKey(Map<K,V> map, Throwables.Predicate<? super K,E> filter) throws E
      Removes entries from the specified map by the the specified filter.
      Type Parameters:
      K - the key type
      V - the value type
      E -
      Parameters:
      map -
      filter -
      Returns:
      true if there are one or more than one entries removed from the specified map.
      Throws:
      E - the e
    • removeIfValue

      public static <K, V, E extends Exception> boolean removeIfValue(Map<K,V> map, Throwables.Predicate<? super V,E> filter) throws E
      Removes entries from the specified map by the the specified filter.
      Type Parameters:
      K - the key type
      V - the value type
      E -
      Parameters:
      map -
      filter -
      Returns:
      true if there are one or more than one entries removed from the specified map.
      Throws:
      E - the e
    • replace

      public static <K, V> boolean replace(Map<K,V> map, K key, V oldValue, V newValue)
      Type Parameters:
      K - the key type
      V - the value type
      Parameters:
      map -
      key -
      oldValue -
      newValue -
      Returns:
    • replace

      public static <K, V> V replace(Map<K,V> map, K key, V newValue)
      Type Parameters:
      K - the key type
      V - the value type
      Parameters:
      map -
      key -
      newValue -
      Returns:
    • replaceAll

      public static <K, V, E extends Exception> void replaceAll(Map<K,V> map, Throwables.BiFunction<? super K,? super V,? extends V,E> function) throws E
      Type Parameters:
      K - the key type
      V - the value type
      E -
      Parameters:
      map -
      function -
      Throws:
      E - the e
    • filter

      public static <K, V, E extends Exception> Map<K,V> filter(Map<K,V> map, Throwables.BiPredicate<? super K,? super V,E> predicate) throws E
      Type Parameters:
      K - the key type
      V - the value type
      E -
      Parameters:
      map -
      predicate -
      Returns:
      Throws:
      E - the e
    • filterByKey

      public static <K, V, E extends Exception> Map<K,V> filterByKey(Map<K,V> map, Throwables.Predicate<? super K,E> predicate) throws E
      Filter by key.
      Type Parameters:
      K - the key type
      V - the value type
      E -
      Parameters:
      map -
      predicate -
      Returns:
      Throws:
      E - the e
    • filterByValue

      public static <K, V, E extends Exception> Map<K,V> filterByValue(Map<K,V> map, Throwables.Predicate<? super V,E> predicate) throws E
      Filter by value.
      Type Parameters:
      K - the key type
      V - the value type
      E -
      Parameters:
      map -
      predicate -
      Returns:
      Throws:
      E - the e
    • invert

      public static <K, V> Map<V,K> invert(Map<K,V> map)
      Type Parameters:
      K - the key type
      V - the value type
      Parameters:
      map -
      Returns:
      See Also:
      • Multimap#invertFrom(Map, Supplier)
      • ListMultimap#invertFrom(Map)
      • ListMultimap#invertFrom(Map)
    • invert

      public static <K, V> Map<V,K> invert(Map<K,V> map, BinaryOperator<K> mergeOp)
      Type Parameters:
      K - the key type
      V - the value type
      Parameters:
      map -
      mergeOp -
      Returns:
    • flatInvert

      public static <K, V> Map<V,List<K>> flatInvert(Map<K,? extends Collection<? extends V>> map)
      Type Parameters:
      K - the key type
      V - the value type
      Parameters:
      map -
      Returns:
      See Also:
      • Multimap#flatInvertFrom(Map, Supplier)
      • ListMultimap#flatInvertFrom(Map)
      • SetMultimap#flatInvertFrom(Map)
    • flatToMap

      public static <K, V> List<Map<K,V>> flatToMap(Map<K,? extends Collection<? extends V>> map)
      {a=[1, 2, 3], b=[4, 5, 6], c=[7, 8]} -> [{a=1, b=4, c=7}, {a=2, b=5, c=8}, {a=3, b=6}].
      Type Parameters:
      K -
      V -
      Parameters:
      map -
      Returns:
    • flatten

      public static Map<String,Object> flatten(Map<String,Object> map)
      Parameters:
      map -
      Returns:
    • flatten

      public static <M extends Map<String, Object>> M flatten(Map<String,Object> map, Supplier<? extends M> mapSupplier)
      Type Parameters:
      M -
      Parameters:
      map -
      mapSupplier -
      Returns:
    • flatten

      public static <M extends Map<String, Object>> M flatten(Map<String,Object> map, String delimiter, Supplier<? extends M> mapSupplier)
      Type Parameters:
      M -
      Parameters:
      map -
      delimiter -
      mapSupplier -
      Returns:
    • unflatten

      public static Map<String,Object> unflatten(Map<String,Object> map)
      Parameters:
      map -
      Returns:
    • unflatten

      public static <M extends Map<String, Object>> M unflatten(Map<String,Object> map, Supplier<? extends M> mapSupplier)
      Type Parameters:
      M -
      Parameters:
      map -
      mapSupplier -
      Returns:
    • unflatten

      public static <M extends Map<String, Object>> M unflatten(Map<String,Object> map, String delimiter, Supplier<? extends M> mapSupplier)
      Type Parameters:
      M -
      Parameters:
      map -
      delimiter -
      mapSupplier -
      Returns:
    • merge

      public static <K, V> void merge(Map<K,V> map, K key, V value, BinaryOperator<V> remappingFunction)
      Type Parameters:
      K - the key type
      V - the value type
      Parameters:
      map -
      key -
      value -
      remappingFunction -
    • map2Bean

      public static <T> T map2Bean(Map<String,Object> m, Class<? extends T> targetClass)
      Map to bean.
      Type Parameters:
      T -
      Parameters:
      m -
      targetClass -
      Returns:
    • map2Bean

      public static <T> T map2Bean(Map<String,Object> m, boolean ignoreNullProperty, boolean ignoreUnmatchedProperty, Class<? extends T> targetClass)
      Map to bean.
      Type Parameters:
      T -
      Parameters:
      m -
      ignoreNullProperty -
      ignoreUnmatchedProperty -
      targetClass -
      Returns:
    • map2Bean

      public static <T> T map2Bean(Map<String,Object> m, Collection<String> selectPropNames, Class<? extends T> targetClass)
      Map to bean.
      Type Parameters:
      T -
      Parameters:
      m -
      selectPropNames -
      targetClass -
      Returns:
    • map2Bean

      public static <T> List<T> map2Bean(Collection<Map<String,Object>> mList, Class<? extends T> targetClass)
      Map to bean.
      Type Parameters:
      T -
      Parameters:
      mList -
      targetClass -
      Returns:
    • map2Bean

      public static <T> List<T> map2Bean(Collection<Map<String,Object>> mList, boolean igoreNullProperty, boolean ignoreUnmatchedProperty, Class<? extends T> targetClass)
      Map to bean.
      Type Parameters:
      T -
      Parameters:
      mList -
      igoreNullProperty -
      ignoreUnmatchedProperty -
      targetClass -
      Returns:
    • map2Bean

      public static <T> List<T> map2Bean(Collection<Map<String,Object>> mList, Collection<String> selectPropNames, Class<? extends T> targetClass)
      Map to bean.
      Type Parameters:
      T -
      Parameters:
      mList -
      selectPropNames -
      targetClass -
      Returns:
    • bean2Map

      public static Map<String,Object> bean2Map(Object bean)
      Bean to map.
      Parameters:
      bean -
      Returns:
    • bean2Map

      public static <M extends Map<String, Object>> M bean2Map(Object bean, IntFunction<? extends M> mapSupplier)
      Bean to map.
      Type Parameters:
      M -
      Parameters:
      bean -
      mapSupplier -
      Returns:
    • bean2Map

      public static Map<String,Object> bean2Map(Object bean, Collection<String> selectPropNames)
      Bean to map.
      Parameters:
      bean -
      selectPropNames -
      Returns:
    • bean2Map

      public static <M extends Map<String, Object>> M bean2Map(Object bean, Collection<String> selectPropNames, IntFunction<? extends M> mapSupplier)
      Bean to map.
      Type Parameters:
      M -
      Parameters:
      bean -
      selectPropNames -
      mapSupplier -
      Returns:
    • bean2Map

      public static <M extends Map<String, Object>> M bean2Map(Object bean, Collection<String> selectPropNames, NamingPolicy keyNamingPolicy, IntFunction<? extends M> mapSupplier)
      Bean to map.
      Type Parameters:
      M -
      Parameters:
      bean -
      selectPropNames -
      keyNamingPolicy -
      mapSupplier -
      Returns:
    • bean2Map

      public static <M extends Map<String, Object>> M bean2Map(M resultMap, Object bean)
      Bean to map.
      Type Parameters:
      M -
      Parameters:
      resultMap -
      bean -
      Returns:
    • bean2Map

      public static <M extends Map<String, Object>> M bean2Map(M resultMap, Object bean, Collection<String> selectPropNames)
      Bean to map.
      Type Parameters:
      M -
      Parameters:
      resultMap -
      bean -
      selectPropNames -
      Returns:
    • bean2Map

      public static <M extends Map<String, Object>> M bean2Map(M resultMap, Object bean, Collection<String> selectPropNames, NamingPolicy keyNamingPolicy)
      Bean to map.
      Type Parameters:
      M -
      Parameters:
      resultMap -
      bean -
      selectPropNames -
      keyNamingPolicy -
      Returns:
    • bean2Map

      public static Map<String,Object> bean2Map(Object bean, boolean ignoreNullProperty)
      Bean to map.
      Parameters:
      bean -
      ignoreNullProperty -
      Returns:
    • bean2Map

      public static Map<String,Object> bean2Map(Object bean, boolean ignoreNullProperty, Set<String> ignoredPropNames)
      Bean to map.
      Parameters:
      bean -
      ignoreNullProperty -
      ignoredPropNames -
      Returns:
    • bean2Map

      public static <M extends Map<String, Object>> M bean2Map(Object bean, boolean ignoreNullProperty, Set<String> ignoredPropNames, IntFunction<? extends M> mapSupplier)
      Bean to map.
      Type Parameters:
      M -
      Parameters:
      bean -
      ignoreNullProperty -
      ignoredPropNames -
      mapSupplier -
      Returns:
    • bean2Map

      public static Map<String,Object> bean2Map(Object bean, boolean ignoreNullProperty, Set<String> ignoredPropNames, NamingPolicy keyNamingPolicy)
      Bean to map.
      Parameters:
      bean -
      ignoreNullProperty -
      ignoredPropNames -
      keyNamingPolicy -
      Returns:
    • bean2Map

      public static <M extends Map<String, Object>> M bean2Map(Object bean, boolean ignoreNullProperty, Set<String> ignoredPropNames, NamingPolicy keyNamingPolicy, IntFunction<? extends M> mapSupplier)
      Bean to map.
      Type Parameters:
      M -
      Parameters:
      bean -
      ignoreNullProperty -
      ignoredPropNames -
      keyNamingPolicy -
      mapSupplier -
      Returns:
    • bean2Map

      public static <M extends Map<String, Object>> M bean2Map(M resultMap, Object bean, boolean ignoreNullProperty)
      Bean to map.
      Type Parameters:
      M -
      Parameters:
      resultMap -
      bean -
      ignoreNullProperty -
      Returns:
    • bean2Map

      public static <M extends Map<String, Object>> M bean2Map(M resultMap, Object bean, boolean ignoreNullProperty, Set<String> ignoredPropNames)
      Bean to map.
      Type Parameters:
      M -
      Parameters:
      resultMap -
      bean -
      ignoreNullProperty -
      ignoredPropNames -
      Returns:
    • bean2Map

      public static <M extends Map<String, Object>> M bean2Map(M resultMap, Object bean, boolean ignoreNullProperty, Set<String> ignoredPropNames, NamingPolicy keyNamingPolicy)
      Bean to map.
      Type Parameters:
      M -
      Parameters:
      resultMap -
      bean -
      ignoreNullProperty -
      ignoredPropNames -
      keyNamingPolicy -
      Returns:
    • deepBean2Map

      public static Map<String,Object> deepBean2Map(Object bean)
      Bean to map.
      Parameters:
      bean -
      Returns:
    • deepBean2Map

      public static <M extends Map<String, Object>> M deepBean2Map(Object bean, IntFunction<? extends M> mapSupplier)
      Bean to map.
      Type Parameters:
      M -
      Parameters:
      bean -
      mapSupplier -
      Returns:
    • deepBean2Map

      public static Map<String,Object> deepBean2Map(Object bean, Collection<String> selectPropNames)
      Bean to map.
      Parameters:
      bean -
      selectPropNames -
      Returns:
    • deepBean2Map

      public static <M extends Map<String, Object>> M deepBean2Map(Object bean, Collection<String> selectPropNames, IntFunction<? extends M> mapSupplier)
      Bean to map.
      Type Parameters:
      M -
      Parameters:
      bean -
      selectPropNames -
      mapSupplier -
      Returns:
    • deepBean2Map

      public static <M extends Map<String, Object>> M deepBean2Map(Object bean, Collection<String> selectPropNames, NamingPolicy keyNamingPolicy, IntFunction<? extends M> mapSupplier)
      Bean to map.
      Type Parameters:
      M -
      Parameters:
      bean -
      selectPropNames -
      keyNamingPolicy -
      mapSupplier -
      Returns:
    • deepBean2Map

      public static <M extends Map<String, Object>> M deepBean2Map(M resultMap, Object bean)
      Bean to map.
      Type Parameters:
      M -
      Parameters:
      resultMap -
      bean -
      Returns:
    • deepBean2Map

      public static <M extends Map<String, Object>> M deepBean2Map(M resultMap, Object bean, Collection<String> selectPropNames)
      Bean to map.
      Type Parameters:
      M -
      Parameters:
      resultMap -
      bean -
      selectPropNames -
      Returns:
    • deepBean2Map

      public static <M extends Map<String, Object>> M deepBean2Map(M resultMap, Object bean, Collection<String> selectPropNames, NamingPolicy keyNamingPolicy)
      Bean to map.
      Type Parameters:
      M -
      Parameters:
      resultMap -
      bean -
      selectPropNames -
      keyNamingPolicy -
      Returns:
    • deepBean2Map

      public static Map<String,Object> deepBean2Map(Object bean, boolean ignoreNullProperty)
      Bean to map.
      Parameters:
      bean -
      ignoreNullProperty -
      Returns:
    • deepBean2Map

      public static Map<String,Object> deepBean2Map(Object bean, boolean ignoreNullProperty, Set<String> ignoredPropNames)
      Bean to map.
      Parameters:
      bean -
      ignoreNullProperty -
      ignoredPropNames -
      Returns:
    • deepBean2Map

      public static <M extends Map<String, Object>> M deepBean2Map(Object bean, boolean ignoreNullProperty, Set<String> ignoredPropNames, IntFunction<? extends M> mapSupplier)
      Bean to map.
      Type Parameters:
      M -
      Parameters:
      bean -
      ignoreNullProperty -
      ignoredPropNames -
      mapSupplier -
      Returns:
    • deepBean2Map

      public static Map<String,Object> deepBean2Map(Object bean, boolean ignoreNullProperty, Set<String> ignoredPropNames, NamingPolicy keyNamingPolicy)
      Bean to map.
      Parameters:
      bean -
      ignoreNullProperty -
      ignoredPropNames -
      keyNamingPolicy -
      Returns:
    • deepBean2Map

      public static <M extends Map<String, Object>> M deepBean2Map(Object bean, boolean ignoreNullProperty, Set<String> ignoredPropNames, NamingPolicy keyNamingPolicy, IntFunction<? extends M> mapSupplier)
      Bean to map.
      Type Parameters:
      M -
      Parameters:
      bean -
      ignoreNullProperty -
      ignoredPropNames -
      keyNamingPolicy -
      mapSupplier -
      Returns:
    • deepBean2Map

      public static <M extends Map<String, Object>> M deepBean2Map(M resultMap, Object bean, boolean ignoreNullProperty)
      Bean to map.
      Type Parameters:
      M -
      Parameters:
      resultMap -
      bean -
      ignoreNullProperty -
      Returns:
    • deepBean2Map

      public static <M extends Map<String, Object>> M deepBean2Map(M resultMap, Object bean, boolean ignoreNullProperty, Set<String> ignoredPropNames)
      Bean to map.
      Type Parameters:
      M -
      Parameters:
      resultMap -
      bean -
      ignoreNullProperty -
      ignoredPropNames -
      Returns:
    • deepBean2Map

      public static <M extends Map<String, Object>> M deepBean2Map(M resultMap, Object bean, boolean ignoreNullProperty, Set<String> ignoredPropNames, NamingPolicy keyNamingPolicy)
      Bean to map.
      Type Parameters:
      M -
      Parameters:
      resultMap -
      bean -
      ignoreNullProperty -
      ignoredPropNames -
      keyNamingPolicy -
      Returns:
    • bean2FlatMap

      public static Map<String,Object> bean2FlatMap(Object bean)
      Bean to map.
      Parameters:
      bean -
      Returns:
    • bean2FlatMap

      public static <M extends Map<String, Object>> M bean2FlatMap(Object bean, IntFunction<? extends M> mapSupplier)
      Bean to map.
      Type Parameters:
      M -
      Parameters:
      bean -
      mapSupplier -
      Returns:
    • bean2FlatMap

      public static Map<String,Object> bean2FlatMap(Object bean, Collection<String> selectPropNames)
      Bean to map.
      Parameters:
      bean -
      selectPropNames -
      Returns:
    • bean2FlatMap

      public static <M extends Map<String, Object>> M bean2FlatMap(Object bean, Collection<String> selectPropNames, IntFunction<? extends M> mapSupplier)
      Bean to map.
      Type Parameters:
      M -
      Parameters:
      bean -
      selectPropNames -
      mapSupplier -
      Returns:
    • bean2FlatMap

      public static <M extends Map<String, Object>> M bean2FlatMap(Object bean, Collection<String> selectPropNames, NamingPolicy keyNamingPolicy, IntFunction<? extends M> mapSupplier)
      Bean to map.
      Type Parameters:
      M -
      Parameters:
      bean -
      selectPropNames -
      keyNamingPolicy -
      mapSupplier -
      Returns:
    • bean2FlatMap

      public static <M extends Map<String, Object>> M bean2FlatMap(M resultMap, Object bean)
      Bean to map.
      Type Parameters:
      M -
      Parameters:
      resultMap -
      bean -
      Returns:
    • bean2FlatMap

      public static <M extends Map<String, Object>> M bean2FlatMap(M resultMap, Object bean, Collection<String> selectPropNames)
      Bean to map.
      Type Parameters:
      M -
      Parameters:
      resultMap -
      bean -
      selectPropNames -
      Returns:
    • bean2FlatMap

      public static <M extends Map<String, Object>> M bean2FlatMap(M resultMap, Object bean, Collection<String> selectPropNames, NamingPolicy keyNamingPolicy)
      Bean to map.
      Type Parameters:
      M -
      Parameters:
      resultMap -
      bean -
      selectPropNames -
      keyNamingPolicy -
      Returns:
    • bean2FlatMap

      public static Map<String,Object> bean2FlatMap(Object bean, boolean ignoreNullProperty)
      Bean to map.
      Parameters:
      bean -
      ignoreNullProperty -
      Returns:
    • bean2FlatMap

      public static Map<String,Object> bean2FlatMap(Object bean, boolean ignoreNullProperty, Set<String> ignoredPropNames)
      Bean to map.
      Parameters:
      bean -
      ignoreNullProperty -
      ignoredPropNames -
      Returns:
    • bean2FlatMap

      public static <M extends Map<String, Object>> M bean2FlatMap(Object bean, boolean ignoreNullProperty, Set<String> ignoredPropNames, IntFunction<? extends M> mapSupplier)
      Bean to map.
      Type Parameters:
      M -
      Parameters:
      bean -
      ignoreNullProperty -
      ignoredPropNames -
      mapSupplier -
      Returns:
    • bean2FlatMap

      public static Map<String,Object> bean2FlatMap(Object bean, boolean ignoreNullProperty, Set<String> ignoredPropNames, NamingPolicy keyNamingPolicy)
      Bean to map.
      Parameters:
      bean -
      ignoreNullProperty -
      ignoredPropNames -
      keyNamingPolicy -
      Returns:
    • bean2FlatMap

      public static <M extends Map<String, Object>> M bean2FlatMap(Object bean, boolean ignoreNullProperty, Set<String> ignoredPropNames, NamingPolicy keyNamingPolicy, IntFunction<? extends M> mapSupplier)
      Bean to map.
      Type Parameters:
      M -
      Parameters:
      bean -
      ignoreNullProperty -
      ignoredPropNames -
      keyNamingPolicy -
      mapSupplier -
      Returns:
    • bean2FlatMap

      public static <M extends Map<String, Object>> M bean2FlatMap(M resultMap, Object bean, boolean ignoreNullProperty)
      Bean to map.
      Type Parameters:
      M -
      Parameters:
      resultMap -
      bean -
      ignoreNullProperty -
      Returns:
    • bean2FlatMap

      public static <M extends Map<String, Object>> M bean2FlatMap(M resultMap, Object bean, boolean ignoreNullProperty, Set<String> ignoredPropNames)
      Bean to map.
      Type Parameters:
      M -
      Parameters:
      resultMap -
      bean -
      ignoreNullProperty -
      ignoredPropNames -
      Returns:
    • bean2FlatMap

      public static <M extends Map<String, Object>> M bean2FlatMap(M resultMap, Object bean, boolean ignoreNullProperty, Set<String> ignoredPropNames, NamingPolicy keyNamingPolicy)
      Bean to map.
      Type Parameters:
      M -
      Parameters:
      resultMap -
      bean -
      ignoreNullProperty -
      ignoredPropNames -
      keyNamingPolicy -
      Returns: