Package com.webmethods.caf.common
Class ListTools
java.lang.Object
com.webmethods.caf.common.ListTools
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
Inner class that iterates through enumerations. -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected static void
Auxiliary method for stringToMapInternal().static String
ConvertsCollection
toString
.protected static String
Escape list csv string value.protected static String
Escape csv string value.protected static String
escapeValue
(Object v, Pattern p) Escape csv string value.static Collection
ConvertsIterator
toCollection
.static List
static String
static String
listToString
(List l) protected static String
Convert list to string comma separatedprotected static String
Protected class used to convert a list to strings for all systems except IBM VM's.static List
static String
mapToString
(Map m) static Collection
ConvertsIterator
toCollection
.static List
static String
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 returnedThis 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 returnedstringToMap
(String aString) protected static String
Unescape csv string value.protected static String
Unescape csv string value.
-
Field Details
-
RE_ESCAPE_LIST_VALUE
-
RE_ESCAPE_MAP_VALUE
-
-
Constructor Details
-
ListTools
public ListTools()
-
-
Method Details
-
stringToList
ConvertsString
toList
.- Split string on ','. (except when escaped by '\\': "\\,").
- Trim whitespace from each sub-string.
- Add each sub-string to list, including empty sub-strings.
- Parameters:
s
- String or null.- Returns:
- Non-null immutable list.
- See Also:
-
unescapeValue
Unescape csv string value.- Parameters:
v
- CSV string input- Returns:
- unescape value from CSV string
-
unescapeValue
Unescape csv string value.- Parameters:
b
- CSV string input String Builder- Returns:
- unescape value from CSV string
-
iteratorToList
- Parameters:
i
- Iterator or null.- Returns:
- Non-null immutable list.
-
mapToList
ConvertsMap
toList
. 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
- Parameters:
o
- Object or null.- Returns:
- Non-null immutable list.
-
iteratorToCollection
ConvertsIterator
toCollection
.- Parameters:
i
- Iterator or null.- Returns:
- Non-null immutable list.
-
objectToCollection
- Parameters:
o
- Object or null.- Returns:
- Non-null immutable list.
-
stringToMap
ConvertsString
toMap
.- Split string on ','. (except when escaped by '\\': "\\,").
- Split sub-strings on '=' into name,value pairs.
- If the name or the value contains "\\=", convert it to '='.
- Trim whitespace from each name and value.
- 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
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
ConvertsList
toString
.- Convert each item in list to string (convert nulls to "").
- Convert ',' char to "\\,".
- Concatonate items with ','.
- Parameters:
l
- List or null.- Returns:
- Non-null string.
- See Also:
-
listToString_sun
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
Convert list to string comma separated- Parameters:
l
- list or null- Returns:
- string representation of l
-
escapeListValue
Escape list csv string value. -
escapeMapValue
Escape csv string value. -
escapeValue
Escape csv string value. -
mapToString
ConvertsMap
toString
.- Convert each entry in the map to a name=value string (convert nulls to "").
- Convert ',' char to "\\,".
- Convert '=' char to "\\=".
- Concatenate entries with ','.
- Parameters:
m
- Map or null.- Returns:
- Non-null string.
- See Also:
-
iteratorToString
ConvertsIterator
toString
.- Convert each item in the list to a string (convert nulls to "").
- Convert ',' char to "\\,".
- Concatenate entries with ','.
- Parameters:
i
- Iterator or null.- Returns:
- Non-null string.
- See Also:
-
collectionToString
ConvertsCollection
toString
.- Convert each item in the list to a string (convert nulls to "").
- Convert ',' char to "\\,".
- Concatenate entries with ','.
- Parameters:
c
- Colection or null.- Returns:
- Non-null string.
- See Also:
-
objectToString
- Parameters:
o
- Object or null.- Returns:
- Non-null string.
- See Also:
-
splitArray
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 splitchunkSize
- - size of each array- Returns:
- - an ArrayList containing smaller subsets of @array
-
splitList
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 splitchunkSize
- - size of each array- Returns:
- - an ArrayList containing smaller subsets of @list
-