Search in sources :

Example 11 with BooleanHashSet

use of org.eclipse.collections.impl.set.mutable.primitive.BooleanHashSet in project eclipse-collections by eclipse.

the class BooleanArrayList method distinct.

/**
 * @since 6.0
 */
@Override
public MutableBooleanList distinct() {
    BooleanArrayList target = new BooleanArrayList();
    MutableBooleanSet seenSoFar = new BooleanHashSet();
    for (int i = 0; i < this.size; i++) {
        boolean each = this.get(i);
        if (seenSoFar.add(each)) {
            target.add(each);
        }
    }
    return target;
}
Also used : BooleanHashSet(org.eclipse.collections.impl.set.mutable.primitive.BooleanHashSet) MutableBooleanSet(org.eclipse.collections.api.set.primitive.MutableBooleanSet)

Example 12 with BooleanHashSet

use of org.eclipse.collections.impl.set.mutable.primitive.BooleanHashSet in project eclipse-collections by eclipse.

the class BooleanArrayList method removeAll.

@Override
public boolean removeAll(boolean... source) {
    if (this.isEmpty() || source.length == 0) {
        return false;
    }
    BooleanHashSet set = BooleanHashSet.newSetWith(source);
    if (set.size() == 2) {
        this.items = null;
        this.size = 0;
        return true;
    }
    int oldSize = this.size;
    int trueCount = this.getTrueCount();
    if (set.contains(true)) {
        this.size -= trueCount;
        this.items.set(0, this.size, false);
    } else {
        this.size = trueCount;
        this.items.set(0, this.size, true);
    }
    return oldSize != this.size;
}
Also used : BooleanHashSet(org.eclipse.collections.impl.set.mutable.primitive.BooleanHashSet)

Aggregations

BooleanHashSet (org.eclipse.collections.impl.set.mutable.primitive.BooleanHashSet)12 MutableBooleanSet (org.eclipse.collections.api.set.primitive.MutableBooleanSet)5 Test (org.junit.Test)4 ImmutableBooleanSetFactory (org.eclipse.collections.api.factory.set.primitive.ImmutableBooleanSetFactory)1 ImmutableBooleanSet (org.eclipse.collections.api.set.primitive.ImmutableBooleanSet)1 BooleanArrayList (org.eclipse.collections.impl.list.mutable.primitive.BooleanArrayList)1