Parallel { public static <T> void forEach(final Iterable<T> objects, final Operation<T> op, final ThreadPoolExecutor pool) { Partitioner<T> partitioner; if (objects instanceof List) { partitioner = new RangePartitioner<T>((List<T>) objects, pool.getMaximumPoolSize()); } else { partitioner = new GrowingChunkPartitioner<T>(objects); } forEach(partitioner, op, pool); }  static void forIndex(final int start, final int stop, final int incr, final Operation<Integer> op,
			final ThreadPoolExecutor pool); static void forIndex(final int start, final int stop, final int incr, final Operation<Integer> op); static void forRange(final int start, final int stop, final int incr, final Operation<IntRange> op); static void forRange(final int start, final int stop, final int incr, final Operation<IntRange> op,
			final ThreadPoolExecutor pool); static void forEach(final Iterable<T> objects, final Operation<T> op, final ThreadPoolExecutor pool); static void forEach(final Iterable<T> objects, final Operation<T> op); static void forEach(final Partitioner<T> partitioner, final Operation<T> op); static void forEach(final Partitioner<T> partitioner, final Operation<T> op, final ThreadPoolExecutor pool); static void forEachUnpartitioned(final Iterator<T> data, final Operation<T> op); static void forEachUnpartitioned(final Iterator<T> data, final Operation<T> op, final ThreadPoolExecutor pool); static void forEachPartitioned(final Partitioner<T> partitioner, final Operation<Iterator<T>> op,
			final ThreadPoolExecutor pool); static void forEachPartitioned(final Partitioner<T> partitioner, final Operation<Iterator<T>> op);  }
@Test public void testForEach() { final Set<Integer> intsList = new HashSet<Integer>(); for (int i = 0; i < Math.random() * 1000000; i++) { intsList.add(i); } final Set<Integer> out = Collections.synchronizedSet(new HashSet<Integer>()); Parallel.forEach(intsList, new Operation<Integer>() { @Override public void perform(Integer object) { out.add(object); } }); assertEquals(intsList.size(), out.size()); }
@Test public void testForEach2() { final List<Integer> intsList = new ArrayList<Integer>(); for (int i = 0; i < Math.random() * 1000000; i++) { intsList.add(i); } final Set<Integer> out = Collections.synchronizedSet(new HashSet<Integer>()); Parallel.forEach(intsList, new Operation<Integer>() { @Override public void perform(Integer object) { out.add(object); } }); assertEquals(intsList.size(), out.size()); }