RangeSet extends AbstractSet<Long> implements Set<Long> { @Override public boolean remove(Object o) { Long value = ((Number) o).longValue(); Map.Entry<Long, LongSegment> entry = map.floorEntry(value); if (entry == null) { return false; } if (!entry.getValue().contains(value)) { return false; } if (entry.getValue().getMin() < value) { map.put(entry.getValue().getMin(), new LongSegment(entry.getValue().getMin(), value - 1)); } else { map.remove(entry.getValue().getMin()); } if (entry.getValue().getMax() > value) { map.put(value + 1, new LongSegment(value + 1, entry.getValue().getMax())); } size--; return true; }  @Override int size(); @Override boolean contains(Object o); @Override Iterator<Long> iterator(); @Override boolean add(Long aLong); @Override boolean remove(Object o); @Override boolean removeAll(Collection<?> c); @Override void clear();  }
@Test(groups = "fast") public void testRemove() throws Exception { Assert.assertTrue(set.isEmpty()); Assert.assertEquals(set.size(), 0); Assert.assertTrue(set.addAll(Arrays.asList(0L, 2L, 3L, 5L, 6L, 8L, 9L, 10L))); Assert.assertEquals(set.size(), 8); Assert.assertFalse(set.remove(-1L)); Assert.assertFalse(set.remove(1L)); Assert.assertFalse(set.remove(4L)); Assert.assertEquals(set.size(), 8); Assert.assertTrue(set.remove(0L)); Assert.assertFalse(set.contains(0L)); Assert.assertEquals(set.size(), 7); Assert.assertTrue(set.remove(2L)); Assert.assertFalse(set.contains(2L)); Assert.assertEquals(set.size(), 6); Assert.assertTrue(set.remove(6L)); Assert.assertFalse(set.contains(6L)); Assert.assertEquals(set.size(), 5); Assert.assertTrue(set.remove(9L)); Assert.assertFalse(set.contains(9L)); Assert.assertEquals(set.size(), 4); }