ElementIndexPreProcessor { public void addScenarioIndices(final List<Report> reports) { List<Element> elements = new ArrayList<>(); for (Report report : reports) { elements.addAll(report.getElements()); } List<Element> sortedElements = elements.stream(). sorted(Comparator.comparing(Element::getStartTimestamp)). collect(Collectors.toList()); int scenarioIndex = 0; for (Element element : sortedElements) { if (element.isScenario()) { scenarioIndex++; element.setScenarioIndex(scenarioIndex); } } }  void addScenarioIndices(final List<Report> reports);  }
@Test public void addScenarioIndicesWithoutTimestampTest() { List<Report> reports = new ArrayList<>(); Report report = new Report(); List<Element> elements = new ArrayList<>(); Element element = new Element(); element.setName("Scenario 1"); element.setType("scenario"); elements.add(element); element = new Element(); element.setName("Scenario 2"); element.setType("scenario"); elements.add(element); element = new Element(); element.setName("Scenario 3"); element.setType("scenario"); elements.add(element); report.setElements(elements); reports.add(report); List<Element> e = reports.get(0).getElements(); assertThat(e.get(0).getScenarioIndex(), is(0)); assertThat(e.get(1).getScenarioIndex(), is(0)); assertThat(e.get(2).getScenarioIndex(), is(0)); elementIndexPreProcessor.addScenarioIndices(reports); assertThat(e.get(0).getScenarioIndex(), is(1)); assertThat(e.get(1).getScenarioIndex(), is(2)); assertThat(e.get(2).getScenarioIndex(), is(3)); }
@Test public void addScenarioIndicesWithTimestampTest() { List<Report> reports = new ArrayList<>(); Report report = new Report(); List<Element> elements = new ArrayList<>(); Element element = new Element(); element.setName("Scenario 1"); element.setType("scenario"); element.setStartTimestamp("2019-04-11T08:00:25.829Z"); elements.add(element); element = new Element(); element.setName("Scenario 2"); element.setType("scenario"); element.setStartTimestamp("2019-04-11T08:00:21.123Z"); elements.add(element); element = new Element(); element.setName("Scenario 3"); element.setType("scenario"); element.setStartTimestamp("2019-04-11T09:00:21.123Z"); elements.add(element); report.setElements(elements); reports.add(report); List<Element> e = reports.get(0).getElements(); assertThat(e.get(0).getScenarioIndex(), is(0)); assertThat(e.get(1).getScenarioIndex(), is(0)); assertThat(e.get(2).getScenarioIndex(), is(0)); elementIndexPreProcessor.addScenarioIndices(reports); assertThat(e.get(0).getScenarioIndex(), is(2)); assertThat(e.get(1).getScenarioIndex(), is(1)); assertThat(e.get(2).getScenarioIndex(), is(3)); }