OoaBFilter { public boolean containsAndAdd(Element element) { ByteBuffer eBytes = element.getByteBuffer(); HashCode code = HASH_FUNC.hashBytes(eBytes.array(), eBytes.arrayOffset() + eBytes.position(), eBytes.remaining()); int index = code.asInt() & sizeMask; boolean seen = true; ByteBuffer buffer = array[index]; synchronized(buffer) { if (!buffer.equals(eBytes)) { seen = false; buffer.put(eBytes); buffer.rewind(); } } return seen; } OoaBFilter(int size, int bufSize); boolean containsAndAdd(Element element); int getSize();  }
@Test public void testTheBasics() { OoaBFilter filter = new OoaBFilter(2, 12); FElement twentyNineId = new FElement(27, 28, 29); FElement thirtyId = new FElement(27, 28, 30); FElement thirtyThreeId = new FElement(27, 28, 33); assertFalse("nothing should be contained at all", filter.containsAndAdd(twentyNineId)); assertTrue("now it should", filter.containsAndAdd(twentyNineId)); assertFalse("false unless the hash collides", filter.containsAndAdd(thirtyId)); assertTrue("original should still return true", filter.containsAndAdd(twentyNineId)); assertTrue("new array should still return true", filter.containsAndAdd(thirtyId)); assertFalse("colliding array returns false", filter.containsAndAdd(thirtyThreeId)); assertTrue( "colliding array returns true in second call", filter.containsAndAdd(thirtyThreeId)); assertFalse("original colliding array returns false", filter.containsAndAdd(thirtyId)); assertTrue("original colliding array returns true", filter.containsAndAdd(thirtyId)); assertFalse("colliding array returns false", filter.containsAndAdd(thirtyThreeId)); }