use of org.eclipse.collections.api.BooleanIterable 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.BooleanIterable in project eclipse-collections by eclipse.
the class AbstractRichIterableTestCase method collectBooleanWithTarget.
@Test
public void collectBooleanWithTarget() {
MutableBooleanCollection target = new BooleanArrayList();
BooleanIterable result = this.newWith(1, 0).collectBoolean(PrimitiveFunctions.integerIsPositive(), target);
Assert.assertSame("Target list sent as parameter not returned", target, result);
Assert.assertEquals(BooleanBags.mutable.of(true, false), result.toBag());
}
use of org.eclipse.collections.api.BooleanIterable in project eclipse-collections by eclipse.
the class AbstractBooleanIterableTestCase method noneSatisfy.
@Test
public void noneSatisfy() {
BooleanIterable booleanIterable = this.classUnderTest();
int size = booleanIterable.size();
Assert.assertEquals(size == 0, booleanIterable.noneSatisfy(BooleanPredicates.isTrue()));
Assert.assertEquals(size <= 1, booleanIterable.noneSatisfy(BooleanPredicates.isFalse()));
Assert.assertTrue(this.newWith().noneSatisfy(BooleanPredicates.isTrue()));
Assert.assertTrue(this.newWith().noneSatisfy(BooleanPredicates.isFalse()));
Assert.assertTrue(this.newWith(false, false).noneSatisfy(BooleanPredicates.isTrue()));
Assert.assertTrue(this.newWith(true, true).noneSatisfy(BooleanPredicates.isFalse()));
Assert.assertFalse(this.newWith(true, true).noneSatisfy(BooleanPredicates.isTrue()));
Assert.assertTrue(this.newWith(false, false, false).noneSatisfy(BooleanPredicates.isTrue()));
}
use of org.eclipse.collections.api.BooleanIterable in project eclipse-collections by eclipse.
the class AbstractBooleanIterableTestCase method toList.
@Test
public void toList() {
BooleanIterable iterable = this.newWith(true, false);
Assert.assertTrue(BooleanArrayList.newListWith(false, true).equals(iterable.toList()) || BooleanArrayList.newListWith(true, false).equals(iterable.toList()));
BooleanIterable iterable1 = this.newWith(true);
Assert.assertEquals(BooleanArrayList.newListWith(true), iterable1.toList());
BooleanIterable iterable0 = this.newWith();
Assert.assertEquals(BooleanArrayList.newListWith(), iterable0.toList());
}
use of org.eclipse.collections.api.BooleanIterable in project eclipse-collections by eclipse.
the class AbstractBooleanIterableTestCase method select.
@Test
public void select() {
BooleanIterable iterable = this.classUnderTest();
int size = iterable.size();
int halfSize = size / 2;
Verify.assertSize((size & 1) == 1 ? halfSize + 1 : halfSize, iterable.select(BooleanPredicates.isTrue()));
Verify.assertSize(halfSize, iterable.select(BooleanPredicates.isFalse()));
BooleanIterable iterable1 = this.newWith(false, true, false, false, true, true, true);
Assert.assertEquals(this.newMutableCollectionWith(true, true, true, true), iterable1.select(BooleanPredicates.isTrue()));
Assert.assertEquals(this.newMutableCollectionWith(false, false, false), iterable1.select(BooleanPredicates.isFalse()));
}
Aggregations