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;
}
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;
}
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);
}
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);
}
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);
}
Aggregations