DeltaLongTimeSeriesSerialiser implements ToBytesSerialiser<LongTimeSeries> { @Override public byte[] serialise(final LongTimeSeries timeSeries) throws SerialisationException { if (null == timeSeries) { return EMPTY_BYTES; } final ByteArrayOutputStream baos = new ByteArrayOutputStream(); final DataOutputStream dos = new DataOutputStream(baos); final Mode mode = calculateMode(timeSeries); final SortedMap<Instant, Long> timeseriesMap = timeSeries.getTimeSeries(); try { dos.write(CompactRawSerialisationUtils.writeLong(timeSeries.getTimeBucket().ordinal())); dos.write(CompactRawSerialisationUtils.writeLong(timeseriesMap.size())); boolean deltaMode = mode == Mode.DELTA; dos.writeBoolean(deltaMode); if (deltaMode) { deltaSerialise(timeseriesMap, dos); } else { defaultSerialise(timeseriesMap, dos); } } catch (final IOException e) { throw new SerialisationException("Exception writing serialised LongTimeSeries to ByteArrayOutputStream", e); } return baos.toByteArray(); }  @Override boolean canHandle(final Class clazz); @Override byte[] serialise(final LongTimeSeries timeSeries); @Override LongTimeSeries deserialise(final byte[] allBytes, final int offset, final int length); @Override LongTimeSeries deserialise(final byte[] bytes); @Override LongTimeSeries deserialiseEmpty(); @Override boolean preservesObjectOrdering(); @Override boolean isConsistent(); @Override boolean equals(final Object obj); @Override int hashCode();  }
@Test public void testConsistent() throws SerialisationException { final LongTimeSeries timeSeries1 = new LongTimeSeries(TimeBucket.SECOND); timeSeries1.upsert(Instant.ofEpochMilli(1000L), 10L); final LongTimeSeries timeSeries2 = new LongTimeSeries(TimeBucket.SECOND); timeSeries2.upsert(Instant.ofEpochMilli(1000L), 5L); timeSeries2.upsert(Instant.ofEpochMilli(1000L), 5L); final byte[] serialised1 = SERIALISER.serialise(timeSeries1); final byte[] serialised2 = SERIALISER.serialise(timeSeries2); assertArrayEquals(serialised1, serialised2); }