Class CollectionUtils


  • public class CollectionUtils
    extends Object
    This class provides collections related helper methods.
    • Method Detail

      • putSetIntoMap

        public static Set<String> putSetIntoMap​(String key,
                                                Map<String,​Set<String>> map,
                                                String value)
        Returns set of string. This is a convenient method for adding a set of string into a map. In this project, we usually have the Map<String, Set<String>> and many times, we just want to add a string to the map.
        Parameters:
        key - Key to the entry in the map.
        map - Map of String to Set of String.
        value - Value to be added to the map referenced by key.
        Returns:
        Set of string.
      • parseStringToMap

        public static Map<String,​Set<String>> parseStringToMap​(String str)
        Returns a map of String to Set of String from a formatted string. The format is
         <key1>=<value11>,<value12>...,<value13>;
         <key2>=<value21>,<value22>...,<value23>; ...
         <keyn>=<valuen1>,<valuen2>...,<valuen3>
         
        Parameters:
        str - Formatted String.
        Returns:
        a map of String to Set of String
      • parseStringToSet

        public static Set<String> parseStringToSet​(String str)
        Returns a Set of String from a formatted string. The format is
         <value1>,<value2>...,<value3>
         
        Parameters:
        str - Formatted String.
        Returns:
        a map of String to Set of String
      • cloneMap

        public static Map<String,​Set<String>> cloneMap​(Map<String,​Set<String>> map)
        Returns a cloned Map of String to Set of String.
        Parameters:
        map - Map to be cloned.
        Returns:
        cloned map.
      • getEmptyValuesMap

        public static Map<String,​Set<String>> getEmptyValuesMap​(Set<String> keys)
        Returns a Map of String to empty set.
        Parameters:
        keys - Keys of the map.
        Returns:
        Map of String to empty set.