Search in sources :

Example 1 with Procedure

use of org.eclipse.collections.api.block.procedure.Procedure in project eclipse-collections by eclipse.

the class RichIterableTestCase method RichIterable_iterationOrder.

@Test
default void RichIterable_iterationOrder() {
    MutableCollection<Integer> expectedIterationOrder = this.expectedIterationOrder();
    Procedure<Object> noop = each -> {
    };
    MutableCollection<Integer> selectIterationOrder = this.newMutableForFilter();
    this.getInstanceUnderTest().select(selectIterationOrder::add).forEach(noop);
    assertEquals(expectedIterationOrder, selectIterationOrder);
    MutableCollection<Integer> selectTargetIterationOrder = this.newMutableForFilter();
    this.getInstanceUnderTest().select(selectTargetIterationOrder::add, new HashBag<>());
    assertEquals(expectedIterationOrder, selectTargetIterationOrder);
    MutableCollection<Integer> selectWithIterationOrder = this.newMutableForFilter();
    this.getInstanceUnderTest().selectWith((each, param) -> selectWithIterationOrder.add(each), null).forEach(noop);
    assertEquals(expectedIterationOrder, selectWithIterationOrder);
    MutableCollection<Integer> selectWithTargetIterationOrder = this.newMutableForFilter();
    this.getInstanceUnderTest().selectWith((each, param) -> selectWithTargetIterationOrder.add(each), null, new HashBag<>());
    assertEquals(expectedIterationOrder, selectWithTargetIterationOrder);
    MutableCollection<Integer> rejectIterationOrder = this.newMutableForFilter();
    this.getInstanceUnderTest().reject(rejectIterationOrder::add).forEach(noop);
    assertEquals(expectedIterationOrder, rejectIterationOrder);
    MutableCollection<Integer> rejectTargetIterationOrder = this.newMutableForFilter();
    this.getInstanceUnderTest().reject(rejectTargetIterationOrder::add, new HashBag<>());
    assertEquals(expectedIterationOrder, rejectTargetIterationOrder);
    MutableCollection<Integer> rejectWithIterationOrder = this.newMutableForFilter();
    this.getInstanceUnderTest().rejectWith((each, param) -> rejectWithIterationOrder.add(each), null).forEach(noop);
    assertEquals(expectedIterationOrder, rejectWithIterationOrder);
    MutableCollection<Integer> rejectWithTargetIterationOrder = this.newMutableForFilter();
    this.getInstanceUnderTest().rejectWith((each, param) -> rejectWithTargetIterationOrder.add(each), null, new HashBag<>());
    assertEquals(expectedIterationOrder, rejectWithTargetIterationOrder);
    MutableCollection<Integer> partitionIterationOrder = this.newMutableForFilter();
    this.getInstanceUnderTest().partition(partitionIterationOrder::add);
    assertEquals(expectedIterationOrder, partitionIterationOrder);
    MutableCollection<Integer> partitionWithIterationOrder = this.newMutableForFilter();
    this.getInstanceUnderTest().partitionWith((each, param) -> partitionWithIterationOrder.add(each), null);
    assertEquals(expectedIterationOrder, partitionWithIterationOrder);
    MutableCollection<Integer> collectIterationOrder = this.newMutableForFilter();
    this.getInstanceUnderTest().collect(collectIterationOrder::add).forEach(noop);
    assertEquals(expectedIterationOrder, collectIterationOrder);
    MutableCollection<Integer> collectTargetIterationOrder = this.newMutableForFilter();
    this.getInstanceUnderTest().collect(collectTargetIterationOrder::add, new HashBag<>());
    assertEquals(expectedIterationOrder, collectTargetIterationOrder);
    MutableCollection<Integer> collectWithIterationOrder = this.newMutableForFilter();
    this.getInstanceUnderTest().collectWith((each, param) -> collectWithIterationOrder.add(each), null).forEach(noop);
    assertEquals(expectedIterationOrder, collectWithIterationOrder);
    MutableCollection<Integer> collectWithTargetIterationOrder = this.newMutableForFilter();
    this.getInstanceUnderTest().collectWith((each, param) -> collectWithTargetIterationOrder.add(each), null, new HashBag<>());
    assertEquals(expectedIterationOrder, collectWithTargetIterationOrder);
    MutableCollection<Integer> collectIfPredicateIterationOrder = this.newMutableForFilter();
    MutableCollection<Integer> collectIfFunctionIterationOrder = this.newMutableForFilter();
    this.getInstanceUnderTest().collectIf(collectIfPredicateIterationOrder::add, collectIfFunctionIterationOrder::add).forEach(noop);
    assertEquals(expectedIterationOrder, collectIfPredicateIterationOrder);
    assertEquals(expectedIterationOrder, collectIfFunctionIterationOrder);
    MutableCollection<Integer> collectIfPredicateTargetIterationOrder = this.newMutableForFilter();
    MutableCollection<Integer> collectIfFunctionTargetIterationOrder = this.newMutableForFilter();
    this.getInstanceUnderTest().collectIf(collectIfPredicateTargetIterationOrder::add, collectIfFunctionTargetIterationOrder::add, new HashBag<>());
    assertEquals(expectedIterationOrder, collectIfPredicateTargetIterationOrder);
    assertEquals(expectedIterationOrder, collectIfFunctionTargetIterationOrder);
    MutableCollection<Integer> collectBooleanIterationOrder = this.newMutableForFilter();
    this.getInstanceUnderTest().collectBoolean(collectBooleanIterationOrder::add).forEach(each -> {
    });
    assertEquals(expectedIterationOrder, collectBooleanIterationOrder);
    MutableCollection<Integer> collectBooleanTargetIterationOrder = this.newMutableForFilter();
    this.getInstanceUnderTest().collectBoolean(collectBooleanTargetIterationOrder::add, new BooleanHashBag());
    assertEquals(expectedIterationOrder, collectBooleanTargetIterationOrder);
    MutableCollection<Integer> collectByteIterationOrder = this.newMutableForFilter();
    this.getInstanceUnderTest().collectByte((Integer each) -> {
        collectByteIterationOrder.add(each);
        return (byte) 0;
    }).forEach(each -> {
    });
    assertEquals(expectedIterationOrder, collectByteIterationOrder);
    MutableCollection<Integer> collectByteTargetIterationOrder = this.newMutableForFilter();
    this.getInstanceUnderTest().collectByte((Integer each) -> {
        collectByteTargetIterationOrder.add(each);
        return (byte) 0;
    }, new ByteHashBag());
    assertEquals(expectedIterationOrder, collectByteTargetIterationOrder);
    MutableCollection<Integer> collectCharIterationOrder = this.newMutableForFilter();
    this.getInstanceUnderTest().collectChar((Integer each) -> {
        collectCharIterationOrder.add(each);
        return ' ';
    }).forEach(each -> {
    });
    assertEquals(expectedIterationOrder, collectCharIterationOrder);
    MutableCollection<Integer> collectCharTargetIterationOrder = this.newMutableForFilter();
    this.getInstanceUnderTest().collectChar((Integer each) -> {
        collectCharTargetIterationOrder.add(each);
        return ' ';
    }, new CharHashBag());
    assertEquals(expectedIterationOrder, collectCharTargetIterationOrder);
    MutableCollection<Integer> collectDoubleIterationOrder = this.newMutableForFilter();
    this.getInstanceUnderTest().collectDouble((Integer each) -> {
        collectDoubleIterationOrder.add(each);
        return 0.0;
    }).forEach(each -> {
    });
    assertEquals(expectedIterationOrder, collectDoubleIterationOrder);
    MutableCollection<Integer> collectDoubleTargetIterationOrder = this.newMutableForFilter();
    this.getInstanceUnderTest().collectDouble((Integer each) -> {
        collectDoubleTargetIterationOrder.add(each);
        return 0.0;
    }, new DoubleHashBag());
    assertEquals(expectedIterationOrder, collectDoubleTargetIterationOrder);
    MutableCollection<Integer> collectFloatIterationOrder = this.newMutableForFilter();
    this.getInstanceUnderTest().collectFloat((Integer each) -> {
        collectFloatIterationOrder.add(each);
        return 0.0f;
    }).forEach(each -> {
    });
    assertEquals(expectedIterationOrder, collectFloatIterationOrder);
    MutableCollection<Integer> collectFloatTargetIterationOrder = this.newMutableForFilter();
    this.getInstanceUnderTest().collectFloat((Integer each) -> {
        collectFloatTargetIterationOrder.add(each);
        return 0.0f;
    }, new FloatHashBag());
    assertEquals(expectedIterationOrder, collectFloatTargetIterationOrder);
    MutableCollection<Integer> collectIntIterationOrder = this.newMutableForFilter();
    this.getInstanceUnderTest().collectInt((Integer each) -> {
        collectIntIterationOrder.add(each);
        return 0;
    }).forEach(each -> {
    });
    assertEquals(expectedIterationOrder, collectIntIterationOrder);
    MutableCollection<Integer> collectIntTargetIterationOrder = this.newMutableForFilter();
    this.getInstanceUnderTest().collectInt((Integer each) -> {
        collectIntTargetIterationOrder.add(each);
        return 0;
    }, new IntHashBag());
    assertEquals(expectedIterationOrder, collectIntTargetIterationOrder);
    MutableCollection<Integer> collectLongIterationOrder = this.newMutableForFilter();
    this.getInstanceUnderTest().collectLong((Integer each) -> {
        collectLongIterationOrder.add(each);
        return 0L;
    }).forEach(each -> {
    });
    assertEquals(expectedIterationOrder, collectLongIterationOrder);
    MutableCollection<Integer> collectLongTargetIterationOrder = this.newMutableForFilter();
    this.getInstanceUnderTest().collectLong((Integer each) -> {
        collectLongTargetIterationOrder.add(each);
        return 0L;
    }, new LongHashBag());
    assertEquals(expectedIterationOrder, collectLongTargetIterationOrder);
    MutableCollection<Integer> collectShortIterationOrder = this.newMutableForFilter();
    this.getInstanceUnderTest().collectShort((ShortFunction<Integer>) each -> {
        collectShortIterationOrder.add(each);
        return (short) 0;
    }).forEach(each -> {
    });
    assertEquals(expectedIterationOrder, collectShortIterationOrder);
    MutableCollection<Integer> collectShortTargetIterationOrder = this.newMutableForFilter();
    this.getInstanceUnderTest().collectShort((ShortFunction<Integer>) each -> {
        collectShortTargetIterationOrder.add(each);
        return (short) 0;
    }, new ShortHashBag());
    assertEquals(expectedIterationOrder, collectShortTargetIterationOrder);
    MutableCollection<Integer> flatCollectIterationOrder = this.newMutableForFilter();
    this.getInstanceUnderTest().flatCollect(each -> Lists.immutable.with(flatCollectIterationOrder.add(each))).forEach(noop);
    assertEquals(expectedIterationOrder, flatCollectIterationOrder);
    MutableCollection<Integer> flatCollectTargetIterationOrder = this.newMutableForFilter();
    this.getInstanceUnderTest().flatCollect(each -> Lists.immutable.with(flatCollectTargetIterationOrder.add(each)), new HashBag<>());
    assertEquals(expectedIterationOrder, flatCollectTargetIterationOrder);
    MutableCollection<Integer> countIterationOrder = this.newMutableForFilter();
    this.getInstanceUnderTest().count(countIterationOrder::add);
    assertEquals(expectedIterationOrder, countIterationOrder);
    MutableCollection<Integer> countWithIterationOrder = this.newMutableForFilter();
    this.getInstanceUnderTest().countWith((each, param) -> countWithIterationOrder.add(each), null);
    assertEquals(expectedIterationOrder, countWithIterationOrder);
    MutableCollection<Integer> anySatisfyIterationOrder = this.newMutableForFilter();
    this.getInstanceUnderTest().anySatisfy(each -> {
        anySatisfyIterationOrder.add(each);
        return false;
    });
    assertEquals(expectedIterationOrder, anySatisfyIterationOrder);
    MutableCollection<Integer> anySatisfyWithIterationOrder = this.newMutableForFilter();
    this.getInstanceUnderTest().anySatisfyWith((each, param) -> {
        anySatisfyWithIterationOrder.add(each);
        return false;
    }, null);
    assertEquals(expectedIterationOrder, anySatisfyWithIterationOrder);
    MutableCollection<Integer> allSatisfyIterationOrder = this.newMutableForFilter();
    this.getInstanceUnderTest().allSatisfy(each -> {
        allSatisfyIterationOrder.add(each);
        return true;
    });
    assertEquals(expectedIterationOrder, allSatisfyIterationOrder);
    MutableCollection<Integer> allSatisfyWithIterationOrder = this.newMutableForFilter();
    this.getInstanceUnderTest().allSatisfyWith((each, param) -> {
        allSatisfyWithIterationOrder.add(each);
        return true;
    }, null);
    assertEquals(expectedIterationOrder, allSatisfyWithIterationOrder);
    MutableCollection<Integer> noneSatisfyIterationOrder = this.newMutableForFilter();
    this.getInstanceUnderTest().noneSatisfy(each -> {
        noneSatisfyIterationOrder.add(each);
        return false;
    });
    assertEquals(expectedIterationOrder, noneSatisfyIterationOrder);
    MutableCollection<Integer> noneSatisfyWithIterationOrder = this.newMutableForFilter();
    this.getInstanceUnderTest().noneSatisfyWith((each, param) -> {
        noneSatisfyWithIterationOrder.add(each);
        return false;
    }, null);
    assertEquals(expectedIterationOrder, noneSatisfyWithIterationOrder);
    MutableCollection<Integer> detectIterationOrder = this.newMutableForFilter();
    this.getInstanceUnderTest().detect(each -> {
        detectIterationOrder.add(each);
        return false;
    });
    assertEquals(expectedIterationOrder, detectIterationOrder);
    MutableCollection<Integer> detectWithIterationOrder = this.newMutableForFilter();
    this.getInstanceUnderTest().detectWith((each, param) -> {
        detectWithIterationOrder.add(each);
        return false;
    }, null);
    assertEquals(expectedIterationOrder, detectWithIterationOrder);
    MutableCollection<Integer> detectIfNoneIterationOrder = this.newMutableForFilter();
    this.getInstanceUnderTest().detectIfNone(each -> {
        detectIfNoneIterationOrder.add(each);
        return false;
    }, () -> 0);
    assertEquals(expectedIterationOrder, detectIfNoneIterationOrder);
    MutableCollection<Integer> detectWithIfNoneIterationOrder = this.newMutableForFilter();
    this.getInstanceUnderTest().detectWithIfNone((each, param) -> {
        detectWithIfNoneIterationOrder.add(each);
        return false;
    }, null, () -> 0);
    assertEquals(expectedIterationOrder, detectWithIfNoneIterationOrder);
    MutableCollection<Integer> minComparatorIterationOrder = this.newMutableForFilter();
    this.getInstanceUnderTest().min((o1, o2) -> {
        if (minComparatorIterationOrder.isEmpty()) {
            minComparatorIterationOrder.add(o2);
        }
        minComparatorIterationOrder.add(o1);
        return 0;
    });
    assertEquals(expectedIterationOrder, minComparatorIterationOrder);
    MutableCollection<Integer> maxComparatorIterationOrder = this.newMutableForFilter();
    this.getInstanceUnderTest().max((o1, o2) -> {
        if (maxComparatorIterationOrder.isEmpty()) {
            maxComparatorIterationOrder.add(o2);
        }
        maxComparatorIterationOrder.add(o1);
        return 0;
    });
    assertEquals(expectedIterationOrder, maxComparatorIterationOrder);
    MutableCollection<Integer> minByIterationOrder = this.newMutableForFilter();
    this.getInstanceUnderTest().minBy(minByIterationOrder::add);
    assertEquals(expectedIterationOrder, minByIterationOrder);
    MutableCollection<Integer> maxByIterationOrder = this.newMutableForFilter();
    this.getInstanceUnderTest().maxBy(maxByIterationOrder::add);
    assertEquals(expectedIterationOrder, maxByIterationOrder);
    MutableCollection<Integer> groupByIterationOrder = this.newMutableForFilter();
    this.getInstanceUnderTest().groupBy(groupByIterationOrder::add);
    assertEquals(expectedIterationOrder, groupByIterationOrder);
    MutableCollection<Integer> groupByTargetIterationOrder = this.newMutableForFilter();
    this.getInstanceUnderTest().groupBy(groupByTargetIterationOrder::add, new HashBagMultimap<>());
    assertEquals(expectedIterationOrder, groupByTargetIterationOrder);
    MutableCollection<Integer> groupByEachIterationOrder = this.newMutableForFilter();
    this.getInstanceUnderTest().groupByEach(each -> {
        groupByEachIterationOrder.add(each);
        return Lists.immutable.with(each);
    });
    assertEquals(expectedIterationOrder, groupByEachIterationOrder);
    MutableCollection<Integer> groupByEachTargetIterationOrder = this.newMutableForFilter();
    this.getInstanceUnderTest().groupByEach(each -> {
        groupByEachTargetIterationOrder.add(each);
        return Lists.immutable.with(each);
    }, new HashBagMultimap<>());
    assertEquals(expectedIterationOrder, groupByEachTargetIterationOrder);
    MutableCollection<Integer> sumOfFloatIterationOrder = this.newMutableForFilter();
    this.getInstanceUnderTest().sumOfFloat(each -> {
        sumOfFloatIterationOrder.add(each);
        return each.floatValue();
    });
    assertEquals(expectedIterationOrder, sumOfFloatIterationOrder);
    MutableCollection<Integer> sumOfDoubleIterationOrder = this.newMutableForFilter();
    this.getInstanceUnderTest().sumOfDouble(each -> {
        sumOfDoubleIterationOrder.add(each);
        return each.doubleValue();
    });
    assertEquals(expectedIterationOrder, sumOfDoubleIterationOrder);
    MutableCollection<Integer> sumOfIntIterationOrder = this.newMutableForFilter();
    this.getInstanceUnderTest().sumOfInt(each -> {
        sumOfIntIterationOrder.add(each);
        return each.intValue();
    });
    assertEquals(expectedIterationOrder, sumOfIntIterationOrder);
    MutableCollection<Integer> sumOfLongIterationOrder = this.newMutableForFilter();
    this.getInstanceUnderTest().sumOfLong(each -> {
        sumOfLongIterationOrder.add(each);
        return each.longValue();
    });
    assertEquals(expectedIterationOrder, sumOfLongIterationOrder);
    /*
         * TODO: Fix sumByPrimitive methods for bags, to only iterate once per item, not per occurrence.
        MutableCollection<Integer> sumByDoubleIterationOrder1 = this.newMutableForFilter();
        MutableCollection<Integer> sumByDoubleIterationOrder2 = this.newMutableForFilter();
        this.getInstanceUnderTest().sumByDouble(
                each -> {
                    sumByDoubleIterationOrder1.add(each);
                    return each;
                },
                each -> {
                    sumByDoubleIterationOrder2.add(each);
                    return 0.0;
                });
        assertEquals(expectedIterationOrder, sumByDoubleIterationOrder1);
        assertEquals(expectedIterationOrder, sumByDoubleIterationOrder2);

        MutableCollection<Integer> sumByFloatIterationOrder1 = this.newMutableForFilter();
        MutableCollection<Integer> sumByFloatIterationOrder2 = this.newMutableForFilter();
        this.getInstanceUnderTest().sumByFloat(
                each -> {
                    sumByFloatIterationOrder1.add(each);
                    return each;
                },
                each -> {
                    sumByFloatIterationOrder2.add(each);
                    return 0.0f;
                });
        assertEquals(expectedIterationOrder, sumByFloatIterationOrder1);
        assertEquals(expectedIterationOrder, sumByFloatIterationOrder2);

        MutableCollection<Integer> sumByIntIterationOrder1 = this.newMutableForFilter();
        MutableCollection<Integer> sumByIntIterationOrder2 = this.newMutableForFilter();
        this.getInstanceUnderTest().sumByInt(
                each -> {
                    sumByIntIterationOrder1.add(each);
                    return each;
                },
                each -> {
                    sumByIntIterationOrder2.add(each);
                    return 0;
                });
        assertEquals(expectedIterationOrder, sumByIntIterationOrder1);
        assertEquals(expectedIterationOrder, sumByIntIterationOrder2);

        MutableCollection<Integer> sumByLongIterationOrder1 = this.newMutableForFilter();
        MutableCollection<Integer> sumByLongIterationOrder2 = this.newMutableForFilter();
        this.getInstanceUnderTest().sumByLong(
                each -> {
                    sumByLongIterationOrder1.add(each);
                    return each;
                },
                each -> {
                    sumByLongIterationOrder2.add(each);
                    return 0L;
                });
        assertEquals(expectedIterationOrder, sumByLongIterationOrder1);
        assertEquals(expectedIterationOrder, sumByLongIterationOrder2);
        */
    MutableCollection<Integer> expectedInjectIntoIterationOrder = this.allowsDuplicates() ? this.newMutableForFilter(4, 4, 4, 4, 3, 3, 3, 2, 2, 1) : expectedIterationOrder;
    MutableCollection<Integer> injectIntoIterationOrder = this.newMutableForFilter();
    this.getInstanceUnderTest().injectInto(0, (Function2<Integer, Integer, Integer>) (argument1, argument2) -> {
        injectIntoIterationOrder.add(argument2);
        return argument1 + argument2;
    });
    assertEquals(expectedInjectIntoIterationOrder, injectIntoIterationOrder);
    MutableCollection<Integer> injectIntoIntIterationOrder = this.newMutableForFilter();
    this.getInstanceUnderTest().injectInto(0, (IntObjectToIntFunction<Integer>) (intParameter, objectParameter) -> {
        injectIntoIntIterationOrder.add(objectParameter);
        return intParameter + objectParameter;
    });
    assertEquals(expectedInjectIntoIterationOrder, injectIntoIntIterationOrder);
    MutableCollection<Integer> injectIntoLongIterationOrder = this.newMutableForFilter();
    this.getInstanceUnderTest().injectInto(0L, (LongObjectToLongFunction<Integer>) (longParameter, objectParameter) -> {
        injectIntoLongIterationOrder.add(objectParameter);
        return longParameter + objectParameter;
    });
    assertEquals(expectedInjectIntoIterationOrder, injectIntoLongIterationOrder);
    MutableCollection<Integer> injectIntoDoubleIterationOrder = this.newMutableForFilter();
    this.getInstanceUnderTest().injectInto(0L, (DoubleObjectToDoubleFunction<Integer>) (doubleParameter, objectParameter) -> {
        injectIntoDoubleIterationOrder.add(objectParameter);
        return doubleParameter + objectParameter;
    });
    assertEquals(expectedInjectIntoIterationOrder, injectIntoDoubleIterationOrder);
    MutableCollection<Integer> injectIntoFloatIterationOrder = this.newMutableForFilter();
    this.getInstanceUnderTest().injectInto(0L, (FloatObjectToFloatFunction<Integer>) (floatParameter, objectParameter) -> {
        injectIntoFloatIterationOrder.add(objectParameter);
        return floatParameter + objectParameter;
    });
    assertEquals(expectedInjectIntoIterationOrder, injectIntoFloatIterationOrder);
    Counter toSortedListCount = new Counter();
    this.getInstanceUnderTest().toSortedList((o1, o2) -> {
        toSortedListCount.increment();
        return 0;
    });
    assertEquals(expectedIterationOrder.size() - 1, toSortedListCount.getCount());
    /*
        MutableCollection<Integer> toSortedListByIterationOrder = this.newMutableForFilter();
        this.getInstanceUnderTest().toSortedListBy(toSortedListByIterationOrder::add);
        assertEquals(expectedIterationOrder.size(), toSortedListByIterationOrder.size());

*/
    Counter toSortedSetCount = new Counter();
    this.getInstanceUnderTest().toSortedSet((o1, o2) -> {
        toSortedSetCount.increment();
        return 0;
    });
    assertEquals(expectedIterationOrder.size(), toSortedSetCount.getCount());
    /*
        MutableCollection<Integer> toSortedSetByIterationOrder = this.newMutableForFilter();
        this.getInstanceUnderTest().toSortedSetBy(toSortedSetByIterationOrder::add);
        assertEquals(expectedIterationOrder.size(), toSortedSetByIterationOrder.size());
*/
    Counter toSortedBagCount = new Counter();
    this.getInstanceUnderTest().toSortedBag((o1, o2) -> {
        toSortedBagCount.increment();
        return 0;
    });
    assertEquals(expectedIterationOrder.size(), toSortedBagCount.getCount());
    /*
        MutableCollection<Integer> toSortedBagByIterationOrder = this.newMutableForFilter();
        this.getInstanceUnderTest().toSortedBagBy(toSortedBagByIterationOrder::add);
        assertEquals(expectedIterationOrder.size(), toSortedBagByIterationOrder.size());
*/
    MutableCollection<Integer> summarizeIntOrder = this.newMutableForFilter();
    this.getInstanceUnderTest().summarizeInt(each -> {
        summarizeIntOrder.add(each);
        return 0;
    });
    assertEquals(expectedIterationOrder, summarizeIntOrder);
    MutableCollection<Integer> summarizeFloatOrder = this.newMutableForFilter();
    this.getInstanceUnderTest().summarizeFloat(each -> {
        summarizeFloatOrder.add(each);
        return 0;
    });
    assertEquals(expectedIterationOrder, summarizeFloatOrder);
    MutableCollection<Integer> summarizeLongOrder = this.newMutableForFilter();
    this.getInstanceUnderTest().summarizeLong(each -> {
        summarizeLongOrder.add(each);
        return 0;
    });
    assertEquals(expectedIterationOrder, summarizeLongOrder);
    MutableCollection<Integer> summarizeDoubleOrder = this.newMutableForFilter();
    this.getInstanceUnderTest().summarizeDouble(each -> {
        summarizeDoubleOrder.add(each);
        return 0;
    });
    assertEquals(expectedIterationOrder, summarizeDoubleOrder);
}
Also used : CharHashBag(org.eclipse.collections.impl.bag.mutable.primitive.CharHashBag) Predicate(org.eclipse.collections.api.block.predicate.Predicate) Multimap(org.eclipse.collections.api.multimap.Multimap) Predicate2(org.eclipse.collections.api.block.predicate.Predicate2) MutableBag(org.eclipse.collections.api.bag.MutableBag) MutableList(org.eclipse.collections.api.list.MutableList) LongObjectToLongFunction(org.eclipse.collections.api.block.function.primitive.LongObjectToLongFunction) Assert.assertThat(org.junit.Assert.assertThat) DoubleObjectToDoubleFunction(org.eclipse.collections.api.block.function.primitive.DoubleObjectToDoubleFunction) RichIterable(org.eclipse.collections.api.RichIterable) MutableLongCollection(org.eclipse.collections.api.collection.primitive.MutableLongCollection) HashBag(org.eclipse.collections.impl.bag.mutable.HashBag) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Functions(org.eclipse.collections.impl.block.factory.Functions) Map(java.util.Map) Matchers.nullValue(org.hamcrest.Matchers.nullValue) LongIterable(org.eclipse.collections.api.LongIterable) MutableMultimap(org.eclipse.collections.api.multimap.MutableMultimap) Tuples(org.eclipse.collections.impl.tuple.Tuples) Interval(org.eclipse.collections.impl.list.Interval) Assert.fail(org.junit.Assert.fail) ShortFunction(org.eclipse.collections.api.block.function.primitive.ShortFunction) ShortHashBag(org.eclipse.collections.impl.bag.mutable.primitive.ShortHashBag) Comparators(org.eclipse.collections.impl.block.factory.Comparators) MutableCharCollection(org.eclipse.collections.api.collection.primitive.MutableCharCollection) DoubleHashBag(org.eclipse.collections.impl.bag.mutable.primitive.DoubleHashBag) UnifiedMap(org.eclipse.collections.impl.map.mutable.UnifiedMap) Matchers.isOneOf(org.hamcrest.Matchers.isOneOf) MutableIntCollection(org.eclipse.collections.api.collection.primitive.MutableIntCollection) IntObjectToIntFunction(org.eclipse.collections.api.block.function.primitive.IntObjectToIntFunction) ByteHashBag(org.eclipse.collections.impl.bag.mutable.primitive.ByteHashBag) BooleanHashBag(org.eclipse.collections.impl.bag.mutable.primitive.BooleanHashBag) Procedures(org.eclipse.collections.impl.block.factory.Procedures) Collectors(java.util.stream.Collectors) CharIterable(org.eclipse.collections.api.CharIterable) Objects(java.util.Objects) List(java.util.List) DoubleIterable(org.eclipse.collections.api.DoubleIterable) Lists(org.eclipse.collections.impl.factory.Lists) ObjectDoubleMaps(org.eclipse.collections.impl.factory.primitive.ObjectDoubleMaps) Assert.assertFalse(org.junit.Assert.assertFalse) Optional(java.util.Optional) MutableByteCollection(org.eclipse.collections.api.collection.primitive.MutableByteCollection) Matchers.is(org.hamcrest.Matchers.is) FloatIterable(org.eclipse.collections.api.FloatIterable) Function(org.eclipse.collections.api.block.function.Function) IntIterable(org.eclipse.collections.api.IntIterable) IterableTestCase.assertEquals(org.eclipse.collections.test.IterableTestCase.assertEquals) Bag(org.eclipse.collections.api.bag.Bag) MutableShortCollection(org.eclipse.collections.api.collection.primitive.MutableShortCollection) Procedure(org.eclipse.collections.api.block.procedure.Procedure) LongHashBag(org.eclipse.collections.impl.bag.mutable.primitive.LongHashBag) Verify.assertThrows(org.eclipse.collections.impl.test.Verify.assertThrows) Assert.assertSame(org.junit.Assert.assertSame) IterableTestCase.assertNotEquals(org.eclipse.collections.test.IterableTestCase.assertNotEquals) MutableMap(org.eclipse.collections.api.map.MutableMap) HashBagMultimap(org.eclipse.collections.impl.multimap.bag.HashBagMultimap) Function2(org.eclipse.collections.api.block.function.Function2) TreeBag(org.eclipse.collections.impl.bag.sorted.mutable.TreeBag) ByteIterable(org.eclipse.collections.api.ByteIterable) ImmutableBag(org.eclipse.collections.api.bag.ImmutableBag) NoSuchElementException(java.util.NoSuchElementException) FloatObjectToFloatFunction(org.eclipse.collections.api.block.function.primitive.FloatObjectToFloatFunction) Pair(org.eclipse.collections.api.tuple.Pair) MutableCollection(org.eclipse.collections.api.collection.MutableCollection) Predicates(org.eclipse.collections.impl.block.factory.Predicates) Counter(org.eclipse.collections.impl.Counter) Predicates2(org.eclipse.collections.impl.block.factory.Predicates2) Collectors2(org.eclipse.collections.impl.collector.Collectors2) MutableFloatCollection(org.eclipse.collections.api.collection.primitive.MutableFloatCollection) Iterator(java.util.Iterator) BooleanIterable(org.eclipse.collections.api.BooleanIterable) IntegerPredicates(org.eclipse.collections.impl.block.factory.IntegerPredicates) ShortIterable(org.eclipse.collections.api.ShortIterable) MutableDoubleCollection(org.eclipse.collections.api.collection.primitive.MutableDoubleCollection) SortedSets(org.eclipse.collections.impl.factory.SortedSets) Bags(org.eclipse.collections.impl.factory.Bags) ObjectLongMaps(org.eclipse.collections.impl.factory.primitive.ObjectLongMaps) TreeSortedMap(org.eclipse.collections.impl.map.sorted.mutable.TreeSortedMap) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) MutableBooleanCollection(org.eclipse.collections.api.collection.primitive.MutableBooleanCollection) Assert.assertNull(org.junit.Assert.assertNull) Sets(org.eclipse.collections.impl.factory.Sets) MapIterable(org.eclipse.collections.api.map.MapIterable) PartitionIterable(org.eclipse.collections.api.partition.PartitionIterable) AddFunction(org.eclipse.collections.impl.block.function.AddFunction) FloatHashBag(org.eclipse.collections.impl.bag.mutable.primitive.FloatHashBag) Assert(org.junit.Assert) IntHashBag(org.eclipse.collections.impl.bag.mutable.primitive.IntHashBag) ByteHashBag(org.eclipse.collections.impl.bag.mutable.primitive.ByteHashBag) BooleanHashBag(org.eclipse.collections.impl.bag.mutable.primitive.BooleanHashBag) DoubleHashBag(org.eclipse.collections.impl.bag.mutable.primitive.DoubleHashBag) Counter(org.eclipse.collections.impl.Counter) FloatHashBag(org.eclipse.collections.impl.bag.mutable.primitive.FloatHashBag) LongHashBag(org.eclipse.collections.impl.bag.mutable.primitive.LongHashBag) ShortFunction(org.eclipse.collections.api.block.function.primitive.ShortFunction) IntHashBag(org.eclipse.collections.impl.bag.mutable.primitive.IntHashBag) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) CharHashBag(org.eclipse.collections.impl.bag.mutable.primitive.CharHashBag) ShortHashBag(org.eclipse.collections.impl.bag.mutable.primitive.ShortHashBag) Test(org.junit.Test)

Example 2 with Procedure

use of org.eclipse.collections.api.block.procedure.Procedure in project eclipse-collections by eclipse.

the class SerialParallelLazyPerformanceTest method forEach.

private void forEach(FastList<Integer> collection) {
    MutableList<Runnable> runnables = FastList.newList();
    runnables.add(() -> this.basicSerialForEachPerformance(collection, SERIAL_RUN_COUNT));
    int cores = Runtime.getRuntime().availableProcessors();
    ExecutorService service = Executors.newFixedThreadPool(cores);
    runnables.add(() -> {
        MutableMap<Integer, Boolean> map = new ConcurrentHashMap<>();
        this.basicParallelLazyForEachPerformance(collection, "Lambda", item -> map.put(item, Boolean.TRUE), PARALLEL_RUN_COUNT, cores, service);
    });
    runnables.add(() -> {
        MutableMap<Integer, Boolean> map = new ConcurrentHashMap<>();
        this.basicParallelLazyForEachPerformance(collection, "Procedure", (Procedure<Integer>) each -> map.put(each, Boolean.TRUE), PARALLEL_RUN_COUNT, cores, service);
    });
    runnables.add(() -> {
        MutableMap<Integer, Boolean> map = new ConcurrentHashMap<>();
        this.basicJava8ParallelLazyForEachPerformance(collection, "Lambda", item -> map.put(item, Boolean.TRUE), PARALLEL_RUN_COUNT);
    });
    List<Integer> arrayList = new ArrayList<>(collection);
    runnables.add(() -> {
        MutableMap<Integer, Boolean> map = new ConcurrentHashMap<>();
        this.basicJava8ParallelLazyForEachPerformance(arrayList, "Lambda", item -> map.put(item, Boolean.TRUE), PARALLEL_RUN_COUNT);
    });
    runnables.add(() -> {
        MutableMap<Integer, Boolean> map = new ConcurrentHashMap<>();
        this.basicJava8ParallelLazyForEachPerformance(arrayList, "Consumer", each -> map.put(each, Boolean.TRUE), PARALLEL_RUN_COUNT);
    });
    this.shuffleAndRun(runnables);
    service.shutdown();
    try {
        service.awaitTermination(1, TimeUnit.MINUTES);
    } catch (InterruptedException e) {
        throw new RuntimeException(e);
    }
}
Also used : Arrays(java.util.Arrays) ConcurrentHashMap(org.eclipse.collections.impl.map.mutable.ConcurrentHashMap) Function(org.eclipse.collections.api.block.function.Function) Predicate(org.eclipse.collections.api.block.predicate.Predicate) LoggerFactory(org.slf4j.LoggerFactory) Procedure(org.eclipse.collections.api.block.procedure.Procedure) Verify(org.eclipse.collections.impl.test.Verify) MutableList(org.eclipse.collections.api.list.MutableList) NumberFormat(java.text.NumberFormat) FastList(org.eclipse.collections.impl.list.mutable.FastList) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Function0(org.eclipse.collections.api.block.function.Function0) MutableMap(org.eclipse.collections.api.map.MutableMap) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) After(org.junit.After) Interval(org.eclipse.collections.impl.list.Interval) ExecutorService(java.util.concurrent.ExecutorService) RandomStringUtils(org.apache.commons.lang.RandomStringUtils) Predicates(org.eclipse.collections.impl.block.factory.Predicates) Before(org.junit.Before) ParallelTests(org.eclipse.collections.impl.ParallelTests) Logger(org.slf4j.Logger) IntegerPredicates(org.eclipse.collections.impl.block.factory.IntegerPredicates) Collection(java.util.Collection) Set(java.util.Set) Procedures(org.eclipse.collections.impl.block.factory.Procedures) Test(org.junit.Test) Iterate(org.eclipse.collections.impl.utility.Iterate) Category(org.junit.experimental.categories.Category) Collectors(java.util.stream.Collectors) Executors(java.util.concurrent.Executors) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) List(java.util.List) IntInterval(org.eclipse.collections.impl.list.primitive.IntInterval) Assert(org.junit.Assert) IntProcedure(org.eclipse.collections.api.block.procedure.primitive.IntProcedure) UnifiedSet(org.eclipse.collections.impl.set.mutable.UnifiedSet) ArrayList(java.util.ArrayList) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ExecutorService(java.util.concurrent.ExecutorService) ConcurrentHashMap(org.eclipse.collections.impl.map.mutable.ConcurrentHashMap)

Aggregations

List (java.util.List)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 Collectors (java.util.stream.Collectors)2 Function (org.eclipse.collections.api.block.function.Function)2 Predicate (org.eclipse.collections.api.block.predicate.Predicate)2 Procedure (org.eclipse.collections.api.block.procedure.Procedure)2 MutableList (org.eclipse.collections.api.list.MutableList)2 MutableMap (org.eclipse.collections.api.map.MutableMap)2 IntegerPredicates (org.eclipse.collections.impl.block.factory.IntegerPredicates)2 Predicates (org.eclipse.collections.impl.block.factory.Predicates)2 Procedures (org.eclipse.collections.impl.block.factory.Procedures)2 Interval (org.eclipse.collections.impl.list.Interval)2 Assert (org.junit.Assert)2 Test (org.junit.Test)2 NumberFormat (java.text.NumberFormat)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 HashSet (java.util.HashSet)1 Iterator (java.util.Iterator)1