@Test public void testCustomBaseSnapshot() throws Exception { DummyMetric metric = new DummyMetric(); metric.value = 0; DummyMetricCollector collector = new DummyMetricCollector(); collector.currentValue = 10; StatefulSystemMetricsCollector<DummyMetric, DummyMetricCollector> withCustomInitialSnapshot = new StatefulSystemMetricsCollector<>( collector, collector.createMetrics(), metric, collector.createMetrics()); StatefulSystemMetricsCollector<DummyMetric, DummyMetricCollector> defaultInitialSnapshot = new StatefulSystemMetricsCollector<>(collector); assertThat(withCustomInitialSnapshot.getLatestDiff().value).isEqualTo(10); assertThat(defaultInitialSnapshot.getLatestDiff().value).isEqualTo(0); }
@Nullable public R getLatestDiff() { mIsValid &= mCollector.getSnapshot(this.mCurr); if (!mIsValid) { return null; } mCurr.diff(mPrev, mDiff); return mDiff; }
StatefulSystemMetricsCollector { @Nullable public R getLatestDiff() { mIsValid &= mCollector.getSnapshot(this.mCurr); if (!mIsValid) { return null; } mCurr.diff(mPrev, mDiff); return mDiff; } }
StatefulSystemMetricsCollector { @Nullable public R getLatestDiff() { mIsValid &= mCollector.getSnapshot(this.mCurr); if (!mIsValid) { return null; } mCurr.diff(mPrev, mDiff); return mDiff; } StatefulSystemMetricsCollector(S collector);  StatefulSystemMetricsCollector(S collector, R curr, R prev, R diff); }
StatefulSystemMetricsCollector { @Nullable public R getLatestDiff() { mIsValid &= mCollector.getSnapshot(this.mCurr); if (!mIsValid) { return null; } mCurr.diff(mPrev, mDiff); 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 getLatestDiff() { mIsValid &= mCollector.getSnapshot(this.mCurr); if (!mIsValid) { return null; } mCurr.diff(mPrev, mDiff); return mDiff; } StatefulSystemMetricsCollector(S collector);  StatefulSystemMetricsCollector(S collector, R curr, R prev, R diff); S getCollector(); @Nullable R getLatestDiffAndReset(); @Nullable R getLatestDiff();  }