@Test public void testGetLatestDiffAndReset() throws Exception { DummyMetricCollector collector = new DummyMetricCollector(); collector.currentValue = 10; StatefulSystemMetricsCollector<DummyMetric, DummyMetricCollector> statefulCollector = new StatefulSystemMetricsCollector<>(collector); assertThat(statefulCollector.getLatestDiffAndReset().value).isEqualTo(0); collector.currentValue = 20; assertThat(statefulCollector.getLatestDiffAndReset().value).isEqualTo(10); assertThat(statefulCollector.getLatestDiffAndReset().value).isEqualTo(0); }
@Nullable public R getLatestDiffAndReset() { if (getLatestDiff() == null) { return null; } R temp = mPrev; mPrev = mCurr; mCurr = temp; return mDiff; }
StatefulSystemMetricsCollector { @Nullable public R getLatestDiffAndReset() { if (getLatestDiff() == null) { return null; } R temp = mPrev; mPrev = mCurr; mCurr = temp; return mDiff; } }
StatefulSystemMetricsCollector { @Nullable public R getLatestDiffAndReset() { if (getLatestDiff() == null) { return null; } R temp = mPrev; mPrev = mCurr; mCurr = temp; return mDiff; } StatefulSystemMetricsCollector(S collector);  StatefulSystemMetricsCollector(S collector, R curr, R prev, R diff); }
StatefulSystemMetricsCollector { @Nullable public R getLatestDiffAndReset() { if (getLatestDiff() == null) { return null; } R temp = mPrev; mPrev = mCurr; mCurr = temp; return mDiff; } StatefulSystemMetricsCollector(S collector);  StatefulSystemMetricsCollector(S collector, R curr, R prev, R diff); S getCollector(); @Nullable R getLatestDiffAndReset(); @Nullable R getLatestDiff(); }
StatefulSystemMetricsCollector { @Nullable public R getLatestDiffAndReset() { if (getLatestDiff() == null) { return null; } R temp = mPrev; mPrev = mCurr; mCurr = temp; return mDiff; } StatefulSystemMetricsCollector(S collector);  StatefulSystemMetricsCollector(S collector, R curr, R prev, R diff); S getCollector(); @Nullable R getLatestDiffAndReset(); @Nullable R getLatestDiff();  }