/** * Given a row, finds the length of the row. * * @param row length needs to be determined. * @return length of the row. */ public static int columns(Row row) { return row.length(); }
@Override public List<Row> execute(List<Row> rows, ExecutorContext context) throws DirectiveExecutionException { for (Row row : rows) { int idx = 0; for (String name : columns) { if (idx < row.length()) { row.setColumn(idx, name.trim()); } idx++; } } return rows; } }
@Override public void set(Row value) { map.clear(); for(int i = 0; i < value.length(); ++i) { map.put(value.getColumn(i), value.getValue(i)); } }
@Override public List<Row> execute(List<Row> rows, ExecutorContext context) throws DirectiveExecutionException { for (Row row : rows) { for (int i = 0; i < row.length(); ++i) { String column = row.getColumn(i); // Trims column = column.trim(); // Lower case columns column = column.toLowerCase(); // Filtering unwanted characters column = column.replaceAll("[^a-zA-Z0-9_]", "_"); row.setColumn(i, column); } } return rows; } }
@Override public List<Row> execute(List<Row> rows, ExecutorContext context) throws DirectiveExecutionException { for (Row row : rows) { for (int i = 0; i < row.length(); ++i) { String name = row.getColumn(i); if (toLower) { row.setColumn(i, name.toLowerCase()); } else { row.setColumn(i, name.toUpperCase()); } } } return rows; } }
@Override public List<Row> execute(List<Row> rows, ExecutorContext context) throws DirectiveExecutionException { for (Row row : rows) { try { final ByteArrayOutputStream bOut = new ByteArrayOutputStream(); try(Writer out = new BufferedWriter(new OutputStreamWriter(bOut))) { CSVPrinter csvPrinter = new CSVPrinter(out, CSVFormat.DEFAULT); for (int i = 0; i < row.length(); ++i) { csvPrinter.print(row.getValue(i)); } csvPrinter.flush(); csvPrinter.close(); } catch (Exception e) { bOut.close(); } row.add(column, bOut.toString()); } catch (IOException e) { throw new DirectiveExecutionException(toString() + " : Failed to write CSV row. " + e.getMessage()); } } return rows; } }
@Override public List<Row> execute(List<Row> rows, ExecutorContext context) throws DirectiveExecutionException { for (Row row : rows) { for (int i = 0; i < row.length(); ++i) { String name = row.getColumn(i); try { Unix4jCommandBuilder builder = Unix4j.echo(name).sed(sed); row.setColumn(i, builder.toStringResult()); } catch (IllegalArgumentException e) { throw new DirectiveExecutionException( String.format(toString() + " : " + e.getMessage()) ); } } } return rows; } }
for (Row row : rows) { ++count; for (int i = 0; i < row.length(); ++i) { String column = row.getColumn(i); Object object = row.getValue(i);