List of usage examples for org.apache.commons.csv CSVRecord iterator
@Override
public Iterator<String> iterator()
From source file:org.sonar.scanner.config.DefaultConfiguration.java
/** * In most cases we expect a single record. <br>Having multiple records means the input value was splitted over multiple lines (this is common in Maven). * For example:/*from w ww .j a v a2 s . c o m*/ * <pre> * <sonar.exclusions> * src/foo, * src/bar, * src/biz * <sonar.exclusions> * </pre> * In this case records will be merged to form a single list of items. Last item of a record is appended to first item of next record. * <p> * This is a very curious case, but we try to preserve line break in the middle of an item: * <pre> * <sonar.exclusions> * a * b, * c * <sonar.exclusions> * </pre> * will produce ['a\nb', 'c'] */ private static void processRecords(List<String> result, List<CSVRecord> records) { for (CSVRecord csvRecord : records) { Iterator<String> it = csvRecord.iterator(); if (!result.isEmpty()) { String next = it.next(); if (!next.isEmpty()) { int lastItemIdx = result.size() - 1; String previous = result.get(lastItemIdx); if (previous.isEmpty()) { result.set(lastItemIdx, next); } else { result.set(lastItemIdx, previous + "\n" + next); } } } it.forEachRemaining(result::add); } }
From source file:su90.etl.controller.SlaveController.java
private void _do_imps() { Reader in = null;/*from w ww. j av a 2 s .c om*/ try { in = new FileReader(INPUTPATHSTR + System.getProperty("file.separator") + "facts" + System.getProperty("file.separator") + "imps" + System.getProperty("file.separator") + FILENAME); Iterable<CSVRecord> records = CSVFormat.EXCEL.parse(in); for (CSVRecord record : records) { Result tmpresult = parse_imps(record.iterator()); if (results.containsKey(tmpresult.hashCode())) { Result previousresult = results.get(tmpresult.hashCode()); previousresult.setImps(previousresult.getImps() + tmpresult.getImps()); previousresult.addOneDeviceType(tmpresult.getDevice_type()); results.put(previousresult.hashCode(), previousresult); } else { results.put(tmpresult.hashCode(), tmpresult); } } } catch (FileNotFoundException ex) { Logger.getLogger(SlaveController.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(SlaveController.class.getName()).log(Level.SEVERE, null, ex); } finally { if (in != null) try { in.close(); } catch (IOException ex) { Logger.getLogger(SlaveController.class.getName()).log(Level.SEVERE, null, ex); } } }
From source file:su90.etl.controller.SlaveController.java
private void _do_clicks() { Reader in = null;/*from w w w . jav a 2 s. c o m*/ try { in = new FileReader(INPUTPATHSTR + System.getProperty("file.separator") + "facts" + System.getProperty("file.separator") + "clicks" + System.getProperty("file.separator") + FILENAME); Iterable<CSVRecord> records = CSVFormat.EXCEL.parse(in); for (CSVRecord record : records) { Result tmpresult = parse_clicks(record.iterator()); if (results.containsKey(tmpresult.hashCode())) { Result previousresult = results.get(tmpresult.hashCode()); previousresult.setClicks(previousresult.getClicks() + tmpresult.getClicks()); results.put(previousresult.hashCode(), previousresult); } else { results.put(tmpresult.hashCode(), tmpresult); } } } catch (FileNotFoundException ex) { Logger.getLogger(SlaveController.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(SlaveController.class.getName()).log(Level.SEVERE, null, ex); } finally { if (in != null) try { in.close(); } catch (IOException ex) { Logger.getLogger(SlaveController.class.getName()).log(Level.SEVERE, null, ex); } } }