Class ListTools

java.lang.Object
com.webmethods.caf.common.ListTools

public class ListTools extends Object
Converts Strings to Lists and vice-versa, using Property Editor rules.
  • Field Details

    • RE_ESCAPE_LIST_VALUE

      protected static final Pattern RE_ESCAPE_LIST_VALUE
    • RE_ESCAPE_MAP_VALUE

      protected static final Pattern RE_ESCAPE_MAP_VALUE
  • Constructor Details

    • ListTools

      public ListTools()
  • Method Details

    • stringToList

      public static List<String> stringToList(String s)
      Converts String to List.
      1. Split string on ','. (except when escaped by '\\': "\\,").
      2. Trim whitespace from each sub-string.
      3. Add each sub-string to list, including empty sub-strings.
      Parameters:
      s - String or null.
      Returns:
      Non-null immutable list.
      See Also:
    • unescapeValue

      protected static String unescapeValue(String v)
      Unescape csv string value.
      Parameters:
      v - CSV string input
      Returns:
      unescape value from CSV string
    • unescapeValue

      protected static String unescapeValue(StringBuilder b)
      Unescape csv string value.
      Parameters:
      b - CSV string input String Builder
      Returns:
      unescape value from CSV string
    • iteratorToList

      public static List iteratorToList(Iterator i)
      Converts Iterator to List.
      Parameters:
      i - Iterator or null.
      Returns:
      Non-null immutable list.
    • mapToList

      public static List mapToList(Map m)
      Converts Map to List. Converts each entry in map to name=value string (convert nulls to ""). Characters '=' are not converted to "\\=". They are not expected in this method.
      Parameters:
      m - Map or null.
      Returns:
      Non-null string.
      See Also:
    • objectToList

      public static List objectToList(Object o)
      Converts Iterator to List. If object is string, uses stringToList(java.lang.String).
      Parameters:
      o - Object or null.
      Returns:
      Non-null immutable list.
    • iteratorToCollection

      public static Collection iteratorToCollection(Iterator i)
      Converts Iterator to Collection.
      Parameters:
      i - Iterator or null.
      Returns:
      Non-null immutable list.
    • objectToCollection

      public static Collection objectToCollection(Object o)
      Converts Iterator to Collection. If object is string, uses stringToList(java.lang.String).
      Parameters:
      o - Object or null.
      Returns:
      Non-null immutable list.
    • stringToMap

      public static Map<String,String> stringToMap(String aString)
      Converts String to Map.
      1. Split string on ','. (except when escaped by '\\': "\\,").
      2. Split sub-strings on '=' into name,value pairs.
      3. If the name or the value contains "\\=", convert it to '='.
      4. Trim whitespace from each name and value.
      5. Add each name,value pair to a map, including those with empty names and/or values.
      Parameters:
      s - String or null.
      Returns:
      Non-null immutable map.
      See Also:
    • addToMap

      protected static void addToMap(Map aMap, String aString)
      Auxiliary method for stringToMapInternal(). Splits the string on two based on the first occurance of a non-escaped equals character '='. Adds an entry in the map based on the split. The key of the entry is the left substring of the split and the value is the right substring of the split. If there is an escaped equals character, e.g. "\\=", it is saved as a normal equals character in the key or the value of the entry. If there are other characters which are escaped via "\\", they are also converted to their normal value. Examples: "x=1": {"x" => "1"} "x=1=2": {"x" => "1=2"} "x=1\\=2": {"x" => "1=2"} "x\\=y=1\\=2": {"x=y" => "1=2"} "x1": {"x1" => ""} "x\\=1": {"x=1" => ""}
    • listToString

      public static String listToString(List l)
      Converts List to String.
      1. Convert each item in list to string (convert nulls to "").
      2. Convert ',' char to "\\,".
      3. Concatonate items with ','.
      Parameters:
      l - List or null.
      Returns:
      Non-null string.
      See Also:
    • listToString_sun

      protected static String listToString_sun(List l)
      Protected class used to convert a list to strings for all systems except IBM VM's.
      Parameters:
      l - list or null
      Returns:
      Non-null string
    • listToString_ibm

      protected static String listToString_ibm(List l)
      Convert list to string comma separated
      Parameters:
      l - list or null
      Returns:
      string representation of l
    • escapeListValue

      protected static String escapeListValue(Object v)
      Escape list csv string value.
    • escapeMapValue

      protected static String escapeMapValue(Object v)
      Escape csv string value.
    • escapeValue

      protected static String escapeValue(Object v, Pattern p)
      Escape csv string value.
    • mapToString

      public static String mapToString(Map m)
      Converts Map to String.
      1. Convert each entry in the map to a name=value string (convert nulls to "").
      2. Convert ',' char to "\\,".
      3. Convert '=' char to "\\=".
      4. Concatenate entries with ','.
      Parameters:
      m - Map or null.
      Returns:
      Non-null string.
      See Also:
    • iteratorToString

      public static String iteratorToString(Iterator i)
      Converts Iterator to String.
      1. Convert each item in the list to a string (convert nulls to "").
      2. Convert ',' char to "\\,".
      3. Concatenate entries with ','.
      Parameters:
      i - Iterator or null.
      Returns:
      Non-null string.
      See Also:
    • collectionToString

      public static String collectionToString(Collection c)
      Converts Collection to String.
      1. Convert each item in the list to a string (convert nulls to "").
      2. Convert ',' char to "\\,".
      3. Concatenate entries with ','.
      Parameters:
      c - Colection or null.
      Returns:
      Non-null string.
      See Also:
    • objectToString

      public static String objectToString(Object o)
      Converts Object to String. If object is collection, uses collectionToString(java.util.Collection).
      Parameters:
      o - Object or null.
      Returns:
      Non-null string.
      See Also:
    • splitArray

      public static <T> List<T[]> splitArray(T[] array, int chunkSize)
      This method takes in an array of any type and a chunkSize It returns an ArrayList containing a subset of smaller arrays(chunkSize) If chunkSize is <=0 or bigger than array.length, an ArrayList containing only @array is returned if @array is null or @array length is <=0 an empty ArrayList is returned
      Type Parameters:
      T - - type of array
      Parameters:
      array - - array to split
      chunkSize - - size of each array
      Returns:
      - an ArrayList containing smaller subsets of @array
    • splitList

      public static <T> List<List<T>> splitList(List<T> list, int chunkSize)
      This method takes in a list of any type and a chunkSize It returns an ArrayList containing a subset of smaller lists(chunkSize) If chunkSize is <=0 or bigger than array.length, an ArrayList containing only @array is returned if @list is null or @list length is <=0 an empty ArrayList is returned
      Type Parameters:
      T - - type of the list
      Parameters:
      list - - list to split
      chunkSize - - size of each array
      Returns:
      - an ArrayList containing smaller subsets of @list