Search in sources :

Example 36 with BooleanIterator

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

the class ImmutableBooleanArrayList method newWithAll.

@Override
public ImmutableBooleanList newWithAll(BooleanIterable elements) {
    BitSet newItems = (BitSet) this.items.clone();
    int index = 0;
    for (BooleanIterator booleanIterator = elements.booleanIterator(); booleanIterator.hasNext(); index++) {
        if (booleanIterator.next()) {
            newItems.set(this.size + index);
        }
    }
    return new ImmutableBooleanArrayList(newItems, this.size + elements.size());
}
Also used : BitSet(java.util.BitSet) BooleanIterator(org.eclipse.collections.api.iterator.BooleanIterator)

Example 37 with BooleanIterator

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

the class ImmutableBooleanArrayList 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(this);
        } else {
            BooleanIterator iterator = this.booleanIterator();
            while (iterator.hasNext()) {
                MutableBooleanList batch = BooleanLists.mutable.empty();
                for (int i = 0; i < size && iterator.hasNext(); i++) {
                    batch.add(iterator.next());
                }
                result.add(batch.toImmutable());
            }
        }
    }
    return result.toImmutable();
}
Also used : ReverseBooleanIterable(org.eclipse.collections.impl.lazy.primitive.ReverseBooleanIterable) LazyBooleanIterable(org.eclipse.collections.api.LazyBooleanIterable) BooleanIterable(org.eclipse.collections.api.BooleanIterable) MutableBooleanList(org.eclipse.collections.api.list.primitive.MutableBooleanList) BooleanIterator(org.eclipse.collections.api.iterator.BooleanIterator)

Example 38 with BooleanIterator

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

the class AbstractBooleanIterableTestCase method iterator_throws.

@Test(expected = NoSuchElementException.class)
public void iterator_throws() {
    BooleanIterator iterator = this.classUnderTest().booleanIterator();
    while (iterator.hasNext()) {
        iterator.next();
    }
    iterator.next();
}
Also used : BooleanIterator(org.eclipse.collections.api.iterator.BooleanIterator) Test(org.junit.Test)

Example 39 with BooleanIterator

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

the class AbstractBooleanIterableTestCase method booleanIterator.

@Test
public void booleanIterator() {
    BooleanArrayList list = BooleanArrayList.newListWith(true, false, true);
    BooleanIterator iterator = this.classUnderTest().booleanIterator();
    for (int i = 0; i < 3; i++) {
        Assert.assertTrue(iterator.hasNext());
        Assert.assertTrue(list.remove(iterator.next()));
    }
    Verify.assertEmpty(list);
    Assert.assertFalse(iterator.hasNext());
}
Also used : BooleanArrayList(org.eclipse.collections.impl.list.mutable.primitive.BooleanArrayList) 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