Search in sources :

Example 26 with BooleanIterator

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

the class LazyBooleanIterableAdapterTest method booleanIterator.

@Test
public void booleanIterator() {
    int sum = 0;
    for (BooleanIterator iterator = this.iterable.booleanIterator(); iterator.hasNext(); ) {
        sum += iterator.next() ? 1 : 0;
    }
    Assert.assertEquals(2, sum);
}
Also used : BooleanIterator(org.eclipse.collections.api.iterator.BooleanIterator) Test(org.junit.Test)

Example 27 with BooleanIterator

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

the class ReverseBooleanIterableTest method iterator_throws.

@Test(expected = NoSuchElementException.class)
public void iterator_throws() {
    BooleanIterable iterable = BooleanArrayList.newListWith(false, false, true).asReversed();
    BooleanIterator iterator = iterable.booleanIterator();
    while (iterator.hasNext()) {
        iterator.next();
    }
    iterator.next();
}
Also used : BooleanIterable(org.eclipse.collections.api.BooleanIterable) BooleanIterator(org.eclipse.collections.api.iterator.BooleanIterator) Test(org.junit.Test)

Example 28 with BooleanIterator

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

the class ReverseBooleanIterableTest method iterator.

@Test
public void iterator() {
    BooleanIterable iterable = BooleanArrayList.newListWith(false, false, true).asReversed();
    BooleanIterator iterator = iterable.booleanIterator();
    Assert.assertTrue(iterator.hasNext());
    Assert.assertTrue(iterator.next());
    Assert.assertTrue(iterator.hasNext());
    Assert.assertFalse(iterator.next());
    Assert.assertTrue(iterator.hasNext());
    Assert.assertFalse(iterator.next());
}
Also used : BooleanIterable(org.eclipse.collections.api.BooleanIterable) BooleanIterator(org.eclipse.collections.api.iterator.BooleanIterator) Test(org.junit.Test)

Example 29 with BooleanIterator

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

the class AbstractImmutableBooleanListTestCase method booleanIterator.

@Override
@Test
public void booleanIterator() {
    BooleanIterator iterator = this.classUnderTest().booleanIterator();
    for (int i = 0; iterator.hasNext(); i++) {
        Assert.assertEquals(i % 2 == 0, iterator.next());
    }
    Assert.assertFalse(iterator.hasNext());
}
Also used : BooleanIterator(org.eclipse.collections.api.iterator.BooleanIterator) Test(org.junit.Test)

Example 30 with BooleanIterator

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

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