Package snap.util

Class MapUtils

java.lang.Object
snap.util.MapUtils

public class MapUtils extends Object
Utility methods for use with Java.util.Map.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static Object
    Returns any element from a map.
    static <K, V> boolean
    boolValue(Map<K,V> aMap, K aKey)
    Returns a key value interpreted as a boolean.
    static <K, V> boolean
    boolValue(Map<K,V> aMap, K aKey, boolean defaultValue)
    Returns a key value interpreted as a boolean (with optional default value).
    static Map
    clone(Map aMap)
    Clones a map.
    static <K, V> float
    floatValue(Map<K,V> aMap, K aKey)
    Returns a key value interpreted as a float.
    static <K, V> float
    floatValue(Map<K,V> aMap, K aKey, float defaultValue)
    Returns a key value interpreted as a float (with optional default value).
    static <K, V> V
    get(Map<K,V> aMap, K aKey)
    Returns value for aKey in given map (accepts null map).
    static <K, V> V
    get(Map<K,V> aMap, K aKey, V defaultValue)
    Returns value for aKey in given map with an optional default value for missing keys.
    static Object
    getKey(Map aMap, Object aValue)
    Returns the key for a given object in the given map.
    static Object
    getKeyId(Map aMap, Object aValue)
    Returns the key for a given identical object in the given map.
    static <K, V> int
    intValue(Map<K,V> aMap, K aKey)
    Returns a key value interpreted as an int.
    static <K, V> int
    intValue(Map<K,V> aMap, K aKey, int defaultValue)
    Returns a key value interpreted as an int (with optional default value).
    static Map
    newMap(Object... theKeyValues)
    Creates a new map with given args in key/value sequence.
    static Map
    newMap(Object aKey, Object anObj)
    Creates a new map for given key and object.
    static <K, V> V
    put(Map<K,V> aMap, K aKey, V aValue)
    Adds given key and value to given map (removes key if value is null).
    static Map
    putAllIfAbsent(Map m1, Map m2, boolean copyIfAbsent)
    Same as putAll, but only adds absent keys (option to copy if there are absent keys).
    static int
    size(Map aMap)
    Returns the size of given map (accepts null map).
    static String
    Returns a string representation of map that doesn't recurse.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • MapUtils

      public MapUtils()
  • Method Details

    • newMap

      public static Map newMap(Object aKey, Object anObj)
      Creates a new map for given key and object.
    • newMap

      public static Map newMap(Object... theKeyValues)
      Creates a new map with given args in key/value sequence.
    • size

      public static int size(Map aMap)
      Returns the size of given map (accepts null map).
    • get

      public static <K, V> V get(Map<K,V> aMap, K aKey)
      Returns value for aKey in given map (accepts null map).
    • get

      public static <K, V> V get(Map<K,V> aMap, K aKey, V defaultValue)
      Returns value for aKey in given map with an optional default value for missing keys.
    • put

      public static <K, V> V put(Map<K,V> aMap, K aKey, V aValue)
      Adds given key and value to given map (removes key if value is null).
    • clone

      public static Map clone(Map aMap)
      Clones a map.
    • boolValue

      public static <K, V> boolean boolValue(Map<K,V> aMap, K aKey)
      Returns a key value interpreted as a boolean.
    • boolValue

      public static <K, V> boolean boolValue(Map<K,V> aMap, K aKey, boolean defaultValue)
      Returns a key value interpreted as a boolean (with optional default value).
    • intValue

      public static <K, V> int intValue(Map<K,V> aMap, K aKey)
      Returns a key value interpreted as an int.
    • intValue

      public static <K, V> int intValue(Map<K,V> aMap, K aKey, int defaultValue)
      Returns a key value interpreted as an int (with optional default value).
    • floatValue

      public static <K, V> float floatValue(Map<K,V> aMap, K aKey)
      Returns a key value interpreted as a float.
    • floatValue

      public static <K, V> float floatValue(Map<K,V> aMap, K aKey, float defaultValue)
      Returns a key value interpreted as a float (with optional default value).
    • putAllIfAbsent

      public static Map putAllIfAbsent(Map m1, Map m2, boolean copyIfAbsent)
      Same as putAll, but only adds absent keys (option to copy if there are absent keys).
    • getKey

      public static Object getKey(Map aMap, Object aValue)
      Returns the key for a given object in the given map.
    • getKeyId

      public static Object getKeyId(Map aMap, Object aValue)
      Returns the key for a given identical object in the given map.
    • anyElement

      public static Object anyElement(Map aMap)
      Returns any element from a map.
    • toStringSafe

      public static String toStringSafe(Map aMap)
      Returns a string representation of map that doesn't recurse.