@Test public void add() { DataSync<Data> ds = new DataSync<>(10); ds.add(1, new Data(10.0)); ds.add(3, new Data(20.0)); ds.add(5, new Data(30.0)); assertThat(ds.get(0)).isNotPresent(); assertThat(ds.get(1)).isPresent(); assertThat(ds.get(2)).isPresent(); assertThat(ds.get(3)).isPresent(); assertThat(ds.get(5)).isPresent(); assertThat(ds.get(6)).isNotPresent(); DataSync<Data>.DataPair dp1 = ds.get(1).orElseThrow(AssertionFailedError::new); assertThat(dp1.getFirst().getTimestamp()).isEqualTo(1L); assertThat(dp1.getSecond().getTimestamp()).isEqualTo(3L); assertThat(dp1.getFirst().getData()).isEqualTo(new Data(10.0)); assertThat(dp1.getSecond().getData()).isEqualTo(new Data(20.0)); ds.add(0, new Data(50.0)); assertThat(ds.get(1)).isNotPresent(); assertThat(ds.get(0)).isNotPresent(); }
public synchronized void add(final long timestamp, final T data) { DataStore store = new DataStore(timestamp, data); if (!buffer.isEmpty() && timestamp < buffer.get(0).getTimestamp()) { log.debug("Clearing buffer, since incoming timestamp is smaller than buffered timestamp ({} < {})", timestamp, buffer.get(0).getTimestamp()); buffer.clear(); } buffer.removeIf(d -> d.timestamp < timestamp - horizon); buffer.add(store); }
DataSync { public synchronized void add(final long timestamp, final T data) { DataStore store = new DataStore(timestamp, data); if (!buffer.isEmpty() && timestamp < buffer.get(0).getTimestamp()) { log.debug("Clearing buffer, since incoming timestamp is smaller than buffered timestamp ({} < {})", timestamp, buffer.get(0).getTimestamp()); buffer.clear(); } buffer.removeIf(d -> d.timestamp < timestamp - horizon); buffer.add(store); } }
DataSync { public synchronized void add(final long timestamp, final T data) { DataStore store = new DataStore(timestamp, data); if (!buffer.isEmpty() && timestamp < buffer.get(0).getTimestamp()) { log.debug("Clearing buffer, since incoming timestamp is smaller than buffered timestamp ({} < {})", timestamp, buffer.get(0).getTimestamp()); buffer.clear(); } buffer.removeIf(d -> d.timestamp < timestamp - horizon); buffer.add(store); } DataSync(final double horizon); }
DataSync { public synchronized void add(final long timestamp, final T data) { DataStore store = new DataStore(timestamp, data); if (!buffer.isEmpty() && timestamp < buffer.get(0).getTimestamp()) { log.debug("Clearing buffer, since incoming timestamp is smaller than buffered timestamp ({} < {})", timestamp, buffer.get(0).getTimestamp()); buffer.clear(); } buffer.removeIf(d -> d.timestamp < timestamp - horizon); buffer.add(store); } DataSync(final double horizon); synchronized void add(final long timestamp, final T data); synchronized Optional<DataPair> get(final long timestamp); synchronized Optional<DataStore> getLatest(); synchronized Optional<DataStore> getOldest(); synchronized void reset(); List<DataStore> getBuffer(); }
DataSync { public synchronized void add(final long timestamp, final T data) { DataStore store = new DataStore(timestamp, data); if (!buffer.isEmpty() && timestamp < buffer.get(0).getTimestamp()) { log.debug("Clearing buffer, since incoming timestamp is smaller than buffered timestamp ({} < {})", timestamp, buffer.get(0).getTimestamp()); buffer.clear(); } buffer.removeIf(d -> d.timestamp < timestamp - horizon); buffer.add(store); } DataSync(final double horizon); synchronized void add(final long timestamp, final T data); synchronized Optional<DataPair> get(final long timestamp); synchronized Optional<DataStore> getLatest(); synchronized Optional<DataStore> getOldest(); synchronized void reset(); List<DataStore> getBuffer();  }