Search in sources :

Example 41 with MutableBooleanList

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

use of org.eclipse.collections.api.list.primitive.MutableBooleanList in project eclipse-collections by eclipse.

the class ImmutableBooleanArrayList method newWithoutAll.

@Override
public ImmutableBooleanList newWithoutAll(BooleanIterable elements) {
    MutableBooleanList list = this.toList();
    list.removeAll(elements);
    return list.toImmutable();
}
Also used : MutableBooleanList(org.eclipse.collections.api.list.primitive.MutableBooleanList)

Example 43 with MutableBooleanList

use of org.eclipse.collections.api.list.primitive.MutableBooleanList in project eclipse-collections by eclipse.

the class BooleanCaseProcedureTest method oneCaseWithDefault.

@Test
public void oneCaseWithDefault() {
    MutableBooleanList ifOneList = BooleanLists.mutable.empty();
    MutableBooleanList defaultList = BooleanLists.mutable.empty();
    MutableBooleanList list = BooleanLists.mutable.with(true, false);
    BooleanCaseProcedure procedure = new BooleanCaseProcedure(defaultList::add).addCase(value -> value, ifOneList::add);
    list.each(procedure);
    Assert.assertEquals(BooleanLists.mutable.with(true), ifOneList);
    Assert.assertEquals(BooleanLists.mutable.with(false), defaultList);
}
Also used : MutableBooleanList(org.eclipse.collections.api.list.primitive.MutableBooleanList) Test(org.junit.Test)

Example 44 with MutableBooleanList

use of org.eclipse.collections.api.list.primitive.MutableBooleanList in project eclipse-collections by eclipse.

the class BooleanCaseProcedureTest method twoCasesNoDefault.

@Test
public void twoCasesNoDefault() {
    MutableBooleanList ifTrueList = BooleanLists.mutable.empty();
    MutableBooleanList ifFalseList = BooleanLists.mutable.empty();
    MutableBooleanList list = BooleanLists.mutable.with(true, false);
    BooleanCaseProcedure procedure = new BooleanCaseProcedure().addCase(value -> value, ifTrueList::add).addCase(value -> !value, ifFalseList::add);
    list.each(procedure);
    Assert.assertEquals(BooleanLists.mutable.with(true), ifTrueList);
    Assert.assertEquals(BooleanLists.mutable.with(false), ifFalseList);
    Verify.assertContains("BooleanCaseProcedure", procedure.toString());
}
Also used : MutableBooleanList(org.eclipse.collections.api.list.primitive.MutableBooleanList) BooleanLists(org.eclipse.collections.impl.factory.primitive.BooleanLists) Test(org.junit.Test) Verify(org.eclipse.collections.impl.test.Verify) Assert(org.junit.Assert) BooleanList(org.eclipse.collections.api.list.primitive.BooleanList) MutableBooleanList(org.eclipse.collections.api.list.primitive.MutableBooleanList) Test(org.junit.Test)

Aggregations

MutableBooleanList (org.eclipse.collections.api.list.primitive.MutableBooleanList)44 Test (org.junit.Test)38 BooleanArrayList (org.eclipse.collections.impl.list.mutable.primitive.BooleanArrayList)6 ImmutableBooleanCollection (org.eclipse.collections.api.collection.primitive.ImmutableBooleanCollection)4 BooleanIterator (org.eclipse.collections.api.iterator.BooleanIterator)3 BooleanList (org.eclipse.collections.api.list.primitive.BooleanList)3 ImmutableBooleanList (org.eclipse.collections.api.list.primitive.ImmutableBooleanList)3 Verify (org.eclipse.collections.impl.test.Verify)3 Assert (org.junit.Assert)3 ArrayList (java.util.ArrayList)2 BooleanIterable (org.eclipse.collections.api.BooleanIterable)2 LazyBooleanIterable (org.eclipse.collections.api.LazyBooleanIterable)2 BooleanLists (org.eclipse.collections.impl.factory.primitive.BooleanLists)2 ReverseBooleanIterable (org.eclipse.collections.impl.lazy.primitive.ReverseBooleanIterable)2 ByteArrayList (org.eclipse.collections.impl.list.mutable.primitive.ByteArrayList)2 CharArrayList (org.eclipse.collections.impl.list.mutable.primitive.CharArrayList)2 DoubleArrayList (org.eclipse.collections.impl.list.mutable.primitive.DoubleArrayList)2 FloatArrayList (org.eclipse.collections.impl.list.mutable.primitive.FloatArrayList)2 IntArrayList (org.eclipse.collections.impl.list.mutable.primitive.IntArrayList)2 LongArrayList (org.eclipse.collections.impl.list.mutable.primitive.LongArrayList)2