I am using SuperCSV library to read a csv file with the method below. However, the method returns a Collection<Object>
and I need a Collection<Double>
. I am already using the Optional(new ParseDouble())
processors which converts every cell to a Double.
The question is how do you convert it/ cast it/ or is there another way?
Also, if possible I need to avoid any expensive operations since this method is called frequently.
private static Collection<Object> partialReadWithCsvMapReader(int row, String[] header, CellProcessor[] processors) throws Exception {
ICsvMapReader mapReader = null;
Map<String, Object> rowMap = null;
try {
mapReader = new CsvMapReader(new FileReader(CSV_FILENAME), CsvPreference.STANDARD_PREFERENCE);
mapReader.getHeader(true);
while( (rowMap = mapReader.read(header, processors)) != null ) {
if(mapReader.getLineNumber() == row){
break;
}
}
}
finally {
if( mapReader != null ) {
mapReader.close();
}
}
return rowMap.values();
}
The question is in the context of the SuperCSV library. Since the individual values are already converted to Doubles by the processors - would it be possible to return a
Collection<Double>
instead of having to convert the collection once again.