SubContingenciesProvider implements ContingenciesProvider { @Override public List<Contingency> getContingencies(Network network) { List<Contingency> fullList = delegate.getContingencies(network); int fullSize = fullList.size(); int start = partition.startIndex(fullSize); int end = partition.endIndex(fullSize); return new ArrayList<>(fullList.subList(start, end)); } SubContingenciesProvider(ContingenciesProvider delegate, Partition partition); @Override List<Contingency> getContingencies(Network network);  }
@Test public void test() { ContingenciesProvider provider = n -> IntStream.range(1, 5) .mapToObj(i -> new Contingency("contingency-" + i)) .collect(Collectors.toList()); Network network = Mockito.mock(Network.class); List<String> subList1 = new SubContingenciesProvider(provider, new Partition(1, 2)) .getContingencies(network) .stream().map(Contingency::getId).collect(Collectors.toList()); List<String> subList2 = new SubContingenciesProvider(provider, new Partition(2, 2)) .getContingencies(network) .stream().map(Contingency::getId).collect(Collectors.toList()); assertEquals(ImmutableList.of("contingency-1", "contingency-2"), subList1); assertEquals(ImmutableList.of("contingency-3", "contingency-4"), subList2); }
@Test public void testEmpty() { ContingenciesProvider provider = n -> Collections.emptyList(); Network network = Mockito.mock(Network.class); List<String> subList1 = new SubContingenciesProvider(provider, new Partition(1, 1)) .getContingencies(network) .stream().map(Contingency::getId).collect(Collectors.toList()); assertEquals(Collections.emptyList(), subList1); }