use of uk.gov.gchq.gaffer.time.LongTimeSeries in project Gaffer by gchq.
the class DeltaLongTimeSeriesSerialiser method deserialise.
@Override
public LongTimeSeries deserialise(final byte[] allBytes, final int offset, final int length) throws SerialisationException {
if (allBytes.length == 0 || length == 0) {
return null;
}
final ByteArrayInputStream bais = new ByteArrayInputStream(allBytes, offset, length);
final DataInputStream dis = new DataInputStream(bais);
final int bucketInt = (int) CompactRawSerialisationUtils.read(dis);
final TimeBucket bucket = TimeBucket.values()[bucketInt];
final int numEntries = (int) CompactRawSerialisationUtils.read(dis);
final LongTimeSeries timeSeries = new LongTimeSeries(bucket);
try {
final boolean deltaMode = dis.readBoolean();
if (deltaMode) {
deltaDeserialise(timeSeries, numEntries, dis);
} else {
defaultDeserialise(timeSeries, numEntries, dis);
}
} catch (final IOException e) {
throw new SerialisationException("IOException reading boolean", e);
}
return timeSeries;
}
use of uk.gov.gchq.gaffer.time.LongTimeSeries in project Gaffer by gchq.
the class DeltaLongTimeSeriesSerialiserTest method getExampleValueMillisecond.
private LongTimeSeries getExampleValueMillisecond() {
final LongTimeSeries timeSeries = new LongTimeSeries(TimeBucket.MILLISECOND);
timeSeries.upsert(Instant.ofEpochMilli(1_000L), 1L);
timeSeries.upsert(Instant.ofEpochMilli(3_000L), 10L);
timeSeries.upsert(Instant.ofEpochMilli(1_000_000L), 10_000_000L);
return timeSeries;
}
use of uk.gov.gchq.gaffer.time.LongTimeSeries in project Gaffer by gchq.
the class DeltaLongTimeSeriesSerialiserTest method testSerialiserForEmptyTimeSeries.
@Test
public void testSerialiserForEmptyTimeSeries() throws SerialisationException {
// Given
final LongTimeSeries timeSeries = new LongTimeSeries(TimeBucket.SECOND);
// When
final byte[] serialised = SERIALISER.serialise(timeSeries);
final LongTimeSeries deserialised = SERIALISER.deserialise(serialised);
// Then
assertEquals(timeSeries, deserialised);
}
use of uk.gov.gchq.gaffer.time.LongTimeSeries in project Gaffer by gchq.
the class DeltaLongTimeSeriesSerialiserTest method getExampleValueSecond.
private LongTimeSeries getExampleValueSecond() {
final LongTimeSeries timeSeries = new LongTimeSeries(TimeBucket.SECOND);
timeSeries.upsert(Instant.ofEpochMilli(CommonTimeUtil.MILLISECONDS_IN_SECOND * 100), 100L);
timeSeries.upsert(Instant.ofEpochMilli(CommonTimeUtil.MILLISECONDS_IN_SECOND * 1_000), 100L);
timeSeries.upsert(Instant.ofEpochMilli(CommonTimeUtil.MILLISECONDS_IN_SECOND * 1_000_000_000), 1_000_000_000L);
return timeSeries;
}
use of uk.gov.gchq.gaffer.time.LongTimeSeries in project Gaffer by gchq.
the class DeltaLongTimeSeriesSerialiserTest method getExampleValueMonth.
private LongTimeSeries getExampleValueMonth() {
final LongTimeSeries timeSeries = new LongTimeSeries(TimeBucket.MONTH);
timeSeries.upsert(Instant.ofEpochMilli(CommonTimeUtil.MILLISECONDS_IN_DAY * 30), 30L);
timeSeries.upsert(Instant.ofEpochMilli(CommonTimeUtil.MILLISECONDS_IN_DAY * 90), 90L);
timeSeries.upsert(Instant.ofEpochMilli(CommonTimeUtil.MILLISECONDS_IN_DAY * 1000), 1000L);
return timeSeries;
}
Aggregations