Search in sources :

Example 16 with BooleanIterator

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

the class ObjectBooleanHashMapValuesTestCase method booleanIterator.

@Override
@Test
public void booleanIterator() {
    MutableBooleanCollection bag = this.newWith(true, false, true, true);
    BooleanArrayList list = BooleanArrayList.newListWith(true, false, true, true);
    BooleanIterator iterator1 = bag.booleanIterator();
    for (int i = 0; i < 4; i++) {
        Assert.assertTrue(iterator1.hasNext());
        Assert.assertTrue(list.remove(iterator1.next()));
    }
    Verify.assertEmpty(list);
    Assert.assertFalse(iterator1.hasNext());
    Verify.assertThrows(NoSuchElementException.class, (Runnable) iterator1::next);
    ObjectBooleanHashMap<String> map2 = new ObjectBooleanHashMap<>();
    for (int each = 2; each < 100; each++) {
        map2.put(String.valueOf(each), each % 2 == 0);
    }
    MutableBooleanIterator iterator2 = map2.booleanIterator();
    while (iterator2.hasNext()) {
        iterator2.next();
        iterator2.remove();
    }
    Assert.assertTrue(map2.isEmpty());
}
Also used : MutableBooleanCollection(org.eclipse.collections.api.collection.primitive.MutableBooleanCollection) BooleanArrayList(org.eclipse.collections.impl.list.mutable.primitive.BooleanArrayList) MutableBooleanIterator(org.eclipse.collections.api.iterator.MutableBooleanIterator) BooleanIterator(org.eclipse.collections.api.iterator.BooleanIterator) MutableBooleanIterator(org.eclipse.collections.api.iterator.MutableBooleanIterator) Test(org.junit.Test)

Example 17 with BooleanIterator

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

the class AbstractObjectBooleanMapTestCase method iterator.

@Test
public void iterator() {
    ObjectBooleanMap<String> map1 = this.newWithKeysValues(null, true, "EclipseCollections", false);
    ObjectBooleanMap<String> map2 = this.newWithKeysValues("0", true);
    ObjectBooleanMap<String> map3 = this.newWithKeysValues("0", false);
    BooleanIterator iterator1 = map1.booleanIterator();
    Assert.assertTrue(iterator1.hasNext());
    boolean first = iterator1.next();
    Assert.assertTrue(iterator1.hasNext());
    boolean second = iterator1.next();
    Assert.assertEquals(first, !second);
    Assert.assertFalse(iterator1.hasNext());
    Verify.assertThrows(NoSuchElementException.class, (Runnable) iterator1::next);
    BooleanIterator iterator2 = map2.booleanIterator();
    Assert.assertTrue(iterator2.hasNext());
    Assert.assertTrue(iterator2.next());
    Assert.assertFalse(iterator2.hasNext());
    Verify.assertThrows(NoSuchElementException.class, (Runnable) iterator2::next);
    BooleanIterator iterator3 = map3.booleanIterator();
    Assert.assertTrue(iterator3.hasNext());
    Assert.assertFalse(iterator3.next());
    Assert.assertFalse(iterator3.hasNext());
    Verify.assertThrows(NoSuchElementException.class, (Runnable) iterator3::next);
}
Also used : BooleanIterator(org.eclipse.collections.api.iterator.BooleanIterator) Test(org.junit.Test)

Example 18 with BooleanIterator

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

the class AbstractBooleanListTestCase method booleanIterator.

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

Example 19 with BooleanIterator

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

the class ObjectBooleanHashMap 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()) {
        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 20 with BooleanIterator

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

the class BooleanHashSet method removeAll.

@Override
public boolean removeAll(BooleanIterable source) {
    if (this.isEmpty() || source.isEmpty()) {
        return false;
    }
    boolean modified = false;
    BooleanIterator iterator = source.booleanIterator();
    while (iterator.hasNext()) {
        if (this.state == 0) {
            return modified;
        }
        boolean item = iterator.next();
        if (this.remove(item)) {
            modified = true;
        }
    }
    return modified;
}
Also used : 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