Search in sources :

Example 6 with BooleanHashBag

use of org.eclipse.collections.impl.bag.mutable.primitive.BooleanHashBag 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 7 with BooleanHashBag

use of org.eclipse.collections.impl.bag.mutable.primitive.BooleanHashBag in project eclipse-collections by eclipse.

the class MapIterableTestCase method collectBooleanWithTarget.

@Test
public void collectBooleanWithTarget() {
    BooleanHashBag target = new BooleanHashBag();
    MapIterable<String, String> map = this.newMapWithKeysValues("One", "true", "Two", "nah", "Three", "TrUe");
    BooleanHashBag result = map.collectBoolean(Boolean::parseBoolean, target);
    Assert.assertSame("Target sent as parameter not returned", target, result);
    Assert.assertEquals(BooleanHashBag.newBagWith(true, false, true), result.toBag());
}
Also used : BooleanHashBag(org.eclipse.collections.impl.bag.mutable.primitive.BooleanHashBag) Test(org.junit.Test)

Example 8 with BooleanHashBag

use of org.eclipse.collections.impl.bag.mutable.primitive.BooleanHashBag in project eclipse-collections by eclipse.

the class AbstractObjectBooleanMapTestCase method select.

@Test
public void select() {
    Assert.assertEquals(BooleanHashBag.newBagWith(true, true), this.classUnderTest().select(BooleanPredicates.isTrue()).toBag());
    Assert.assertEquals(BooleanHashBag.newBagWith(false), this.classUnderTest().select(BooleanPredicates.isFalse()).toBag());
    Assert.assertEquals(BooleanHashBag.newBagWith(true, true, false), this.classUnderTest().select(BooleanPredicates.or(BooleanPredicates.isTrue(), BooleanPredicates.isFalse())).toBag());
    Assert.assertEquals(new BooleanHashBag(), this.classUnderTest().select(BooleanPredicates.and(BooleanPredicates.isTrue(), BooleanPredicates.isFalse())).toBag());
    Assert.assertEquals(this.newWithKeysValues("0", true), this.classUnderTest().select((object, value) -> (Integer.parseInt(object) & 1) == 0 && value));
    Assert.assertEquals(this.newWithKeysValues("2", false), this.classUnderTest().select((object, value) -> (Integer.parseInt(object) & 1) == 0 && !value));
    Assert.assertEquals(ObjectBooleanHashMap.newMap(), this.classUnderTest().select((object, value) -> (Integer.parseInt(object) & 1) != 0 && !value));
}
Also used : Arrays(java.util.Arrays) UnifiedMap(org.eclipse.collections.impl.map.mutable.UnifiedMap) BooleanIterator(org.eclipse.collections.api.iterator.BooleanIterator) ObjectBooleanMap(org.eclipse.collections.api.map.primitive.ObjectBooleanMap) BooleanHashBag(org.eclipse.collections.impl.bag.mutable.primitive.BooleanHashBag) Test(org.junit.Test) BooleanPredicates(org.eclipse.collections.impl.block.factory.primitive.BooleanPredicates) Verify(org.eclipse.collections.impl.test.Verify) ImmutableObjectBooleanMap(org.eclipse.collections.api.map.primitive.ImmutableObjectBooleanMap) FastList(org.eclipse.collections.impl.list.mutable.FastList) BooleanArrayList(org.eclipse.collections.impl.list.mutable.primitive.BooleanArrayList) NoSuchElementException(java.util.NoSuchElementException) Assert(org.junit.Assert) BooleanHashSet(org.eclipse.collections.impl.set.mutable.primitive.BooleanHashSet) BooleanHashBag(org.eclipse.collections.impl.bag.mutable.primitive.BooleanHashBag) Test(org.junit.Test)

Example 9 with BooleanHashBag

use of org.eclipse.collections.impl.bag.mutable.primitive.BooleanHashBag in project eclipse-collections by eclipse.

the class ImmutableObjectBooleanSingletonMapTest method select.

@Override
@Test
public void select() {
    Assert.assertEquals(this.classUnderTest(), this.classUnderTest().select((object1, value3) -> true));
    Assert.assertEquals(this.getEmptyMap(), this.classUnderTest().select((object, value2) -> false));
    Assert.assertEquals(new BooleanHashBag(), this.classUnderTest().select(value1 -> false).toBag());
    Assert.assertEquals(BooleanHashBag.newBagWith(true), this.classUnderTest().select(value -> true).toBag());
}
Also used : BooleanIterator(org.eclipse.collections.api.iterator.BooleanIterator) ObjectBooleanMap(org.eclipse.collections.api.map.primitive.ObjectBooleanMap) BooleanHashBag(org.eclipse.collections.impl.bag.mutable.primitive.BooleanHashBag) Test(org.junit.Test) BooleanPredicates(org.eclipse.collections.impl.block.factory.primitive.BooleanPredicates) Verify(org.eclipse.collections.impl.test.Verify) ImmutableObjectBooleanMap(org.eclipse.collections.api.map.primitive.ImmutableObjectBooleanMap) FastList(org.eclipse.collections.impl.list.mutable.FastList) ObjectBooleanHashMap(org.eclipse.collections.impl.map.mutable.primitive.ObjectBooleanHashMap) BooleanArrayList(org.eclipse.collections.impl.list.mutable.primitive.BooleanArrayList) NoSuchElementException(java.util.NoSuchElementException) Assert(org.junit.Assert) BooleanHashSet(org.eclipse.collections.impl.set.mutable.primitive.BooleanHashSet) BooleanHashBag(org.eclipse.collections.impl.bag.mutable.primitive.BooleanHashBag) Test(org.junit.Test)

Example 10 with BooleanHashBag

use of org.eclipse.collections.impl.bag.mutable.primitive.BooleanHashBag in project eclipse-collections by eclipse.

the class AbstractImmutableMap method collectBoolean.

@Override
public ImmutableBooleanBag collectBoolean(BooleanFunction<? super V> booleanFunction) {
    MutableBooleanBag result = new BooleanHashBag();
    this.forEach(new CollectBooleanProcedure<>(booleanFunction, result));
    return result.toImmutable();
}
Also used : BooleanHashBag(org.eclipse.collections.impl.bag.mutable.primitive.BooleanHashBag) MutableBooleanBag(org.eclipse.collections.api.bag.primitive.MutableBooleanBag)

Aggregations

BooleanHashBag (org.eclipse.collections.impl.bag.mutable.primitive.BooleanHashBag)23 Test (org.junit.Test)21 NoSuchElementException (java.util.NoSuchElementException)8 BooleanArrayList (org.eclipse.collections.impl.list.mutable.primitive.BooleanArrayList)8 Assert (org.junit.Assert)8 BooleanIterator (org.eclipse.collections.api.iterator.BooleanIterator)7 FastList (org.eclipse.collections.impl.list.mutable.FastList)7 Verify (org.eclipse.collections.impl.test.Verify)7 ImmutableObjectBooleanMap (org.eclipse.collections.api.map.primitive.ImmutableObjectBooleanMap)6 ObjectBooleanMap (org.eclipse.collections.api.map.primitive.ObjectBooleanMap)6 BooleanHashSet (org.eclipse.collections.impl.set.mutable.primitive.BooleanHashSet)6 BooleanPredicates (org.eclipse.collections.impl.block.factory.primitive.BooleanPredicates)4 UnifiedMap (org.eclipse.collections.impl.map.mutable.UnifiedMap)4 ObjectBooleanHashMap (org.eclipse.collections.impl.map.mutable.primitive.ObjectBooleanHashMap)3 Arrays (java.util.Arrays)2 MutableBooleanBag (org.eclipse.collections.api.bag.primitive.MutableBooleanBag)2 Collections (java.util.Collections)1 Comparator (java.util.Comparator)1 Iterator (java.util.Iterator)1 List (java.util.List)1