Class CollectionHelper

    • Method Detail

      • size

        public static Integer size​(Object value)
        Returns the size of the collection if it can be determined to be a collection
        Parameters:
        value - the collection
        Returns:
        the size, or null if not a collection
      • appendValue

        public static void appendValue​(Map<String,​Object> map,
                                       String key,
                                       Object value)
        Sets the value of the entry in the map for the given key, though if the map already contains a value for the given key then the value is appended to a list of values.
        Parameters:
        map - the map to add the entry to
        key - the key in the map
        value - the value to put in the map
      • flattenKeysInMap

        public static Map<String,​ObjectflattenKeysInMap​(Map<String,​Object> map,
                                                                String separator)
        Traverses the given map recursively and flattern the keys by combining them with the optional separator.
        Parameters:
        map - the map
        separator - optional separator to use in key name, for example a hyphen or dot.
        Returns:
        the map with flattern keys
      • unmodifiableMap

        public static <K,​V> Map<K,​V> unmodifiableMap​(Map<K,​V> map)
        Build an unmodifiable map on top of a given map. Note tha thew given map is copied if not null.
        Parameters:
        map - a map
        Returns:
        an unmodifiable map.
      • mapOf

        public static <K,​V> Map<K,​V> mapOf​(Supplier<Map<K,​V>> creator,
                                                       K key,
                                                       V value,
                                                       Object... keyVals)
        Build a map from varargs.
      • immutableMapOf

        public static <K,​V> Map<K,​V> immutableMapOf​(Supplier<Map<K,​V>> creator,
                                                                K key,
                                                                V value,
                                                                Object... keyVals)
        Build an immutable map from varargs.
      • mapOf

        public static <K,​V> Map<K,​V> mapOf​(K key,
                                                       V value,
                                                       Object... keyVals)
        Build a map from varargs.
      • immutableMapOf

        public static <K,​V> Map<K,​V> immutableMapOf​(K key,
                                                                V value,
                                                                Object... keyVals)
        Build an immutable map from varargs.
      • mergeMaps

        @SafeVarargs
        public static <K,​V> Map<K,​V> mergeMaps​(Map<K,​V> map,
                                                           Map<K,​V>... maps)
        Build a new map that is the result of merging the given list of maps.