Search in sources :

Example 31 with BooleanIterator

use of org.eclipse.collections.api.iterator.BooleanIterator 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)

Example 32 with BooleanIterator

use of org.eclipse.collections.api.iterator.BooleanIterator 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 33 with BooleanIterator

use of org.eclipse.collections.api.iterator.BooleanIterator in project eclipse-collections by eclipse.

the class BooleanArrayStack method writeExternal.

@Override
public void writeExternal(ObjectOutput out) throws IOException {
    out.writeInt(this.size());
    BooleanIterator iterator = this.delegate.asReversed().booleanIterator();
    while (iterator.hasNext()) {
        boolean each = iterator.next();
        out.writeBoolean(each);
    }
}
Also used : BooleanIterator(org.eclipse.collections.api.iterator.BooleanIterator) MutableBooleanIterator(org.eclipse.collections.api.iterator.MutableBooleanIterator) UnmodifiableBooleanIterator(org.eclipse.collections.impl.iterator.UnmodifiableBooleanIterator)

Example 34 with BooleanIterator

use of org.eclipse.collections.api.iterator.BooleanIterator in project eclipse-collections by eclipse.

the class ImmutableObjectBooleanEmptyMapTest method iterator.

@Override
@Test
public void iterator() {
    BooleanIterator iterator = this.classUnderTest().booleanIterator();
    Assert.assertFalse(iterator.hasNext());
    Verify.assertThrows(NoSuchElementException.class, (Runnable) iterator::next);
}
Also used : BooleanIterator(org.eclipse.collections.api.iterator.BooleanIterator) Test(org.junit.Test)

Example 35 with BooleanIterator

use of org.eclipse.collections.api.iterator.BooleanIterator in project eclipse-collections by eclipse.

the class ImmutableObjectBooleanSingletonMapTest method iterator.

@Override
@Test
public void iterator() {
    BooleanIterator iterator = this.classUnderTest().booleanIterator();
    Assert.assertTrue(iterator.hasNext());
    Assert.assertTrue(iterator.next());
    Assert.assertFalse(iterator.hasNext());
    Verify.assertThrows(NoSuchElementException.class, (Runnable) iterator::next);
}
Also used : BooleanIterator(org.eclipse.collections.api.iterator.BooleanIterator) Test(org.junit.Test)

Aggregations

BooleanIterator (org.eclipse.collections.api.iterator.BooleanIterator)39 Test (org.junit.Test)22 BooleanIterable (org.eclipse.collections.api.BooleanIterable)10 MutableBooleanIterator (org.eclipse.collections.api.iterator.MutableBooleanIterator)10 LazyBooleanIterable (org.eclipse.collections.api.LazyBooleanIterable)7 MutableBooleanBag (org.eclipse.collections.api.bag.primitive.MutableBooleanBag)6 ImmutableBooleanSet (org.eclipse.collections.api.set.primitive.ImmutableBooleanSet)5 BooleanBag (org.eclipse.collections.api.bag.primitive.BooleanBag)2 ImmutableBooleanBag (org.eclipse.collections.api.bag.primitive.ImmutableBooleanBag)2 MutableBooleanList (org.eclipse.collections.api.list.primitive.MutableBooleanList)2 ReverseBooleanIterable (org.eclipse.collections.impl.lazy.primitive.ReverseBooleanIterable)2 BooleanArrayList (org.eclipse.collections.impl.list.mutable.primitive.BooleanArrayList)2 BitSet (java.util.BitSet)1 MutableBooleanCollection (org.eclipse.collections.api.collection.primitive.MutableBooleanCollection)1 BooleanHashBag (org.eclipse.collections.impl.bag.mutable.primitive.BooleanHashBag)1 ImmutableEmptyBooleanIterator (org.eclipse.collections.impl.iterator.ImmutableEmptyBooleanIterator)1 UnmodifiableBooleanIterator (org.eclipse.collections.impl.iterator.UnmodifiableBooleanIterator)1 AbstractBooleanIterable (org.eclipse.collections.impl.primitive.AbstractBooleanIterable)1 SynchronizedBooleanIterable (org.eclipse.collections.impl.primitive.SynchronizedBooleanIterable)1