@Test public void testParallelForLoopIterationFailures() throws Exception { final List<Integer> input = new LinkedList<Integer>(); for(int i = 0; i < 10; i++) { input.add(i); } final List<Integer> failForList = Arrays.asList(new Integer[] { 2, 5, 7}); ParallelLoopResult<Integer> loopResult = Parallel.forLoop(input, new LoopBody<Integer, Integer>() { @Override public Integer run(Integer in1) { if(failForList.contains(in1)) { return null; } return in1 * in1; } }); Assert.assertFalse(loopResult.getIsCompleted()); Assert.assertNotNull(loopResult.getResult()); List<Integer> output = loopResult.getResult(); Assert.assertEquals(input.size(), output.size()); for(int i = 0; i < input.size(); i++) { if(failForList.contains(i)) { Assert.assertNull(output.get(i)); output.set(i, i * i); } else { Assert.assertEquals(i * i, (int) output.get(i)); } } }
public static <T, R> ParallelLoopResult<R> forLoop( List<T> source, final LoopBody<T, R> loopBody) { if(source == null || source.isEmpty()) { return new ParallelLoopResult<>(true, Collections.<R>emptyList()); } return forLoop(source, 0, source.size(), loopBody); }
Parallel { public static <T, R> ParallelLoopResult<R> forLoop( List<T> source, final LoopBody<T, R> loopBody) { if(source == null || source.isEmpty()) { return new ParallelLoopResult<>(true, Collections.<R>emptyList()); } return forLoop(source, 0, source.size(), loopBody); } }
Parallel { public static <T, R> ParallelLoopResult<R> forLoop( List<T> source, final LoopBody<T, R> loopBody) { if(source == null || source.isEmpty()) { return new ParallelLoopResult<>(true, Collections.<R>emptyList()); } return forLoop(source, 0, source.size(), loopBody); }  }
Parallel { public static <T, R> ParallelLoopResult<R> forLoop( List<T> source, final LoopBody<T, R> loopBody) { if(source == null || source.isEmpty()) { return new ParallelLoopResult<>(true, Collections.<R>emptyList()); } return forLoop(source, 0, source.size(), loopBody); }  static ParallelLoopResult<R> forLoop(
      List<T> source,
      final LoopBody<T, R> loopBody); static ParallelLoopResult<R> forLoop(
      final List<T> source,
      int startIndex,
      int endIndex,
      final LoopBody<T, R> loopBody); }
Parallel { public static <T, R> ParallelLoopResult<R> forLoop( List<T> source, final LoopBody<T, R> loopBody) { if(source == null || source.isEmpty()) { return new ParallelLoopResult<>(true, Collections.<R>emptyList()); } return forLoop(source, 0, source.size(), loopBody); }  static ParallelLoopResult<R> forLoop(
      List<T> source,
      final LoopBody<T, R> loopBody); static ParallelLoopResult<R> forLoop(
      final List<T> source,
      int startIndex,
      int endIndex,
      final LoopBody<T, R> loopBody);  }