@Override public int size() { return this.points.getSize(); }
@Override public synchronized boolean add(final T o) { // NOPMD It would not make sense to sync within this method if (this.unbounded) { return super.add(o); } else { return this.addBounded(o); } }
@Override public int getSize() { return this.size(); }
/** * 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()); }
/** * @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 startTime * start time of Timeseries * @param timeSeriesTimeUnit * time unit of the startTime * @param deltaTime * time of timeseries * @param deltaTimeUnit * Time unit * @param capacity * length of timeseries */ public TimeSeries(final long startTime, final TimeUnit timeSeriesTimeUnit, final long deltaTime, final TimeUnit deltaTimeUnit, final int frequency, final int capacity) { this.startTime = startTime; this.timeSeriesTimeUnit = timeSeriesTimeUnit; this.deltaTime = deltaTime; this.deltaTimeUnit = deltaTimeUnit; this.frequency = frequency; this.capacity = capacity; this.timeSeriesStepSize = timeSeriesTimeUnit.convert(this.deltaTime, this.deltaTimeUnit); if (ITimeSeries.INFINITE_CAPACITY == capacity) { this.points = new TimeSeriesPointsBuffer<ITimeSeriesPoint<T>>(); } else { this.points = new TimeSeriesPointsBuffer<ITimeSeriesPoint<T>>(this.capacity); } this.nextTime = this.startTime; }
/** * print buffer. */ public void printBuffer() { LOGGER.info(this.toString()); } }
/** * 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()); } }
/** * @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; }
/** * @param startTime * start time of Timeseries * @param timeSeriesTimeUnit * time unit of the startTime * @param deltaTime * time of timeseries * @param deltaTimeUnit * Time unit * @param capacity * length of timeseries */ public TimeSeries(final long startTime, final TimeUnit timeSeriesTimeUnit, final long deltaTime, final TimeUnit deltaTimeUnit, final int frequency, final int capacity) { this.startTime = startTime; this.timeSeriesTimeUnit = timeSeriesTimeUnit; this.deltaTime = deltaTime; this.deltaTimeUnit = deltaTimeUnit; this.frequency = frequency; this.capacity = capacity; this.timeSeriesStepSize = timeSeriesTimeUnit.convert(this.deltaTime, this.deltaTimeUnit); if (ITimeSeries.INFINITE_CAPACITY == capacity) { this.points = new TimeSeriesPointsBuffer<>(); } else { this.points = new TimeSeriesPointsBuffer<>(this.capacity); } this.nextTime = this.startTime; }
/** * print buffer. */ public void printBuffer() { LOG.info(this.toString()); } }
@Override public int size() { return this.points.getSize(); }
@Override public int getSize() { return this.size(); }
@Override public synchronized boolean add(final T o) { // NOPMD It would not make sense to sync within this method if (this.unbounded) { return super.add(o); } else { return this.addBounded(o); } }
private synchronized boolean addBounded(final T o) { // NOPMD It would not make sense to sync within this method if (this.size() == this.capacity) { super.poll(); return super.add(o); } else { return super.add(o); } }
private synchronized boolean addBounded(final T o) { // NOPMD It would not make sense to sync within this method if (this.size() == this.capacity) { super.poll(); return super.add(o); } else { return super.add(o); } }