Package org.supercsv.util
Class Util
java.lang.Object
org.supercsv.util.Util
Useful utility methods.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic void
executeCellProcessors
(List<Object> destination, List<?> source, CellProcessor[] processors, int lineNo, int rowNo) Processes each element in the source List (using the corresponding processor chain in the processors array) and adds it to the destination List.static <T> void
filterListToMap
(Map<String, T> destinationMap, String[] nameMapping, List<? extends T> sourceList) Converts a List to a Map using the elements of the nameMapping array as the keys of the Map.filterMapToList
(Map<String, ?> map, String[] nameMapping) Returns a List of all of the values in the Map whose key matches an entry in the nameMapping array.static Object[]
filterMapToObjectArray
(Map<String, ?> values, String[] nameMapping) Converts a Map to an array of objects, adding only those entries whose key is in the nameMapping array.static String[]
objectArrayToStringArray
(Object[] objectArray) Converts an Object array to a String array (null-safe), by calling toString() on each element.static String[]
objectListToStringArray
(List<?> objectList) Converts anList<Object>
to a String array (null-safe), by callingtoString()
on each element.
-
Constructor Details
-
Util
private Util()
-
-
Method Details
-
executeCellProcessors
public static void executeCellProcessors(List<Object> destination, List<?> source, CellProcessor[] processors, int lineNo, int rowNo) Processes each element in the source List (using the corresponding processor chain in the processors array) and adds it to the destination List. A null CellProcessor in the array indicates that no processing is required and the element should be added as-is.- Parameters:
destination
- the List to add the processed elements to (which is cleared before it's populated)source
- the List of source elements to be processedprocessors
- the array of CellProcessors used to process each element. The number of elements in this array must match the size of the source List. A null CellProcessor in this array indicates that no processing is required and the element should be added as-is.lineNo
- the current line numberrowNo
- the current row number- Throws:
NullPointerException
- if destination, source or processors is nullSuperCsvConstraintViolationException
- if a CellProcessor constraint failedSuperCsvException
- if source.size() != processors.length, or CellProcessor execution failed
-
filterListToMap
public static <T> void filterListToMap(Map<String, T> destinationMap, String[] nameMapping, List<? extends T> sourceList) Converts a List to a Map using the elements of the nameMapping array as the keys of the Map.- Type Parameters:
T
- the type of the values in the map- Parameters:
destinationMap
- the destination Map (which is cleared before it's populated)nameMapping
- the keys of the Map (corresponding with the elements in the sourceList). Cannot contain duplicates.sourceList
- the List to convert- Throws:
NullPointerException
- if destinationMap, nameMapping or sourceList are nullSuperCsvException
- if nameMapping and sourceList are not the same size
-
filterMapToList
Returns a List of all of the values in the Map whose key matches an entry in the nameMapping array.- Parameters:
map
- the mapnameMapping
- the keys of the Map values to add to the List- Returns:
- a List of all of the values in the Map whose key matches an entry in the nameMapping array
- Throws:
NullPointerException
- if map or nameMapping is null
-
filterMapToObjectArray
Converts a Map to an array of objects, adding only those entries whose key is in the nameMapping array.- Parameters:
values
- the Map of values to convertnameMapping
- the keys to extract from the Map (elements in the target array will be added in this order)- Returns:
- the array of Objects
- Throws:
NullPointerException
- if values or nameMapping is null
-
objectArrayToStringArray
Converts an Object array to a String array (null-safe), by calling toString() on each element.- Parameters:
objectArray
- the Object array- Returns:
- the String array, or null if objectArray is null
-
objectListToStringArray
Converts anList<Object>
to a String array (null-safe), by callingtoString()
on each element.- Parameters:
objectList
- the List- Returns:
- the String array, or null if objectList is null
-