CountingBytesSource extends AbstractChainedSource<byte[], byte[], byte[], byte[]> implements HashedKeySource<byte[], byte[]> { @Override public void delete(byte[] key) { synchronized (this) { int srcCount; byte[] srcVal = null; if (filter == null || filter.maybeContains(key)) { srcVal = getSource().get(key); srcCount = decodeCount(srcVal); } else { srcCount = 1; } if (srcCount > 1) { getSource().put(key, encodeCount(decodeValue(srcVal), srcCount - 1)); } else { getSource().delete(key); } } } CountingBytesSource(Source<byte[], byte[]> src);  CountingBytesSource(Source<byte[], byte[]> src, boolean bloom); @Override void put(byte[] key, byte[] val); @Override byte[] get(byte[] key); @Override void delete(byte[] key);  }
@Test public void testDelete() { src.put(intToKey(0), intToValue(0)); src.delete(intToKey(0)); assertNull(src.get(intToKey(0))); src.put(intToKey(0), intToValue(0)); src.put(intToKey(0), intToValue(0)); src.delete(intToKey(0)); assertEquals(str(intToValue(0)), str(src.get(intToKey(0)))); src.delete(intToKey(0)); assertNull(src.get(intToKey(0))); src.put(intToKey(1), intToValue(1)); src.put(intToKey(1), intToValue(1)); src.put(intToKey(1), null); assertEquals(str(intToValue(1)), str(src.get(intToKey(1)))); src.put(intToKey(1), null); assertNull(src.get(intToKey(1))); src.put(intToKey(1), intToValue(1)); src.put(intToKey(1), intToValue(2)); src.delete(intToKey(1)); assertEquals(str(intToValue(2)), str(src.get(intToKey(1)))); src.delete(intToKey(1)); assertNull(src.get(intToKey(1))); }