Package org.genesys.geotools.service
Class HeaderUtils
- java.lang.Object
-
- org.genesys.geotools.service.HeaderUtils
-
public abstract class HeaderUtils extends Object
Helper for CSV header management.
-
-
Constructor Summary
Constructors Constructor Description HeaderUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static Map<String,Integer>makeSourceMapping(String[] headers, String[] supportedHeaders)We are mostly interested in only a few supported headers.static List<Integer>mapHeaderPositions(String[] headers)Map CSV headers to their positions.static voidthrowIfHeaderFound(String[] headers, String[] notAllowedHeaders)Check for invalid headers and throw IOException if one is found.static voidthrowIfHeaderNotFound(String[] headers, String[] requiredHeaders)Check for required headers and throw IOException if one is missing.static String[]toOutputLine(String[] nextLine, List<String> outputHeaders, List<Integer> outputMapping)Copy data from input CSV line to output CSV line with appropriate destination mapping.
-
-
-
Method Detail
-
throwIfHeaderFound
public static void throwIfHeaderFound(String[] headers, String[] notAllowedHeaders) throws IOException
Check for invalid headers and throw IOException if one is found.- Parameters:
headers- input headersnotAllowedHeaders- array of unacceptable headers- Throws:
IOException- when one unacceptable header is found
-
throwIfHeaderNotFound
public static void throwIfHeaderNotFound(String[] headers, String[] requiredHeaders) throws IOException
Check for required headers and throw IOException if one is missing.- Parameters:
headers- input headersrequiredHeaders- the array of required headers- Throws:
IOException- when one unacceptable header is found
-
mapHeaderPositions
public static List<Integer> mapHeaderPositions(String[] headers)
Map CSV headers to their positions.- Parameters:
headers- CSV header list- Returns:
- a new List with header indexes
-
makeSourceMapping
public static Map<String,Integer> makeSourceMapping(String[] headers, String[] supportedHeaders)
We are mostly interested in only a few supported headers. Get their indexes.- Parameters:
headers- the headerssupportedHeaders- Array of supported headers- Returns:
- Map of positions of supported headers
-
toOutputLine
public static String[] toOutputLine(String[] nextLine, List<String> outputHeaders, List<Integer> outputMapping)
Copy data from input CSV line to output CSV line with appropriate destination mapping.- Parameters:
nextLine- source lineoutputHeaders- output headersoutputMapping- mapping of output columns- Returns:
- the output CSV line filled with data from input CSV line
-
-