@Test public void testParallelForLoopBaseCases() throws Exception { ParallelLoopResult<Integer> nullLoopResult = Parallel.forLoop( null, new LoopBody<Integer, Integer>() { @Override public Integer run(Integer integer) { return integer; } }); Assert.assertTrue(nullLoopResult.getIsCompleted()); Assert.assertTrue(nullLoopResult.getResult().isEmpty()); ParallelLoopResult<Integer> emptyLoopResult = Parallel.forLoop( new ArrayList<Integer>(), new LoopBody<Integer, Integer>() { @Override public Integer run(Integer integer) { return integer; } }); Assert.assertTrue(emptyLoopResult.getIsCompleted()); Assert.assertTrue(emptyLoopResult.getResult().isEmpty()); ParallelLoopResult<Integer> singleElementLoopResult = Parallel.forLoop( Collections.singletonList(7), new LoopBody<Integer, Integer>() { @Override public Integer run(Integer integer) { return integer; } }); Assert.assertTrue(singleElementLoopResult.getIsCompleted()); List<Integer> singleElementList = singleElementLoopResult.getResult(); Assert.assertTrue(singleElementLoopResult.getIsCompleted()); Assert.assertFalse(singleElementList.isEmpty()); Assert.assertEquals(1, singleElementList.size()); Assert.assertNotNull(singleElementList.get(0)); }
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);  }