use of org.eclipse.collections.api.iterator.BooleanIterator in project eclipse-collections by eclipse.
the class ObjectBooleanHashMapValuesTestCase method booleanIterator.
@Override
@Test
public void booleanIterator() {
MutableBooleanCollection bag = this.newWith(true, false, true, true);
BooleanArrayList list = BooleanArrayList.newListWith(true, false, true, true);
BooleanIterator iterator1 = bag.booleanIterator();
for (int i = 0; i < 4; i++) {
Assert.assertTrue(iterator1.hasNext());
Assert.assertTrue(list.remove(iterator1.next()));
}
Verify.assertEmpty(list);
Assert.assertFalse(iterator1.hasNext());
Verify.assertThrows(NoSuchElementException.class, (Runnable) iterator1::next);
ObjectBooleanHashMap<String> map2 = new ObjectBooleanHashMap<>();
for (int each = 2; each < 100; each++) {
map2.put(String.valueOf(each), each % 2 == 0);
}
MutableBooleanIterator iterator2 = map2.booleanIterator();
while (iterator2.hasNext()) {
iterator2.next();
iterator2.remove();
}
Assert.assertTrue(map2.isEmpty());
}
use of org.eclipse.collections.api.iterator.BooleanIterator in project eclipse-collections by eclipse.
the class AbstractObjectBooleanMapTestCase method iterator.
@Test
public void iterator() {
ObjectBooleanMap<String> map1 = this.newWithKeysValues(null, true, "EclipseCollections", false);
ObjectBooleanMap<String> map2 = this.newWithKeysValues("0", true);
ObjectBooleanMap<String> map3 = this.newWithKeysValues("0", false);
BooleanIterator iterator1 = map1.booleanIterator();
Assert.assertTrue(iterator1.hasNext());
boolean first = iterator1.next();
Assert.assertTrue(iterator1.hasNext());
boolean second = iterator1.next();
Assert.assertEquals(first, !second);
Assert.assertFalse(iterator1.hasNext());
Verify.assertThrows(NoSuchElementException.class, (Runnable) iterator1::next);
BooleanIterator iterator2 = map2.booleanIterator();
Assert.assertTrue(iterator2.hasNext());
Assert.assertTrue(iterator2.next());
Assert.assertFalse(iterator2.hasNext());
Verify.assertThrows(NoSuchElementException.class, (Runnable) iterator2::next);
BooleanIterator iterator3 = map3.booleanIterator();
Assert.assertTrue(iterator3.hasNext());
Assert.assertFalse(iterator3.next());
Assert.assertFalse(iterator3.hasNext());
Verify.assertThrows(NoSuchElementException.class, (Runnable) iterator3::next);
}
use of org.eclipse.collections.api.iterator.BooleanIterator in project eclipse-collections by eclipse.
the class AbstractBooleanListTestCase method booleanIterator.
@Override
@Test
public void booleanIterator() {
BooleanIterator iterator = this.classUnderTest().booleanIterator();
Assert.assertTrue(iterator.hasNext());
Assert.assertTrue(iterator.next());
Assert.assertTrue(iterator.hasNext());
Assert.assertFalse(iterator.next());
Assert.assertTrue(iterator.hasNext());
Assert.assertTrue(iterator.next());
Assert.assertFalse(iterator.hasNext());
}
use of org.eclipse.collections.api.iterator.BooleanIterator in project eclipse-collections by eclipse.
the class ObjectBooleanHashMap 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()) {
BooleanIterator iterator = this.booleanIterator();
while (iterator.hasNext()) {
MutableBooleanBag batch = BooleanBags.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.iterator.BooleanIterator in project eclipse-collections by eclipse.
the class BooleanHashSet method removeAll.
@Override
public boolean removeAll(BooleanIterable source) {
if (this.isEmpty() || source.isEmpty()) {
return false;
}
boolean modified = false;
BooleanIterator iterator = source.booleanIterator();
while (iterator.hasNext()) {
if (this.state == 0) {
return modified;
}
boolean item = iterator.next();
if (this.remove(item)) {
modified = true;
}
}
return modified;
}
Aggregations