StoredDoubleTimeSeries extends AbstractTimeSeries<DoublePoint, DoubleDataChunk, DoubleTimeSeries> implements DoubleTimeSeries { @Override public double[] toArray() { DoubleBuffer buffer = DoubleBuffer.allocate(metadata.getIndex().getPointCount()); for (int i = 0; i < metadata.getIndex().getPointCount(); i++) { buffer.put(i, Double.NaN); } fillBuffer(buffer, 0); return buffer.array(); } StoredDoubleTimeSeries(TimeSeriesMetadata metadata, DoubleDataChunk... chunks);  StoredDoubleTimeSeries(TimeSeriesMetadata metadata, List<DoubleDataChunk> chunks); @Override void fillBuffer(DoubleBuffer buffer, int timeSeriesOffset); @Override void fillBuffer(BigDoubleBuffer buffer, long timeSeriesOffset); @Override double[] toArray();  }
@Test public void test() throws IOException { RegularTimeSeriesIndex index = RegularTimeSeriesIndex.create(Interval.parse("2015-01-01T00:00:00Z/2015-01-01T01:45:00Z"), Duration.ofMinutes(15)); TimeSeriesMetadata metadata = new TimeSeriesMetadata("ts1", TimeSeriesDataType.DOUBLE, Collections.emptyMap(), index); UncompressedDoubleDataChunk chunk = new UncompressedDoubleDataChunk(2, new double[] {1d, 2d}); CompressedDoubleDataChunk chunk2 = new CompressedDoubleDataChunk(5, 3, new double[] {3d, 4d}, new int[] {1, 2}); assertEquals(TimeSeriesDataType.DOUBLE, chunk.getDataType()); StoredDoubleTimeSeries timeSeries = new StoredDoubleTimeSeries(metadata, chunk, chunk2); assertSame(metadata, timeSeries.getMetadata()); assertEquals(Arrays.asList(chunk, chunk2), timeSeries.getChunks()); assertArrayEquals(new double[] {Double.NaN, Double.NaN, 1d, 2d, Double.NaN, 3d, 4d, 4d}, timeSeries.toArray(), 0d); DoublePoint[] pointsRef = {new DoublePoint(0, Instant.parse("2015-01-01T00:00:00Z").toEpochMilli(), Double.NaN), new DoublePoint(2, Instant.parse("2015-01-01T00:30:00Z").toEpochMilli(), 1d), new DoublePoint(3, Instant.parse("2015-01-01T00:45:00Z").toEpochMilli(), 2d), new DoublePoint(4, Instant.parse("2015-01-01T01:00:00Z").toEpochMilli(), Double.NaN), new DoublePoint(5, Instant.parse("2015-01-01T01:15:00Z").toEpochMilli(), 3d), new DoublePoint(6, Instant.parse("2015-01-01T01:30:00Z").toEpochMilli(), 4d)}; assertArrayEquals(pointsRef, timeSeries.stream().toArray()); assertArrayEquals(pointsRef, Iterators.toArray(timeSeries.iterator(), DoublePoint.class)); String jsonRef = String.join(System.lineSeparator(), "{", " \"metadata\" : {", " \"name\" : \"ts1\",", " \"dataType\" : \"DOUBLE\",", " \"tags\" : [ ],", " \"regularIndex\" : {", " \"startTime\" : 1420070400000,", " \"endTime\" : 1420076700000,", " \"spacing\" : 900000", " }", " },", " \"chunks\" : [ {", " \"offset\" : 2,", " \"values\" : [ 1.0, 2.0 ]", " }, {", " \"offset\" : 5,", " \"uncompressedLength\" : 3,", " \"stepValues\" : [ 3.0, 4.0 ],", " \"stepLengths\" : [ 1, 2 ]", " } ]", "}" ); String json = JsonUtil.toJson(timeSeries::writeJson); assertEquals(jsonRef, json); List<TimeSeries> timeSeriesList = TimeSeries.parseJson(json); assertEquals(1, timeSeriesList.size()); String json2 = JsonUtil.toJson(timeSeriesList.get(0)::writeJson); assertEquals(json, json2); ObjectMapper objectMapper = JsonUtil.createObjectMapper() .registerModule(new TimeSeriesJsonModule()); assertEquals(timeSeries, objectMapper.readValue(objectMapper.writeValueAsString(timeSeries), DoubleTimeSeries.class)); }
@Test public void testCreate() { TimeSeriesIndex index = new TestTimeSeriesIndex(0L, 3); DoubleTimeSeries ts1 = TimeSeries.createDouble("ts1", index, 0d, 1d, 2d); assertEquals("ts1", ts1.getMetadata().getName()); assertEquals(TimeSeriesDataType.DOUBLE, ts1.getMetadata().getDataType()); assertArrayEquals(new double[] {0d, 1d, 2d}, ts1.toArray(), 0d); }