use of org.eclipse.collections.api.iterator.BooleanIterator in project eclipse-collections by eclipse.
the class ImmutableBooleanArrayList method newWithAll.
@Override
public ImmutableBooleanList newWithAll(BooleanIterable elements) {
BitSet newItems = (BitSet) this.items.clone();
int index = 0;
for (BooleanIterator booleanIterator = elements.booleanIterator(); booleanIterator.hasNext(); index++) {
if (booleanIterator.next()) {
newItems.set(this.size + index);
}
}
return new ImmutableBooleanArrayList(newItems, this.size + elements.size());
}
use of org.eclipse.collections.api.iterator.BooleanIterator 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();
}
use of org.eclipse.collections.api.iterator.BooleanIterator in project eclipse-collections by eclipse.
the class AbstractBooleanIterableTestCase method iterator_throws.
@Test(expected = NoSuchElementException.class)
public void iterator_throws() {
BooleanIterator iterator = this.classUnderTest().booleanIterator();
while (iterator.hasNext()) {
iterator.next();
}
iterator.next();
}
use of org.eclipse.collections.api.iterator.BooleanIterator in project eclipse-collections by eclipse.
the class AbstractBooleanIterableTestCase method booleanIterator.
@Test
public void booleanIterator() {
BooleanArrayList list = BooleanArrayList.newListWith(true, false, true);
BooleanIterator iterator = this.classUnderTest().booleanIterator();
for (int i = 0; i < 3; i++) {
Assert.assertTrue(iterator.hasNext());
Assert.assertTrue(list.remove(iterator.next()));
}
Verify.assertEmpty(list);
Assert.assertFalse(iterator.hasNext());
}
Aggregations