@Override public boolean addAll(Collection<? extends Integer> c) { boolean setChanged = false; for (Integer i : c) { if (!this.contains(i)) { setChanged = true; this.add(i); } } return setChanged; }
@Test public void testSimpleAdd() throws IllegalAccessException, InstantiationException { for (Class<? extends MutableBitmap> clazz : clazzes) { MutableBitmap wrappedBitmap = clazz.newInstance(); IntSetTestUtility.addAllToMutable(wrappedBitmap, IntSetTestUtility.getSetBits()); IntegerSet integerSet = IntegerSet.wrap(wrappedBitmap); Set<Integer> set = IntSetTestUtility.getSetBits(); set.add(999); integerSet.add(999); Assert.assertTrue(Sets.difference(integerSet, set).isEmpty()); integerSet.add(58577); Assert.assertFalse(Sets.difference(integerSet, set).isEmpty()); } }
@Test public void testIntOverflow() throws IllegalAccessException, InstantiationException { for (Class<? extends MutableBitmap> clazz : clazzes) { Exception e = null; try { MutableBitmap wrappedBitmap = clazz.newInstance(); IntSetTestUtility.addAllToMutable(wrappedBitmap, IntSetTestUtility.getSetBits()); IntegerSet integerSet = IntegerSet.wrap(wrappedBitmap); integerSet.add(Integer.MAX_VALUE + 1); } catch (IllegalArgumentException ex) { e = ex; } Assert.assertNotNull(e); } }
@Test public void testIsEmpty() throws IllegalAccessException, InstantiationException { for (Class<? extends MutableBitmap> clazz : clazzes) { MutableBitmap wrappedBitmap = clazz.newInstance(); IntSetTestUtility.addAllToMutable(wrappedBitmap, IntSetTestUtility.getSetBits()); IntegerSet integerSet = IntegerSet.wrap(wrappedBitmap); Assert.assertFalse(integerSet.isEmpty()); integerSet.clear(); Assert.assertTrue(integerSet.isEmpty()); integerSet.add(1); Assert.assertFalse(integerSet.isEmpty()); } }
@Override public boolean addAll(Collection<? extends Integer> c) { boolean setChanged = false; for (Integer i : c) { if (!this.contains(i)) { setChanged = true; this.add(i); } } return setChanged; }