Search in sources :

Example 16 with MutableBooleanBag

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

the class AbstractMutableBooleanBagTestCase method collect.

@Override
@Test
public void collect() {
    super.collect();
    MutableBooleanBag bag = this.newWith(true, false, false, true, true, true);
    BooleanToObjectFunction<String> stringValueOf = parameter -> parameter ? "true" : "false";
    Assert.assertEquals(HashBag.newBagWith("true", "false", "false", "true", "true", "true"), bag.collect(stringValueOf));
    MutableBooleanBag bag1 = this.newWith(false, false);
    Assert.assertEquals(HashBag.newBagWith("false", "false"), bag1.collect(stringValueOf));
    MutableBooleanBag bag2 = this.newWith(true, true);
    Assert.assertEquals(HashBag.newBagWith("true", "true"), bag2.collect(stringValueOf));
}
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 17 with MutableBooleanBag

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

the class AbstractBag method collectBoolean.

@Override
public <R extends MutableBooleanCollection> R collectBoolean(BooleanFunction<? super T> booleanFunction, R target) {
    if (target instanceof MutableBooleanBag) {
        MutableBooleanBag targetBag = (MutableBooleanBag) target;
        this.forEachWithOccurrences((each, occurrences) -> targetBag.addOccurrences(booleanFunction.booleanValueOf(each), occurrences));
    } else {
        this.forEachWithOccurrences((each, occurrences) -> {
            boolean value = booleanFunction.booleanValueOf(each);
            for (int i = 0; i < occurrences; i++) {
                target.add(value);
            }
        });
    }
    return target;
}
Also used : MutableBooleanBag(org.eclipse.collections.api.bag.primitive.MutableBooleanBag)

Example 18 with MutableBooleanBag

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

the class BooleanHashBag 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()) {
        if (this.size() <= size) {
            result.add(BooleanBags.mutable.withAll(this));
        } else {
            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 19 with MutableBooleanBag

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

the class BooleanHashBag method reject.

@Override
public MutableBooleanBag reject(BooleanPredicate predicate) {
    MutableBooleanBag result = new BooleanHashBag();
    this.forEachWithOccurrences((each, occurrences) -> {
        if (!predicate.accept(each)) {
            result.addOccurrences(each, occurrences);
        }
    });
    return result;
}
Also used : MutableBooleanBag(org.eclipse.collections.api.bag.primitive.MutableBooleanBag)

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