Search in sources :

Example 41 with BooleanIterable

use of org.eclipse.collections.api.BooleanIterable 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 42 with BooleanIterable

use of org.eclipse.collections.api.BooleanIterable in project eclipse-collections by eclipse.

the class ReverseBooleanIterableTest method contains.

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

Example 43 with BooleanIterable

use of org.eclipse.collections.api.BooleanIterable in project eclipse-collections by eclipse.

the class ReverseBooleanIterableTest method isEmpty.

@Test
public void isEmpty() {
    BooleanIterable iterable = BooleanArrayList.newListWith(false, false, true).asReversed();
    Verify.assertEmpty(new BooleanArrayList().asReversed());
    Verify.assertNotEmpty(iterable);
}
Also used : BooleanIterable(org.eclipse.collections.api.BooleanIterable) BooleanArrayList(org.eclipse.collections.impl.list.mutable.primitive.BooleanArrayList) Test(org.junit.Test)

Example 44 with BooleanIterable

use of org.eclipse.collections.api.BooleanIterable in project eclipse-collections by eclipse.

the class AbstractRichIterableTestCase method collectBoolean.

@Test
public void collectBoolean() {
    BooleanIterable result = this.newWith(1, 0).collectBoolean(PrimitiveFunctions.integerIsPositive());
    Assert.assertEquals(BooleanBags.mutable.of(true, false), result.toBag());
    Assert.assertEquals(BooleanBags.mutable.of(true, false), BooleanBags.mutable.ofAll(result));
}
Also used : BooleanIterable(org.eclipse.collections.api.BooleanIterable) Test(org.junit.Test)

Example 45 with BooleanIterable

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

Aggregations

BooleanIterable (org.eclipse.collections.api.BooleanIterable)54 Test (org.junit.Test)47 LazyBooleanIterable (org.eclipse.collections.api.LazyBooleanIterable)27 BooleanIterator (org.eclipse.collections.api.iterator.BooleanIterator)11 BooleanArrayList (org.eclipse.collections.impl.list.mutable.primitive.BooleanArrayList)8 MutableBooleanBag (org.eclipse.collections.api.bag.primitive.MutableBooleanBag)4 MutableBooleanIterator (org.eclipse.collections.api.iterator.MutableBooleanIterator)4 MutableBooleanList (org.eclipse.collections.api.list.primitive.MutableBooleanList)2 ReverseBooleanIterable (org.eclipse.collections.impl.lazy.primitive.ReverseBooleanIterable)2 NoSuchElementException (java.util.NoSuchElementException)1 MutableBooleanCollection (org.eclipse.collections.api.collection.primitive.MutableBooleanCollection)1 BooleanHashBag (org.eclipse.collections.impl.bag.mutable.primitive.BooleanHashBag)1 BooleanPredicates (org.eclipse.collections.impl.block.factory.primitive.BooleanPredicates)1 FastList (org.eclipse.collections.impl.list.mutable.FastList)1 MutableInteger (org.eclipse.collections.impl.math.MutableInteger)1 AbstractBooleanIterable (org.eclipse.collections.impl.primitive.AbstractBooleanIterable)1 SynchronizedBooleanIterable (org.eclipse.collections.impl.primitive.SynchronizedBooleanIterable)1 BooleanHashSet (org.eclipse.collections.impl.set.mutable.primitive.BooleanHashSet)1 Verify (org.eclipse.collections.impl.test.Verify)1 Assert (org.junit.Assert)1