StringTimeSeries extends AbstractTimeSeries<StringPoint, StringDataChunk, StringTimeSeries> implements TimeSeries<StringPoint, StringTimeSeries> { public String[] toArray() { CompactStringBuffer buffer = new CompactStringBuffer(ByteBuffer::allocate, metadata.getIndex().getPointCount()); chunks.forEach(chunk -> chunk.fillBuffer(buffer, 0)); return buffer.toArray(); } StringTimeSeries(TimeSeriesMetadata metadata, StringDataChunk... chunks);  StringTimeSeries(TimeSeriesMetadata metadata, List<StringDataChunk> chunks); void fillBuffer(CompactStringBuffer buffer, int timeSeriesOffset); void fillBuffer(BigStringBuffer buffer, long timeSeriesOffset); String[] 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.STRING, Collections.emptyMap(), index); UncompressedStringDataChunk chunk = new UncompressedStringDataChunk(2, new String[] {"a", "b"}); CompressedStringDataChunk chunk2 = new CompressedStringDataChunk(5, 3, new String[] {"c", "d"}, new int[] {1, 2}); assertEquals(TimeSeriesDataType.STRING, chunk.getDataType()); StringTimeSeries timeSeries = new StringTimeSeries(metadata, chunk, chunk2); assertSame(metadata, timeSeries.getMetadata()); assertEquals(Arrays.asList(chunk, chunk2), timeSeries.getChunks()); assertArrayEquals(new String[] {null, null, "a", "b", null, "c", "d", "d"}, timeSeries.toArray()); StringPoint[] pointsRef = {new StringPoint(0, Instant.parse("2015-01-01T00:00:00Z").toEpochMilli(), null), new StringPoint(2, Instant.parse("2015-01-01T00:30:00Z").toEpochMilli(), "a"), new StringPoint(3, Instant.parse("2015-01-01T00:45:00Z").toEpochMilli(), "b"), new StringPoint(4, Instant.parse("2015-01-01T01:00:00Z").toEpochMilli(), null), new StringPoint(5, Instant.parse("2015-01-01T01:15:00Z").toEpochMilli(), "c"), new StringPoint(6, Instant.parse("2015-01-01T01:30:00Z").toEpochMilli(), "d")}; assertArrayEquals(pointsRef, timeSeries.stream().toArray()); assertArrayEquals(pointsRef, Iterators.toArray(timeSeries.iterator(), StringPoint.class)); String jsonRef = String.join(System.lineSeparator(), "{", " \"metadata\" : {", " \"name\" : \"ts1\",", " \"dataType\" : \"STRING\",", " \"tags\" : [ ],", " \"regularIndex\" : {", " \"startTime\" : 1420070400000,", " \"endTime\" : 1420076700000,", " \"spacing\" : 900000", " }", " },", " \"chunks\" : [ {", " \"offset\" : 2,", " \"values\" : [ \"a\", \"b\" ]", " }, {", " \"offset\" : 5,", " \"uncompressedLength\" : 3,", " \"stepValues\" : [ \"c\", \"d\" ],", " \"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), StringTimeSeries.class)); }
@Test public void testCreate() { TimeSeriesIndex index = new TestTimeSeriesIndex(0L, 3); StringTimeSeries ts1 = TimeSeries.createString("ts1", index, "a", "b", "c"); assertEquals("ts1", ts1.getMetadata().getName()); assertEquals(TimeSeriesDataType.STRING, ts1.getMetadata().getDataType()); assertArrayEquals(new String[] {"a", "b", "c"}, ts1.toArray()); }