Charts { public static Pair<long[], double[][]> fillGaps(final long[] timestamps, final long[][] data, final int sampleTime, final int nrColumns) { long startTime = timestamps[0]; int nrSamples = (int) ((timestamps[timestamps.length - 1] - startTime) / sampleTime) + 1; long[] lts = new long[nrSamples]; double[][] dr = new double[nrSamples][]; long nextTime = startTime; int j = 0; int maxDeviation = sampleTime / 2; double[] nodata = new double[nrColumns]; for (int i = 0; i < nrColumns; i++) { nodata[i] = Double.NaN; } for (int i = 0; i < nrSamples; i++) { lts[i] = nextTime; if (Math.abs(timestamps[j] - nextTime) < maxDeviation) { dr[i] = Arrays.toDoubleArray(data[j]); j++; } else { dr[i] = nodata; } nextTime += sampleTime; } return Pair.of(lts, dr); } private  Charts(); @SuppressFBWarnings("CE_CLASS_ENVY") static JFreeChart createHeatJFreeChart(final String[] dsNames, final double[][] values,
          final long startTimeMillis, final long stepMillis, final String uom, final String chartName); static BufferedImage createMinMaxAvgCountImg(final String chartName, final long[] timestamps,
          final double[] min, final double[] max, final double[] total, final double[] count,
          final String uom, final int width, final int height); static BufferedImage generateCountTotalChart(final String groupName, final long[][] timestamps,
          final String[] measurementNames, final String uom1, final double[][] measurements, final int width,
          final int height, final String[] measurementNames2, final String uom2, final double[][] measurements2); static JFreeChart createTimeSeriesJFreeChart(final String chartName, final long[] timestamps,
          final String[] measurementNames, final String uom, final double[][] measurements); static JFreeChart createTimeSeriesJFreeChart(final String chartName, final long[][] timestamps,
          final String[] measurementNames, final String uom, final double[][] measurements); static Pair<long[], double[][]> fillGaps(final long[] timestamps,
          final long[][] data, final int sampleTime, final int nrColumns);  }
@Test public void testGapsFiller1() { Pair<long[], double[][]> fillGaps = Charts.fillGaps(new long[]{0L}, new long[][]{{1L, 2L, 3L}}, 10, 3); Assert.assertEquals(0L, fillGaps.getFirst()[0]); Assert.assertEquals(3d, fillGaps.getSecond()[0][2], 0.01); }
@Test public void testGapsFiller2() { Pair<long[], double[][]> fillGaps = Charts.fillGaps(new long[]{0L, 30L}, new long[][]{{1L, 2L, 3L}, {10L, 20L, 30L}}, 10, 3); long[] first = fillGaps.getFirst(); Assert.assertEquals(4, first.length); double[][] second = fillGaps.getSecond(); Assert.assertEquals(4, second.length); Assert.assertEquals(10L, first[1]); Assert.assertEquals(20L, first[2]); Assert.assertEquals(Double.NaN, second[1][2], 0.01); Assert.assertEquals(Double.NaN, second[2][2], 0.01); }