Search in sources :

Example 11 with MutableBooleanBag

use of org.eclipse.collections.api.bag.primitive.MutableBooleanBag in project eclipse-collections by eclipse.

the class ObjectBooleanHashMap method chunk.

@Override
public RichIterable<BooleanIterable> chunk(int size) {
    if (size <= 0) {
        throw new IllegalArgumentException("Size for groups must be positive but was: " + size);
    }
    MutableList<BooleanIterable> result = Lists.mutable.empty();
    if (this.notEmpty()) {
        BooleanIterator iterator = this.booleanIterator();
        while (iterator.hasNext()) {
            MutableBooleanBag batch = BooleanBags.mutable.empty();
            for (int i = 0; i < size && iterator.hasNext(); i++) {
                batch.add(iterator.next());
            }
            result.add(batch);
        }
    }
    return result;
}
Also used : LazyBooleanIterable(org.eclipse.collections.api.LazyBooleanIterable) BooleanIterable(org.eclipse.collections.api.BooleanIterable) MutableBooleanBag(org.eclipse.collections.api.bag.primitive.MutableBooleanBag) BooleanIterator(org.eclipse.collections.api.iterator.BooleanIterator) MutableBooleanIterator(org.eclipse.collections.api.iterator.MutableBooleanIterator)

Example 12 with MutableBooleanBag

use of org.eclipse.collections.api.bag.primitive.MutableBooleanBag 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)

Example 13 with MutableBooleanBag

use of org.eclipse.collections.api.bag.primitive.MutableBooleanBag in project eclipse-collections by eclipse.

the class AbstractMutableMap method collectBoolean.

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

Example 14 with MutableBooleanBag

use of org.eclipse.collections.api.bag.primitive.MutableBooleanBag in project eclipse-collections by eclipse.

the class AbstractMutableBooleanBagTestCase method allSatisfy.

@Override
@Test
public void allSatisfy() {
    super.allSatisfy();
    int[] count = { 0 };
    MutableBooleanBag bag = this.newWith(false, true, false);
    Assert.assertFalse(bag.allSatisfy(value -> {
        count[0]++;
        return !value;
    }));
    Assert.assertEquals(2L, count[0]);
}
Also used : BooleanToObjectFunction(org.eclipse.collections.api.block.function.primitive.BooleanToObjectFunction) Test(org.junit.Test) Verify(org.eclipse.collections.impl.test.Verify) MutableBag(org.eclipse.collections.api.bag.MutableBag) ImmutableBooleanBag(org.eclipse.collections.api.bag.primitive.ImmutableBooleanBag) MutableBooleanCollection(org.eclipse.collections.api.collection.primitive.MutableBooleanCollection) HashBag(org.eclipse.collections.impl.bag.mutable.HashBag) Lists(org.eclipse.collections.impl.factory.Lists) BooleanArrayList(org.eclipse.collections.impl.list.mutable.primitive.BooleanArrayList) MutableBooleanList(org.eclipse.collections.api.list.primitive.MutableBooleanList) AbstractMutableBooleanCollectionTestCase(org.eclipse.collections.impl.collection.mutable.primitive.AbstractMutableBooleanCollectionTestCase) PrimitiveTuples(org.eclipse.collections.impl.tuple.primitive.PrimitiveTuples) Assert(org.junit.Assert) MutableBooleanBag(org.eclipse.collections.api.bag.primitive.MutableBooleanBag) MutableBooleanBag(org.eclipse.collections.api.bag.primitive.MutableBooleanBag) Test(org.junit.Test)

Example 15 with MutableBooleanBag

use of org.eclipse.collections.api.bag.primitive.MutableBooleanBag in project eclipse-collections by eclipse.

the class AbstractMutableBooleanBagTestCase method addAllIterable.

@Override
@Test
public void addAllIterable() {
    super.addAllIterable();
    MutableBooleanBag bag = this.newWith();
    Assert.assertTrue(bag.addAll(BooleanArrayList.newListWith(true, false, true, false, true)));
    Assert.assertFalse(bag.addAll(new BooleanArrayList()));
    Assert.assertEquals(BooleanHashBag.newBagWith(true, false, true, false, true), bag);
    Assert.assertTrue(bag.addAll(BooleanHashBag.newBagWith(true, false, true, false, true)));
    Assert.assertEquals(BooleanHashBag.newBagWith(false, false, false, false, true, true, true, true, true, true), bag);
}
Also used : BooleanArrayList(org.eclipse.collections.impl.list.mutable.primitive.BooleanArrayList) MutableBooleanBag(org.eclipse.collections.api.bag.primitive.MutableBooleanBag) Test(org.junit.Test)

Aggregations

MutableBooleanBag (org.eclipse.collections.api.bag.primitive.MutableBooleanBag)19 Test (org.junit.Test)9 BooleanArrayList (org.eclipse.collections.impl.list.mutable.primitive.BooleanArrayList)5 BooleanIterable (org.eclipse.collections.api.BooleanIterable)4 LazyBooleanIterable (org.eclipse.collections.api.LazyBooleanIterable)4 MutableBag (org.eclipse.collections.api.bag.MutableBag)4 ImmutableBooleanBag (org.eclipse.collections.api.bag.primitive.ImmutableBooleanBag)4 BooleanToObjectFunction (org.eclipse.collections.api.block.function.primitive.BooleanToObjectFunction)4 MutableBooleanCollection (org.eclipse.collections.api.collection.primitive.MutableBooleanCollection)4 BooleanIterator (org.eclipse.collections.api.iterator.BooleanIterator)4 MutableBooleanList (org.eclipse.collections.api.list.primitive.MutableBooleanList)4 HashBag (org.eclipse.collections.impl.bag.mutable.HashBag)4 AbstractMutableBooleanCollectionTestCase (org.eclipse.collections.impl.collection.mutable.primitive.AbstractMutableBooleanCollectionTestCase)4 Lists (org.eclipse.collections.impl.factory.Lists)4 Verify (org.eclipse.collections.impl.test.Verify)4 PrimitiveTuples (org.eclipse.collections.impl.tuple.primitive.PrimitiveTuples)4 Assert (org.junit.Assert)4 MutableBooleanIterator (org.eclipse.collections.api.iterator.MutableBooleanIterator)3 BooleanHashBag (org.eclipse.collections.impl.bag.mutable.primitive.BooleanHashBag)2 AbstractBooleanIterable (org.eclipse.collections.impl.primitive.AbstractBooleanIterable)1