/** * @param value * value which should append to timeseries * * @return tspoint */ @Override public ITimeSeriesPoint<T> append(final T value) { final ITimeSeriesPoint<T> point; synchronized (value) { point = new TimeSeriesPoint<T>(this.nextTime, value); this.points.add(point); this.startTime = this.points.peek().getTime(); // we have a bounded buffer so the first element might be gone this.nextTime = this.nextTime + this.timeSeriesStepSize; } return point; }
/** * @param value * value which should append to timeseries * * @return tspoint */ @Override public ITimeSeriesPoint<T> append(final T value) { final ITimeSeriesPoint<T> point; synchronized (value) { point = new TimeSeriesPoint<>(this.nextTime, value); this.points.add(point); this.startTime = this.points.peek().getTime(); // we have a bounded buffer so the first element might be gone this.nextTime = this.nextTime + this.timeSeriesStepSize; } return point; }
/** * Test of the bounded buffer version of the time series point buffer. * * @throws InterruptedException * If interrupted * @throws IllegalStateException * If illegal state is reached * @throws AnalysisConfigurationException * If analysis configuration exception appears */ @Test public void testBoundedBuffer() throws InterruptedException, IllegalStateException, AnalysisConfigurationException { final TimeSeriesPointsBuffer<Integer> bounded = new TimeSeriesPointsBuffer<Integer>(3); bounded.add(1); bounded.add(2); bounded.add(3); // Next Value exceed the boundary bounded.add(4); Assert.assertEquals(3, bounded.getSize()); // Test remove bounded.remove(); Assert.assertEquals(2, bounded.getSize()); }
/** * Test of the unbounded buffer version of the time series point buffer. * * @throws InterruptedException * If interrupted * @throws IllegalStateException * If illegal state is reached * @throws AnalysisConfigurationException * If analysis configuration exception appears */ @Test public void testUnboundedBuffer() throws InterruptedException, IllegalStateException, AnalysisConfigurationException { final TimeSeriesPointsBuffer<Integer> unbounded = new TimeSeriesPointsBuffer<Integer>(-1); int i = 0; while (i < 100) { unbounded.add(i); i++; } Assert.assertEquals(i, unbounded.getSize()); // Test remove unbounded.remove(); Assert.assertEquals(i - 1, unbounded.getSize()); } }