RBMBackedTimestampSetSerialiser implements ToBytesSerialiser<RBMBackedTimestampSet> { @Override public byte[] serialise(final RBMBackedTimestampSet rbmBackedTimestampSet) throws SerialisationException { if (null == rbmBackedTimestampSet) { return EMPTY_BYTES; } final ByteArrayOutputStream baos = new ByteArrayOutputStream(); final DataOutputStream dos = new DataOutputStream(baos); try { dos.write(CompactRawSerialisationUtils.writeLong(rbmBackedTimestampSet.getTimeBucket().ordinal())); rbmBackedTimestampSet.getRbm().serialize(dos); } catch (final IOException e) { throw new SerialisationException("Exception writing serialised RBMBackedTimestampSet to ByteArrayOutputStream", e); } return baos.toByteArray(); }  @Override boolean canHandle(final Class clazz); @Override byte[] serialise(final RBMBackedTimestampSet rbmBackedTimestampSet); @Override RBMBackedTimestampSet deserialise(final byte[] allBytes, final int offset, final int length); @Override RBMBackedTimestampSet deserialise(final byte[] bytes); @Override RBMBackedTimestampSet deserialiseEmpty(); @Override boolean preservesObjectOrdering(); @Override boolean isConsistent(); @Override boolean equals(final Object obj); @Override int hashCode();  }
@Test public void testSerialisationSizesQuotedInJavadoc() throws SerialisationException { final Random random = new Random(123456789L); final Instant instant = ZonedDateTime.of(2017, 1, 1, 1, 1, 1, 0, ZoneId.of("UTC")).toInstant(); final RBMBackedTimestampSet rbmBackedTimestampSet1 = new RBMBackedTimestampSet(CommonTimeUtil.TimeBucket.MINUTE); IntStream.range(0, 100) .forEach(i -> rbmBackedTimestampSet1.add(instant.plusSeconds(random.nextInt(24 * 60) * 60))); final RBMBackedTimestampSet rbmBackedTimestampSet2 = new RBMBackedTimestampSet(CommonTimeUtil.TimeBucket.MINUTE); IntStream.range(0, 365 * 24 * 60) .forEach(i -> rbmBackedTimestampSet2.add(instant.plusSeconds(i * 60))); final RBMBackedTimestampSet rbmBackedTimestampSet3 = new RBMBackedTimestampSet(CommonTimeUtil.TimeBucket.SECOND); IntStream.range(0, 365 * 24 * 60 * 60) .forEach(i -> rbmBackedTimestampSet3.add(instant.plusSeconds(i))); final int lengthSet1 = serialiser.serialise(rbmBackedTimestampSet1).length; final int lengthSet2 = serialiser.serialise(rbmBackedTimestampSet2).length; final int lengthSet3 = serialiser.serialise(rbmBackedTimestampSet3).length; assertTrue(200 < lengthSet1 && lengthSet1 < 220); assertTrue(72000 < lengthSet2 && lengthSet2 < 74000); assertTrue(3900000 < lengthSet3 && lengthSet3 < 4100000); }