Search in sources :

Example 21 with BooleanIterator

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

the class ImmutableFalseSet method newWithAll.

@Override
public ImmutableBooleanSet newWithAll(BooleanIterable elements) {
    ImmutableBooleanSet result = this;
    BooleanIterator booleanIterator = elements.booleanIterator();
    while (booleanIterator.hasNext()) {
        result = result.newWith(booleanIterator.next());
    }
    return result;
}
Also used : ImmutableBooleanSet(org.eclipse.collections.api.set.primitive.ImmutableBooleanSet) BooleanIterator(org.eclipse.collections.api.iterator.BooleanIterator)

Example 22 with BooleanIterator

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

the class ImmutableTrueFalseSet method newWithoutAll.

@Override
public ImmutableBooleanSet newWithoutAll(BooleanIterable elements) {
    ImmutableBooleanSet result = this;
    BooleanIterator booleanIterator = elements.booleanIterator();
    while (booleanIterator.hasNext()) {
        result = result.newWithout(booleanIterator.next());
    }
    return result;
}
Also used : ImmutableBooleanSet(org.eclipse.collections.api.set.primitive.ImmutableBooleanSet) BooleanIterator(org.eclipse.collections.api.iterator.BooleanIterator)

Example 23 with BooleanIterator

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

the class ImmutableBooleanHashSetTest method booleanIterator.

@Override
@Test
public void booleanIterator() {
    BooleanIterator booleanIterator0 = this.emptySet.booleanIterator();
    Assert.assertFalse(booleanIterator0.hasNext());
    Verify.assertThrows(NoSuchElementException.class, (Runnable) booleanIterator0::next);
    BooleanIterator booleanIterator1 = this.falseSet.booleanIterator();
    Assert.assertTrue(booleanIterator1.hasNext());
    Assert.assertFalse(booleanIterator1.next());
    Assert.assertFalse(booleanIterator1.hasNext());
    Verify.assertThrows(NoSuchElementException.class, (Runnable) booleanIterator1::next);
    BooleanIterator booleanIterator2 = this.trueSet.booleanIterator();
    Assert.assertTrue(booleanIterator2.hasNext());
    Assert.assertTrue(booleanIterator2.next());
    Assert.assertFalse(booleanIterator2.hasNext());
    Verify.assertThrows(NoSuchElementException.class, (Runnable) booleanIterator2::next);
    BooleanIterator booleanIterator3 = this.trueFalseSet.booleanIterator();
    Assert.assertTrue(booleanIterator3.hasNext());
    BooleanHashSet actual = new BooleanHashSet();
    actual.add(booleanIterator3.next());
    Assert.assertTrue(booleanIterator3.hasNext());
    actual.add(booleanIterator3.next());
    Assert.assertEquals(BooleanHashSet.newSetWith(true, false), actual);
    Assert.assertFalse(booleanIterator3.hasNext());
    Verify.assertThrows(NoSuchElementException.class, (Runnable) booleanIterator3::next);
}
Also used : BooleanIterator(org.eclipse.collections.api.iterator.BooleanIterator) Test(org.junit.Test)

Example 24 with BooleanIterator

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

the class AbstractBooleanStackTestCase method booleanIterator.

@Override
@Test
public void booleanIterator() {
    BooleanIterator iterator = this.classUnderTest().booleanIterator();
    int size = this.classUnderTest().size();
    for (int i = 0; i < size; i++) {
        Assert.assertTrue(iterator.hasNext());
        boolean sizeEven = (size & 1) == 0;
        boolean iEven = (i & 1) == 0;
        Assert.assertEquals(sizeEven != iEven, iterator.next());
    }
    Assert.assertFalse(iterator.hasNext());
    Assert.assertEquals((this.classUnderTest().size() & 1) != 0, this.classUnderTest().booleanIterator().next());
}
Also used : BooleanIterator(org.eclipse.collections.api.iterator.BooleanIterator) Test(org.junit.Test)

Example 25 with BooleanIterator

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

the class CollectBooleanIterableTest method iterator.

@Test
public void iterator() {
    long count = 0;
    long isTrueCount = 0;
    BooleanIterator iterator = this.booleanIterable.booleanIterator();
    while (iterator.hasNext()) {
        count++;
        if (iterator.next()) {
            isTrueCount++;
        }
    }
    Assert.assertEquals(3L, count);
    Assert.assertEquals(2L, isTrueCount);
}
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