use of org.roaringbitmap.RoaringBitmap in project Gaffer by gchq.
the class RoaringBitmapJsonSerialisationTest method testCanSerialiseAndDeserialiseWithRuns.
@Test
public void testCanSerialiseAndDeserialiseWithRuns() throws IOException {
final ByteArrayBuilder byteArrayBuilder = new ByteArrayBuilder();
JsonGenerator jsonGenerator = JSON_FACTORY.createGenerator(byteArrayBuilder);
RoaringBitmap testBitmap = new RoaringBitmap();
testBitmap.add(2);
testBitmap.add(3000);
testBitmap.add(300000);
for (int i = 400000; i < 500000; i += 2) {
testBitmap.add(i);
}
testBitmap.runOptimize();
SERIALISER.serialize(testBitmap, jsonGenerator, null);
jsonGenerator.flush();
byte[] serialisedBitmap = byteArrayBuilder.toByteArray();
JsonParser parser = JSON_FACTORY.createParser(serialisedBitmap);
parser.setCodec(new ObjectMapper());
Object o = DESERIALISER.deserialize(parser, null);
assertEquals(RoaringBitmap.class, o.getClass());
assertEquals(testBitmap, o);
}
Aggregations