Search in sources :

Example 1 with MutableBooleanList

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

the class BooleanArrayStack method peek.

@Override
public BooleanList peek(int count) {
    this.checkPositiveValueForCount(count);
    this.checkSizeLessThanCount(count);
    if (count == 0) {
        return new BooleanArrayList(0);
    }
    MutableBooleanList subList = new BooleanArrayList(count);
    int index = this.delegate.size() - 1;
    for (int i = 0; i < count; i++) {
        subList.add(this.delegate.get(index - i));
    }
    return subList;
}
Also used : BooleanArrayList(org.eclipse.collections.impl.list.mutable.primitive.BooleanArrayList) MutableBooleanList(org.eclipse.collections.api.list.primitive.MutableBooleanList)

Example 2 with MutableBooleanList

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

the class BooleanArrayList 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(BooleanLists.mutable.withAll(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);
            }
        }
    }
    return result;
}
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) MutableBooleanIterator(org.eclipse.collections.api.iterator.MutableBooleanIterator)

Example 3 with MutableBooleanList

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

the class ArrayListIterateTest method collectBooleanWithTargetOverOptimizeLimit.

@Test
public void collectBooleanWithTargetOverOptimizeLimit() {
    ArrayList<Integer> list = new ArrayList<>(Interval.zeroTo(OVER_OPTIMIZED_LIMIT));
    MutableBooleanList target = new BooleanArrayList();
    MutableBooleanList actual = ArrayListIterate.collectBoolean(list, PrimitiveFunctions.integerIsPositive(), target);
    BooleanArrayList expected = new BooleanArrayList(list.size());
    expected.add(false);
    for (int i = 1; i <= OVER_OPTIMIZED_LIMIT; i++) {
        expected.add(true);
    }
    Assert.assertEquals(expected, actual);
    Assert.assertSame("Target sent as parameter was not returned as result", target, actual);
}
Also used : BooleanArrayList(org.eclipse.collections.impl.list.mutable.primitive.BooleanArrayList) DoubleArrayList(org.eclipse.collections.impl.list.mutable.primitive.DoubleArrayList) ShortArrayList(org.eclipse.collections.impl.list.mutable.primitive.ShortArrayList) IntArrayList(org.eclipse.collections.impl.list.mutable.primitive.IntArrayList) ByteArrayList(org.eclipse.collections.impl.list.mutable.primitive.ByteArrayList) CharArrayList(org.eclipse.collections.impl.list.mutable.primitive.CharArrayList) FloatArrayList(org.eclipse.collections.impl.list.mutable.primitive.FloatArrayList) LongArrayList(org.eclipse.collections.impl.list.mutable.primitive.LongArrayList) ArrayList(java.util.ArrayList) BooleanArrayList(org.eclipse.collections.impl.list.mutable.primitive.BooleanArrayList) MutableBooleanList(org.eclipse.collections.api.list.primitive.MutableBooleanList) Test(org.junit.Test)

Example 4 with MutableBooleanList

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

the class ArrayListIterateTest method collectBooleanWithTarget.

@Test
public void collectBooleanWithTarget() {
    ArrayList<Integer> list = this.createIntegerList();
    MutableBooleanList target = new BooleanArrayList();
    MutableBooleanList actual = ArrayListIterate.collectBoolean(list, PrimitiveFunctions.integerIsPositive(), target);
    Assert.assertSame("Target list sent as parameter not returned", target, actual);
    Assert.assertEquals(BooleanArrayList.newListWith(false, false, true), actual);
}
Also used : BooleanArrayList(org.eclipse.collections.impl.list.mutable.primitive.BooleanArrayList) MutableBooleanList(org.eclipse.collections.api.list.primitive.MutableBooleanList) Test(org.junit.Test)

Example 5 with MutableBooleanList

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

the class ArrayListIterateTest method collectBooleanOverOptimizeLimit.

@Test
public void collectBooleanOverOptimizeLimit() {
    ArrayList<Integer> list = new ArrayList<>(Interval.zeroTo(OVER_OPTIMIZED_LIMIT));
    MutableBooleanList actual = ArrayListIterate.collectBoolean(list, PrimitiveFunctions.integerIsPositive());
    BooleanArrayList expected = new BooleanArrayList(list.size());
    expected.add(false);
    for (int i = 1; i <= OVER_OPTIMIZED_LIMIT; i++) {
        expected.add(true);
    }
    Assert.assertEquals(expected, actual);
}
Also used : BooleanArrayList(org.eclipse.collections.impl.list.mutable.primitive.BooleanArrayList) DoubleArrayList(org.eclipse.collections.impl.list.mutable.primitive.DoubleArrayList) ShortArrayList(org.eclipse.collections.impl.list.mutable.primitive.ShortArrayList) IntArrayList(org.eclipse.collections.impl.list.mutable.primitive.IntArrayList) ByteArrayList(org.eclipse.collections.impl.list.mutable.primitive.ByteArrayList) CharArrayList(org.eclipse.collections.impl.list.mutable.primitive.CharArrayList) FloatArrayList(org.eclipse.collections.impl.list.mutable.primitive.FloatArrayList) LongArrayList(org.eclipse.collections.impl.list.mutable.primitive.LongArrayList) ArrayList(java.util.ArrayList) BooleanArrayList(org.eclipse.collections.impl.list.mutable.primitive.BooleanArrayList) 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