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));
}
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;
}
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;
}
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;
}
Aggregations