use of org.eclipse.collections.api.set.MutableSet in project eclipse-collections by eclipse.
the class AbstractMutableSetTestCase method removeIf.
@Override
@Test
public void removeIf() {
super.removeIf();
MutableSet<IntegerWithCast> set = this.newWith();
MutableList<IntegerWithCast> collisions = COLLISIONS.collect(IntegerWithCast::new);
set.addAll(collisions);
collisions.reverseForEach(each -> {
Assert.assertFalse(set.remove(null));
Assert.assertTrue(set.remove(each));
Assert.assertFalse(set.remove(each));
Assert.assertFalse(set.remove(null));
Assert.assertFalse(set.remove(new IntegerWithCast(COLLISION_10)));
});
Assert.assertEquals(UnifiedSet.<IntegerWithCast>newSet(), set);
collisions.forEach(Procedures.cast(each -> {
MutableSet<IntegerWithCast> set2 = this.newWith();
set2.addAll(collisions);
Assert.assertFalse(set2.remove(null));
Assert.assertTrue(set2.remove(each));
Assert.assertFalse(set2.remove(each));
Assert.assertFalse(set2.remove(null));
Assert.assertFalse(set2.remove(new IntegerWithCast(COLLISION_10)));
}));
// remove the second-to-last item in a fully populated single chain to cause the last item to move
MutableSet<Integer> set3 = this.newWith(COLLISION_1, COLLISION_2, COLLISION_3, COLLISION_4);
Assert.assertTrue(set3.remove(COLLISION_3));
Assert.assertEquals(UnifiedSet.newSetWith(COLLISION_1, COLLISION_2, COLLISION_4), set3);
Assert.assertTrue(set3.remove(COLLISION_2));
Assert.assertEquals(UnifiedSet.newSetWith(COLLISION_1, COLLISION_4), set3);
// search a chain for a non-existent element
MutableSet<Integer> chain = this.newWith(COLLISION_1, COLLISION_2, COLLISION_3, COLLISION_4);
Assert.assertFalse(chain.remove(COLLISION_5));
// search a deep chain for a non-existent element
MutableSet<Integer> deepChain = this.newWith(COLLISION_1, COLLISION_2, COLLISION_3, COLLISION_4, COLLISION_5, COLLISION_6, COLLISION_7);
Assert.assertFalse(deepChain.remove(COLLISION_8));
// search for a non-existent element
MutableSet<Integer> empty = this.newWith();
Assert.assertFalse(empty.remove(COLLISION_1));
}
use of org.eclipse.collections.api.set.MutableSet in project eclipse-collections by eclipse.
the class AbstractMutableSetTestCase method tap.
@Override
@Test
public void tap() {
super.tap();
int size = MORE_COLLISIONS.size();
for (int i = 1; i < size; i++) {
MutableList<Integer> tapResult = Lists.mutable.of();
MutableSet<Integer> set = this.newWith();
set.addAll(MORE_COLLISIONS.subList(0, i));
Assert.assertSame(set, set.tap(tapResult::add));
Assert.assertEquals(set.toList(), tapResult);
}
// test iterating on a bucket with only one element
MutableSet<Integer> set = this.newWith(COLLISION_1, COLLISION_2);
set.remove(COLLISION_2);
Counter counter = new Counter();
Assert.assertSame(set, set.tap(x -> counter.increment()));
Assert.assertEquals(1, counter.getCount());
}
Aggregations