@Test public void subsetSnapshots() throws Exception { mACollector.currentValue = 100; mACollector.succeeds = true; CompositeMetrics m = new CompositeMetrics().putMetric(A.class, new A()); mCollector.getSnapshot(m); assertThat(mCollector.getSnapshot(m)).isTrue(); assertThat(m.getMetrics().size()).isEqualTo(1); assertThat(m.getMetric(A.class).value).isEqualTo(100); assertThat(m.isValid(A.class)).isEqualTo(true); assertThat(m.getMetric(B.class)).isNull(); }
@Override @ThreadSafe(enableChecks = false) public boolean getSnapshot(CompositeMetrics snapshot) { checkNotNull(snapshot, "Null value passed to getSnapshot!"); boolean result = false; SimpleArrayMap<Class<? extends SystemMetrics>, SystemMetrics> snapshotMetrics = snapshot.getMetrics(); for (int i = 0, size = snapshotMetrics.size(); i < size; i++) { Class<? extends SystemMetrics> metricsClass = snapshotMetrics.keyAt(i); SystemMetricsCollector collector = mMetricsCollectorMap.get(metricsClass); boolean snapshotResult = false; if (collector != null) { SystemMetrics metric = snapshot.getMetric(metricsClass); snapshotResult = collector.getSnapshot(metric); } snapshot.setIsValid(metricsClass, snapshotResult); result |= snapshotResult; } return result; }
CompositeMetricsCollector extends SystemMetricsCollector<CompositeMetrics> { @Override @ThreadSafe(enableChecks = false) public boolean getSnapshot(CompositeMetrics snapshot) { checkNotNull(snapshot, "Null value passed to getSnapshot!"); boolean result = false; SimpleArrayMap<Class<? extends SystemMetrics>, SystemMetrics> snapshotMetrics = snapshot.getMetrics(); for (int i = 0, size = snapshotMetrics.size(); i < size; i++) { Class<? extends SystemMetrics> metricsClass = snapshotMetrics.keyAt(i); SystemMetricsCollector collector = mMetricsCollectorMap.get(metricsClass); boolean snapshotResult = false; if (collector != null) { SystemMetrics metric = snapshot.getMetric(metricsClass); snapshotResult = collector.getSnapshot(metric); } snapshot.setIsValid(metricsClass, snapshotResult); result |= snapshotResult; } return result; } }
CompositeMetricsCollector extends SystemMetricsCollector<CompositeMetrics> { @Override @ThreadSafe(enableChecks = false) public boolean getSnapshot(CompositeMetrics snapshot) { checkNotNull(snapshot, "Null value passed to getSnapshot!"); boolean result = false; SimpleArrayMap<Class<? extends SystemMetrics>, SystemMetrics> snapshotMetrics = snapshot.getMetrics(); for (int i = 0, size = snapshotMetrics.size(); i < size; i++) { Class<? extends SystemMetrics> metricsClass = snapshotMetrics.keyAt(i); SystemMetricsCollector collector = mMetricsCollectorMap.get(metricsClass); boolean snapshotResult = false; if (collector != null) { SystemMetrics metric = snapshot.getMetric(metricsClass); snapshotResult = collector.getSnapshot(metric); } snapshot.setIsValid(metricsClass, snapshotResult); result |= snapshotResult; } return result; } protected  CompositeMetricsCollector(Builder builder); }
CompositeMetricsCollector extends SystemMetricsCollector<CompositeMetrics> { @Override @ThreadSafe(enableChecks = false) public boolean getSnapshot(CompositeMetrics snapshot) { checkNotNull(snapshot, "Null value passed to getSnapshot!"); boolean result = false; SimpleArrayMap<Class<? extends SystemMetrics>, SystemMetrics> snapshotMetrics = snapshot.getMetrics(); for (int i = 0, size = snapshotMetrics.size(); i < size; i++) { Class<? extends SystemMetrics> metricsClass = snapshotMetrics.keyAt(i); SystemMetricsCollector collector = mMetricsCollectorMap.get(metricsClass); boolean snapshotResult = false; if (collector != null) { SystemMetrics metric = snapshot.getMetric(metricsClass); snapshotResult = collector.getSnapshot(metric); } snapshot.setIsValid(metricsClass, snapshotResult); result |= snapshotResult; } return result; } protected  CompositeMetricsCollector(Builder builder); T getMetricsCollector(
      Class<S> metricsClass); @Override @ThreadSafe(enableChecks = false) boolean getSnapshot(CompositeMetrics snapshot); @Override CompositeMetrics createMetrics(); }
CompositeMetricsCollector extends SystemMetricsCollector<CompositeMetrics> { @Override @ThreadSafe(enableChecks = false) public boolean getSnapshot(CompositeMetrics snapshot) { checkNotNull(snapshot, "Null value passed to getSnapshot!"); boolean result = false; SimpleArrayMap<Class<? extends SystemMetrics>, SystemMetrics> snapshotMetrics = snapshot.getMetrics(); for (int i = 0, size = snapshotMetrics.size(); i < size; i++) { Class<? extends SystemMetrics> metricsClass = snapshotMetrics.keyAt(i); SystemMetricsCollector collector = mMetricsCollectorMap.get(metricsClass); boolean snapshotResult = false; if (collector != null) { SystemMetrics metric = snapshot.getMetric(metricsClass); snapshotResult = collector.getSnapshot(metric); } snapshot.setIsValid(metricsClass, snapshotResult); result |= snapshotResult; } return result; } protected  CompositeMetricsCollector(Builder builder); T getMetricsCollector(
      Class<S> metricsClass); @Override @ThreadSafe(enableChecks = false) boolean getSnapshot(CompositeMetrics snapshot); @Override CompositeMetrics createMetrics();  }