bag.retainAll(retains);
assertEquals("Should have 2 total items", 2, bag.size());
}
public void testIterator() {
Bag bag = makeBag();
bag.add("A");
bag.add("A");
bag.add("B");
assertEquals("Bag should have 3 items", 3, bag.size());
Iterator i = bag.iterator();
boolean foundA = false;
while (i.hasNext()) {
String element = (String) i.next();
// ignore the first A, remove the second via Iterator.remove()
if (element.equals("A")) {
if (foundA == false) {
foundA = true;
} else {
i.remove();
}
}
}
assertTrue("Bag should still contain 'A'", bag.contains("A"));
assertEquals("Bag should have 2 items", 2, bag.size());
assertEquals("Bag should have 1 'A'", 1, bag.getCount("A"));
}