FJIterate { public static <T> void forEach(Iterable<T> iterable, Procedure<? super T> procedure) { FJIterate.forEach(iterable, procedure, FJIterate.FORK_JOIN_POOL); } private  FJIterate(); static void forEachWithIndex(
            Iterable<T> iterable,
            ObjectIntProcedure<? super T> procedure); static void forEachWithIndex(
            Iterable<T> iterable,
            PT procedure,
            ForkJoinPool executor); static void forEachWithIndex(
            Iterable<T> iterable,
            PT procedure,
            int minForkSize,
            int taskCount); static void forEachWithIndex(
            Iterable<T> iterable,
            ObjectIntProcedureFactory<PT> procedureFactory,
            Combiner<PT> combiner,
            ForkJoinPool executor); static void forEachWithIndex(
            Iterable<T> iterable,
            ObjectIntProcedureFactory<PT> procedureFactory,
            Combiner<PT> combiner,
            int minForkSize,
            int taskCount); static void forEachWithIndex(
            Iterable<T> iterable,
            ObjectIntProcedureFactory<PT> procedureFactory,
            Combiner<PT> combiner,
            int minForkSize,
            int taskCount,
            ForkJoinPool executor); static void forEachWithIndexInListOnExecutor(
            List<T> list,
            ObjectIntProcedureFactory<PT> procedureFactory,
            Combiner<PT> combiner,
            int minForkSize,
            int taskCount,
            ForkJoinPool executor); static void forEach(Iterable<T> iterable, Procedure<? super T> procedure); static void forEach(Iterable<T> iterable, Procedure<? super T> procedure, int batchSize); static void forEach(Iterable<T> iterable, Procedure<? super T> procedure, int batchSize, ForkJoinPool executor); static void forEach(
            Iterable<T> iterable,
            PT procedure,
            ForkJoinPool executor); static void forEach(
            Iterable<T> iterable,
            PT procedure,
            int minForkSize,
            int taskCount); static void forEach(
            Iterable<T> iterable,
            PT procedure,
            int minForkSize,
            int taskCount,
            ForkJoinPool executor); static void forEach(
            Iterable<T> iterable,
            ProcedureFactory<PT> procedureFactory,
            Combiner<PT> combiner,
            ForkJoinPool executor); static void forEach(
            Iterable<T> iterable,
            ProcedureFactory<PT> procedureFactory,
            Combiner<PT> combiner); static void forEach(
            Iterable<T> iterable,
            ProcedureFactory<PT> procedureFactory,
            Combiner<PT> combiner,
            int batchSize); static void forEach(
            Iterable<T> iterable,
            ProcedureFactory<PT> blockFactory,
            Combiner<PT> combiner,
            int batchSize,
            ForkJoinPool executor); static void forEach(
            Iterable<T> iterable,
            ProcedureFactory<PT> procedureFactory,
            Combiner<PT> combiner,
            int minForkSize,
            int taskCount); static void forEach(
            Iterable<T> iterable,
            ProcedureFactory<PT> procedureFactory,
            Combiner<PT> combiner,
            int minForkSize,
            int taskCount,
            ForkJoinPool executor); static void forEachInListOnExecutor(
            List<T> list,
            ProcedureFactory<PT> procedureFactory,
            Combiner<PT> combiner,
            int minForkSize,
            int taskCount,
            ForkJoinPool executor); static void forEachInBatchWithExecutor(
            BatchIterable<T> batchIterable,
            ProcedureFactory<PT> procedureFactory, Combiner<PT> combiner, int minForkSize, int taskCount,
            ForkJoinPool executor); static Collection<T> select(
            Iterable<T> iterable,
            Predicate<? super T> predicate); static Collection<T> select(
            Iterable<T> iterable,
            Predicate<? super T> predicate,
            boolean allowReorderedResult); static R select(
            Iterable<T> iterable,
            Predicate<? super T> predicate,
            R target,
            boolean allowReorderedResult); static R select(
            Iterable<T> iterable,
            Predicate<? super T> predicate,
            R target,
            int batchSize,
            ForkJoinPool executor,
            boolean allowReorderedResult); static Collection<T> reject(
            Iterable<T> iterable,
            Predicate<? super T> predicate); static Collection<T> reject(
            Iterable<T> iterable,
            Predicate<? super T> predicate,
            boolean allowReorderedResult); static R reject(
            Iterable<T> iterable,
            Predicate<? super T> predicate,
            R target,
            boolean allowReorderedResult); static R reject(
            Iterable<T> iterable,
            Predicate<? super T> predicate,
            R target,
            int batchSize,
            ForkJoinPool executor,
            boolean allowReorderedResult); static int count(Iterable<T> iterable, Predicate<? super T> predicate); static int count(Iterable<T> iterable, Predicate<? super T> predicate, int batchSize, ForkJoinPool executor); static Collection<V> collect(
            Iterable<T> iterable,
            Function<? super T, V> function); static Collection<V> collect(
            Iterable<T> iterable,
            Function<? super T, V> function,
            boolean allowReorderedResult); static R collect(
            Iterable<T> iterable,
            Function<? super T, V> function,
            R target,
            boolean allowReorderedResult); static R collect(
            Iterable<T> iterable,
            Function<? super T, V> function,
            R target,
            int batchSize,
            ForkJoinPool executor,
            boolean allowReorderedResult); static Collection<V> flatCollect(
            Iterable<T> iterable,
            Function<? super T, ? extends Iterable<V>> function); static Collection<V> flatCollect(
            Iterable<T> iterable,
            Function<? super T, ? extends Iterable<V>> function,
            boolean allowReorderedResult); static R flatCollect(
            Iterable<T> iterable,
            Function<? super T, ? extends Iterable<V>> function,
            R target,
            boolean allowReorderedResult); static R flatCollect(
            Iterable<T> iterable,
            Function<? super T, ? extends Iterable<V>> function,
            R target,
            int batchSize,
            ForkJoinPool executor,
            boolean allowReorderedResult); static Collection<V> collectIf(
            Iterable<T> iterable,
            Predicate<? super T> predicate,
            Function<? super T, V> function); static Collection<V> collectIf(
            Iterable<T> iterable,
            Predicate<? super T> predicate,
            Function<? super T, V> function,
            boolean allowReorderedResult); static R collectIf(
            Iterable<T> iterable,
            Predicate<? super T> predicate,
            Function<? super T, V> function,
            R target,
            boolean allowReorderedResult); static R collectIf(
            Iterable<T> iterable,
            Predicate<? super T> predicate,
            Function<? super T, V> function,
            R target,
            int batchSize,
            ForkJoinPool executor,
            boolean allowReorderedResult); static MutableMap<K, V> aggregateBy(
            Iterable<T> iterable,
            Function<? super T, ? extends K> groupBy,
            Function0<? extends V> zeroValueFactory,
            Function2<? super V, ? super T, ? extends V> nonMutatingAggregator); static R aggregateBy(
            Iterable<T> iterable,
            Function<? super T, ? extends K> groupBy,
            Function0<? extends V> zeroValueFactory,
            Function2<? super V, ? super T, ? extends V> nonMutatingAggregator,
            R mutableMap); static MutableMap<K, V> aggregateBy(
            Iterable<T> iterable,
            Function<? super T, ? extends K> groupBy,
            Function0<? extends V> zeroValueFactory,
            Function2<? super V, ? super T, ? extends V> nonMutatingAggregator,
            int batchSize); static R aggregateBy(
            Iterable<T> iterable,
            Function<? super T, ? extends K> groupBy,
            Function0<? extends V> zeroValueFactory,
            Function2<? super V, ? super T, ? extends V> nonMutatingAggregator,
            R mutableMap,
            int batchSize); static MutableMap<K, V> aggregateBy(
            Iterable<T> iterable,
            Function<? super T, ? extends K> groupBy,
            Function0<? extends V> zeroValueFactory,
            Function2<? super V, ? super T, ? extends V> nonMutatingAggregator,
            int batchSize,
            ForkJoinPool executor); static R aggregateBy(
            Iterable<T> iterable,
            Function<? super T, ? extends K> groupBy,
            Function0<? extends V> zeroValueFactory,
            Function2<? super V, ? super T, ? extends V> nonMutatingAggregator,
            R mutableMap,
            int batchSize,
            ForkJoinPool executor); static MutableMap<K, V> aggregateInPlaceBy(
            Iterable<T> iterable,
            Function<? super T, ? extends K> groupBy,
            Function0<? extends V> zeroValueFactory,
            Procedure2<? super V, ? super T> mutatingAggregator); static R aggregateInPlaceBy(
            Iterable<T> iterable,
            Function<? super T, ? extends K> groupBy,
            Function0<? extends V> zeroValueFactory,
            Procedure2<? super V, ? super T> mutatingAggregator,
            R mutableMap); static MutableMap<K, V> aggregateInPlaceBy(
            Iterable<T> iterable,
            Function<? super T, ? extends K> groupBy,
            Function0<? extends V> zeroValueFactory,
            Procedure2<? super V, ? super T> mutatingAggregator,
            int batchSize); static R aggregateInPlaceBy(
            Iterable<T> iterable,
            Function<? super T, ? extends K> groupBy,
            Function0<? extends V> zeroValueFactory,
            Procedure2<? super V, ? super T> mutatingAggregator,
            R mutableMap,
            int batchSize); static MutableMap<K, V> aggregateInPlaceBy(
            Iterable<T> iterable,
            Function<? super T, ? extends K> groupBy,
            Function0<? extends V> zeroValueFactory,
            Procedure2<? super V, ? super T> mutatingAggregator,
            int batchSize,
            ForkJoinPool executor); static R aggregateInPlaceBy(
            Iterable<T> iterable,
            Function<? super T, ? extends K> groupBy,
            Function0<? extends V> zeroValueFactory,
            Procedure2<? super V, ? super T> mutatingAggregator,
            R mutableMap,
            int batchSize,
            ForkJoinPool executor); static MutableMultimap<K, V> groupBy(
            Iterable<V> iterable,
            Function<? super V, ? extends K> function); static MutableMultimap<K, V> groupBy(
            Iterable<V> iterable,
            Function<? super V, ? extends K> function,
            R concurrentMultimap); static MutableMultimap<K, V> groupBy(
            Iterable<V> iterable,
            Function<? super V, ? extends K> function,
            R concurrentMultimap,
            int batchSize); static MutableMultimap<K, V> groupBy(
            Iterable<V> iterable,
            Function<? super V, ? extends K> function,
            int batchSize); static MutableMultimap<K, V> groupBy(
            Iterable<V> iterable,
            Function<? super V, ? extends K> function,
            int batchSize,
            ForkJoinPool executor); static MutableMultimap<K, V> groupBy(
            Iterable<V> iterable,
            Function<? super V, ? extends K> function,
            R concurrentMultimap,
            int batchSize,
            ForkJoinPool executor); static final int DEFAULT_MIN_FORK_SIZE; }
@Test public void testForEachUsingSet() { IntegerSum sum = new IntegerSum(0); MutableSet<Integer> set = Interval.toSet(1, 100); FJIterate.forEach(set, new SumProcedure(sum), new SumCombiner(sum)); Assert.assertEquals(5050, sum.getSum()); IntegerSum sum2 = new IntegerSum(0); UnifiedSet<Integer> set2 = UnifiedSet.newSet(Interval.oneTo(100)); FJIterate.forEach(set2, new SumProcedure(sum2), new SumCombiner(sum2), 1, set2.getBatchCount(set2.size())); Assert.assertEquals(5050, sum2.getSum()); IntegerSum sum3 = new IntegerSum(0); UnifiedSet<Integer> set3 = UnifiedSet.newSet(Interval.oneTo(100)); FJIterate.forEach(set3, new SumProcedure(sum3), new SumCombiner(sum3), 1, set3.getBatchCount(13)); Assert.assertEquals(5050, sum3.getSum()); IntegerSum sum4 = new IntegerSum(0); UnifiedSet<Integer> set4 = UnifiedSet.newSet(Interval.oneTo(100)); FJIterate.forEach(set4, new SumProcedure(sum4), new SumCombiner(sum4), 1); Assert.assertEquals(5050, sum4.getSum()); }
@Test public void testForEachUsingMap() { IntegerSum sum1 = new IntegerSum(0); MutableMap<String, Integer> map1 = Interval.fromTo(1, 100).toMap(Functions.getToString(), Functions.getIntegerPassThru()); FJIterate.forEach(map1, new SumProcedure(sum1), new SumCombiner(sum1)); Assert.assertEquals(5050, sum1.getSum()); IntegerSum sum2 = new IntegerSum(0); UnifiedMap<String, Integer> map2 = (UnifiedMap<String, Integer>) Interval.fromTo(1, 100).toMap(Functions.getToString(), Functions.getIntegerPassThru()); FJIterate.forEach(map2, new SumProcedure(sum2), new SumCombiner(sum2), 1, map2.getBatchCount(map2.size())); Assert.assertEquals(5050, sum2.getSum()); IntegerSum sum3 = new IntegerSum(0); UnifiedMap<String, Integer> set3 = (UnifiedMap<String, Integer>) Interval.fromTo(1, 100).toMap(Functions.getToString(), Functions.getIntegerPassThru()); FJIterate.forEach(set3, new SumProcedure(sum3), new SumCombiner(sum3), 1, set3.getBatchCount(13)); Assert.assertEquals(5050, sum3.getSum()); }
@Test public void testForEach() { IntegerSum sum1 = new IntegerSum(0); List<Integer> list1 = FJIterateTest.createIntegerList(16); FJIterate.forEach(list1, new SumProcedure(sum1), new SumCombiner(sum1), 1, list1.size() / 2); Assert.assertEquals(16, sum1.getSum()); IntegerSum sum2 = new IntegerSum(0); List<Integer> list2 = FJIterateTest.createIntegerList(7); FJIterate.forEach(list2, new SumProcedure(sum2), new SumCombiner(sum2)); Assert.assertEquals(7, sum2.getSum()); IntegerSum sum3 = new IntegerSum(0); List<Integer> list3 = FJIterateTest.createIntegerList(15); FJIterate.forEach(list3, new SumProcedure(sum3), new SumCombiner(sum3), 1, list3.size() / 2); Assert.assertEquals(15, sum3.getSum()); IntegerSum sum4 = new IntegerSum(0); List<Integer> list4 = FJIterateTest.createIntegerList(35); FJIterate.forEach(list4, new SumProcedure(sum4), new SumCombiner(sum4)); Assert.assertEquals(35, sum4.getSum()); IntegerSum sum5 = new IntegerSum(0); MutableList<Integer> list5 = FastList.newList(list4); FJIterate.forEach(list5, new SumProcedure(sum5), new SumCombiner(sum5)); Assert.assertEquals(35, sum5.getSum()); IntegerSum sum6 = new IntegerSum(0); List<Integer> list6 = FJIterateTest.createIntegerList(40); FJIterate.forEach(list6, new SumProcedure(sum6), new SumCombiner(sum6), 1, list6.size() / 2); Assert.assertEquals(40, sum6.getSum()); IntegerSum sum7 = new IntegerSum(0); MutableList<Integer> list7 = FastList.newList(list6); FJIterate.forEach(list7, new SumProcedure(sum7), new SumCombiner(sum7), 1, list6.size() / 2); Assert.assertEquals(40, sum7.getSum()); }
@Test public void testForEachImmutable() { IntegerSum sum1 = new IntegerSum(0); ImmutableList<Integer> list1 = Lists.immutable.ofAll(FJIterateTest.createIntegerList(16)); FJIterate.forEach(list1, new SumProcedure(sum1), new SumCombiner(sum1), 1, list1.size() / 2); Assert.assertEquals(16, sum1.getSum()); IntegerSum sum2 = new IntegerSum(0); ImmutableList<Integer> list2 = Lists.immutable.ofAll(FJIterateTest.createIntegerList(7)); FJIterate.forEach(list2, new SumProcedure(sum2), new SumCombiner(sum2)); Assert.assertEquals(7, sum2.getSum()); IntegerSum sum3 = new IntegerSum(0); ImmutableList<Integer> list3 = Lists.immutable.ofAll(FJIterateTest.createIntegerList(15)); FJIterate.forEach(list3, new SumProcedure(sum3), new SumCombiner(sum3), 1, list3.size() / 2); Assert.assertEquals(15, sum3.getSum()); IntegerSum sum4 = new IntegerSum(0); ImmutableList<Integer> list4 = Lists.immutable.ofAll(FJIterateTest.createIntegerList(35)); FJIterate.forEach(list4, new SumProcedure(sum4), new SumCombiner(sum4)); Assert.assertEquals(35, sum4.getSum()); IntegerSum sum5 = new IntegerSum(0); ImmutableList<Integer> list5 = FastList.newList(list4).toImmutable(); FJIterate.forEach(list5, new SumProcedure(sum5), new SumCombiner(sum5)); Assert.assertEquals(35, sum5.getSum()); IntegerSum sum6 = new IntegerSum(0); ImmutableList<Integer> list6 = Lists.immutable.ofAll(FJIterateTest.createIntegerList(40)); FJIterate.forEach(list6, new SumProcedure(sum6), new SumCombiner(sum6), 1, list6.size() / 2); Assert.assertEquals(40, sum6.getSum()); IntegerSum sum7 = new IntegerSum(0); ImmutableList<Integer> list7 = FastList.newList(list6).toImmutable(); FJIterate.forEach(list7, new SumProcedure(sum7), new SumCombiner(sum7), 1, list6.size() / 2); Assert.assertEquals(40, sum7.getSum()); }
@Test public void testForEachWithException() { Verify.assertThrows(RuntimeException.class, new Runnable() { public void run() { FJIterate.forEach( FJIterateTest.createIntegerList(5), new PassThruProcedureFactory<>(EXCEPTION_PROCEDURE), new PassThruCombiner<Procedure<Integer>>(), 1, 5); } }); }