RemoveLinesDataModifier implements DataFilterJob<String> { private String modify(String data, Set<Integer> indexesToRemove) { List<String> lines = Arrays.asList(StringUtils.split(data, NEWLINE)); Set<Integer> dataIndexes = ContiguousSet.create(Range.closed(1, lines.size()), DiscreteDomain.integers()); if (!dataIndexes.containsAll(indexesToRemove)) { LOGGER.warn("Some of defined ranges exceed source lenght. Source length is: " + lines.size()); } Set<Integer> filtereedIndexesToRemove = Sets.intersection(dataIndexes, indexesToRemove); List<String> modifiedLines = new ArrayList<String>( lines.size() - filtereedIndexesToRemove.size()); for (int i = 0; i < lines.size(); i++) { if (!filtereedIndexesToRemove.contains(i + 1)) { modifiedLines.add(lines.get(i)); } } return StringUtils.join(modifiedLines, NEWLINE); }  @Override void setParameters(Map<String, String> params); @Override String modifyData(String data); @Override String modifyPattern(String data); @Override String getInfo(); void validateParameters(String dataRanges, String patternRanges); static final String NAME; }
@TestWith({"abcd\nefgh\n1234-02,2-abcd\n1234", "abcd\nefgh\n1234-4,10-abcd\nefgh\n1234"}) public void testModify(String data, String dataRanges, String result) throws ParametersException, ProcessingException { Map<String, String> params = new HashMap<String, String>(); params.put("dataRanges", dataRanges); tested.setParameters(params); assertEquals(result, tested.modifyData(data)); }