@Test public void testSentenceTrim() throws Exception { String expected = "TITLE IS TITLE"; String[] directives = new String[] { "trim body", }; List<Row> rows = Arrays.asList( new Row("body", "TITLE IS TITLE"), new Row("body", " TITLE IS TITLE"), new Row("body", "TITLE IS TITLE "), new Row("body", " TITLE IS TITLE "), new Row("body", " TITLE IS TITLE "), new Row("body", "\t TITLE IS TITLE \t"), new Row("body", "\t" + expected), new Row("body", expected + "\t"), new Row("body", '\u0009' + expected), new Row("body", "\r" + expected), new Row("body", expected + "\r"), new Row("body", '\u2004' + expected), new Row("body", expected + '\u2004'), new Row("body", '\u2005' + expected), new Row("body", expected + '\u2005'), new Row("body", '\u2006' + expected), new Row("body", expected + '\u2006'), new Row("body", '\u3000' + expected), new Row("body", '\t' + expected + '\u3000' + '\u3000' + '\t' + '\r') ); rows = TestingRig.execute(directives, rows); Assert.assertEquals(rows.size(), rows.size()); Assert.assertEquals("TITLE IS TITLE", rows.get(0).getValue("body")); Assert.assertEquals("TITLE IS TITLE", rows.get(1).getValue("body")); Assert.assertEquals("TITLE IS TITLE", rows.get(2).getValue("body")); Assert.assertEquals("TITLE IS TITLE", rows.get(3).getValue("body")); Assert.assertEquals("TITLE IS TITLE", rows.get(4).getValue("body")); for (int i = 5; i < rows.size(); ++i) { Assert.assertEquals(expected, rows.get(i).getValue("body")); } }
@Override public List<Row> execute(List<Row> rows, ExecutorContext context) throws DirectiveExecutionException { for (Row row : rows) { int idx = row.find(column); if (idx != -1) { Object object = row.getValue(idx); if (object instanceof String) { if (object != null) { String value = (String) object; row.setValue(idx, Trimmer.trim(value)); } } } } return rows; }
Trim implements Directive, Lineage { @Override public List<Row> execute(List<Row> rows, ExecutorContext context) throws DirectiveExecutionException { for (Row row : rows) { int idx = row.find(column); if (idx != -1) { Object object = row.getValue(idx); if (object instanceof String) { if (object != null) { String value = (String) object; row.setValue(idx, Trimmer.trim(value)); } } } } return rows; } }
Trim implements Directive, Lineage { @Override public List<Row> execute(List<Row> rows, ExecutorContext context) throws DirectiveExecutionException { for (Row row : rows) { int idx = row.find(column); if (idx != -1) { Object object = row.getValue(idx); if (object instanceof String) { if (object != null) { String value = (String) object; row.setValue(idx, Trimmer.trim(value)); } } } } return rows; }  }
Trim implements Directive, Lineage { @Override public List<Row> execute(List<Row> rows, ExecutorContext context) throws DirectiveExecutionException { for (Row row : rows) { int idx = row.find(column); if (idx != -1) { Object object = row.getValue(idx); if (object instanceof String) { if (object != null) { String value = (String) object; row.setValue(idx, Trimmer.trim(value)); } } } } return rows; }  @Override UsageDefinition define(); @Override void initialize(Arguments args); @Override void destroy(); @Override List<Row> execute(List<Row> rows, ExecutorContext context); @Override Mutation lineage(); }
Trim implements Directive, Lineage { @Override public List<Row> execute(List<Row> rows, ExecutorContext context) throws DirectiveExecutionException { for (Row row : rows) { int idx = row.find(column); if (idx != -1) { Object object = row.getValue(idx); if (object instanceof String) { if (object != null) { String value = (String) object; row.setValue(idx, Trimmer.trim(value)); } } } } return rows; }  @Override UsageDefinition define(); @Override void initialize(Arguments args); @Override void destroy(); @Override List<Row> execute(List<Row> rows, ExecutorContext context); @Override Mutation lineage(); static final String NAME; }