Search in sources :

Example 1 with BooleanBag

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

the class BooleanHashBag method addAll.

@Override
public boolean addAll(BooleanIterable source) {
    if (source.isEmpty()) {
        return false;
    }
    if (source instanceof BooleanBag) {
        BooleanBag otherBag = (BooleanBag) source;
        otherBag.forEachWithOccurrences(this::addOccurrences);
    } else {
        BooleanIterator iterator = source.booleanIterator();
        while (iterator.hasNext()) {
            boolean each = iterator.next();
            this.add(each);
        }
    }
    return true;
}
Also used : MutableBooleanBag(org.eclipse.collections.api.bag.primitive.MutableBooleanBag) BooleanBag(org.eclipse.collections.api.bag.primitive.BooleanBag) ImmutableBooleanBag(org.eclipse.collections.api.bag.primitive.ImmutableBooleanBag) BooleanIterator(org.eclipse.collections.api.iterator.BooleanIterator) MutableBooleanIterator(org.eclipse.collections.api.iterator.MutableBooleanIterator)

Example 2 with BooleanBag

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

the class BooleanHashBag method removeAll.

@Override
public boolean removeAll(BooleanIterable source) {
    if (source.isEmpty()) {
        return false;
    }
    int oldSize = this.size();
    if (source instanceof BooleanBag) {
        BooleanBag otherBag = (BooleanBag) source;
        otherBag.forEachWithOccurrences((each, occurrences) -> {
            if (each) {
                this.trueCount = 0;
            } else {
                this.falseCount = 0;
            }
        });
    } else {
        BooleanIterator iterator = source.booleanIterator();
        while (iterator.hasNext()) {
            boolean each = iterator.next();
            if (each) {
                this.trueCount = 0;
            } else {
                this.falseCount = 0;
            }
        }
    }
    return this.size() != oldSize;
}
Also used : MutableBooleanBag(org.eclipse.collections.api.bag.primitive.MutableBooleanBag) BooleanBag(org.eclipse.collections.api.bag.primitive.BooleanBag) ImmutableBooleanBag(org.eclipse.collections.api.bag.primitive.ImmutableBooleanBag) BooleanIterator(org.eclipse.collections.api.iterator.BooleanIterator) MutableBooleanIterator(org.eclipse.collections.api.iterator.MutableBooleanIterator)

Aggregations

BooleanBag (org.eclipse.collections.api.bag.primitive.BooleanBag)2 ImmutableBooleanBag (org.eclipse.collections.api.bag.primitive.ImmutableBooleanBag)2 MutableBooleanBag (org.eclipse.collections.api.bag.primitive.MutableBooleanBag)2 BooleanIterator (org.eclipse.collections.api.iterator.BooleanIterator)2 MutableBooleanIterator (org.eclipse.collections.api.iterator.MutableBooleanIterator)2