@Test public void testDiff() { HealthStatsMetrics a = createTestMetrics(); HealthStatsMetrics b = createTestMetrics(); HealthStatsMetrics diff = a.diff(b, null); HealthStatsMetrics expectedDiff = new HealthStatsMetrics(); expectedDiff.dataType = TEST_DATATYPE; expectedDiff.measurement.put(123, 0L); expectedDiff.measurements.put(234, new ArrayMap<String, Long>()); expectedDiff.measurements.get(234).put("measurements", 0L); expectedDiff.timer.put(345, new HealthStatsMetrics.TimerMetrics(0, 0)); ArrayMap<String, HealthStatsMetrics.TimerMetrics> timersValues = new ArrayMap<>(); timersValues.put("timers", new HealthStatsMetrics.TimerMetrics(0, 0)); expectedDiff.timers.put(456, timersValues); ArrayMap<String, HealthStatsMetrics> value = new ArrayMap<>(); value.put("stats", new HealthStatsMetrics(expectedDiff)); expectedDiff.stats.put(1234, value); assertThat(diff).isEqualTo(expectedDiff); }
@Override public HealthStatsMetrics diff( @Nullable HealthStatsMetrics b, @Nullable HealthStatsMetrics output) { if (output == null) { output = new HealthStatsMetrics(); } output.dataType = dataType; if (b == null || compareSnapshotAge(this, b) < 0 ) { output.set(this); } else if (!strEquals(b.dataType, dataType)) { throw new IllegalArgumentException( "Attempting to subtract different types of HealthStatMetrics: " + dataType + " and " + b.dataType); } else { op(OP_DIFF, measurement, b.measurement, output.measurement); op(OP_DIFF, measurements, b.measurements, output.measurements); op(OP_DIFF, timer, b.timer, output.timer); op(OP_DIFF, timers, b.timers, output.timers); op(OP_DIFF, stats, b.stats, output.stats); } return output; }
HealthStatsMetrics extends SystemMetrics<HealthStatsMetrics> { @Override public HealthStatsMetrics diff( @Nullable HealthStatsMetrics b, @Nullable HealthStatsMetrics output) { if (output == null) { output = new HealthStatsMetrics(); } output.dataType = dataType; if (b == null || compareSnapshotAge(this, b) < 0 ) { output.set(this); } else if (!strEquals(b.dataType, dataType)) { throw new IllegalArgumentException( "Attempting to subtract different types of HealthStatMetrics: " + dataType + " and " + b.dataType); } else { op(OP_DIFF, measurement, b.measurement, output.measurement); op(OP_DIFF, measurements, b.measurements, output.measurements); op(OP_DIFF, timer, b.timer, output.timer); op(OP_DIFF, timers, b.timers, output.timers); op(OP_DIFF, stats, b.stats, output.stats); } return output; } }
HealthStatsMetrics extends SystemMetrics<HealthStatsMetrics> { @Override public HealthStatsMetrics diff( @Nullable HealthStatsMetrics b, @Nullable HealthStatsMetrics output) { if (output == null) { output = new HealthStatsMetrics(); } output.dataType = dataType; if (b == null || compareSnapshotAge(this, b) < 0 ) { output.set(this); } else if (!strEquals(b.dataType, dataType)) { throw new IllegalArgumentException( "Attempting to subtract different types of HealthStatMetrics: " + dataType + " and " + b.dataType); } else { op(OP_DIFF, measurement, b.measurement, output.measurement); op(OP_DIFF, measurements, b.measurements, output.measurements); op(OP_DIFF, timer, b.timer, output.timer); op(OP_DIFF, timers, b.timers, output.timers); op(OP_DIFF, stats, b.stats, output.stats); } return output; } HealthStatsMetrics();  HealthStatsMetrics(HealthStats healthStats);  HealthStatsMetrics(HealthStatsMetrics metrics); }
HealthStatsMetrics extends SystemMetrics<HealthStatsMetrics> { @Override public HealthStatsMetrics diff( @Nullable HealthStatsMetrics b, @Nullable HealthStatsMetrics output) { if (output == null) { output = new HealthStatsMetrics(); } output.dataType = dataType; if (b == null || compareSnapshotAge(this, b) < 0 ) { output.set(this); } else if (!strEquals(b.dataType, dataType)) { throw new IllegalArgumentException( "Attempting to subtract different types of HealthStatMetrics: " + dataType + " and " + b.dataType); } else { op(OP_DIFF, measurement, b.measurement, output.measurement); op(OP_DIFF, measurements, b.measurements, output.measurements); op(OP_DIFF, timer, b.timer, output.timer); op(OP_DIFF, timers, b.timers, output.timers); op(OP_DIFF, stats, b.stats, output.stats); } return output; } HealthStatsMetrics();  HealthStatsMetrics(HealthStats healthStats);  HealthStatsMetrics(HealthStatsMetrics metrics); @Override HealthStatsMetrics sum(
      @Nullable HealthStatsMetrics b, @Nullable HealthStatsMetrics output); @Override HealthStatsMetrics diff(
      @Nullable HealthStatsMetrics b, @Nullable HealthStatsMetrics output); @Override HealthStatsMetrics set(HealthStatsMetrics b); HealthStatsMetrics set(HealthStats healthStats); @Override String toString(); static String getKeyName(int key); JSONObject toJSONObject(); @Override boolean equals(Object o); @Override int hashCode(); }
HealthStatsMetrics extends SystemMetrics<HealthStatsMetrics> { @Override public HealthStatsMetrics diff( @Nullable HealthStatsMetrics b, @Nullable HealthStatsMetrics output) { if (output == null) { output = new HealthStatsMetrics(); } output.dataType = dataType; if (b == null || compareSnapshotAge(this, b) < 0 ) { output.set(this); } else if (!strEquals(b.dataType, dataType)) { throw new IllegalArgumentException( "Attempting to subtract different types of HealthStatMetrics: " + dataType + " and " + b.dataType); } else { op(OP_DIFF, measurement, b.measurement, output.measurement); op(OP_DIFF, measurements, b.measurements, output.measurements); op(OP_DIFF, timer, b.timer, output.timer); op(OP_DIFF, timers, b.timers, output.timers); op(OP_DIFF, stats, b.stats, output.stats); } return output; } HealthStatsMetrics();  HealthStatsMetrics(HealthStats healthStats);  HealthStatsMetrics(HealthStatsMetrics metrics); @Override HealthStatsMetrics sum(
      @Nullable HealthStatsMetrics b, @Nullable HealthStatsMetrics output); @Override HealthStatsMetrics diff(
      @Nullable HealthStatsMetrics b, @Nullable HealthStatsMetrics output); @Override HealthStatsMetrics set(HealthStatsMetrics b); HealthStatsMetrics set(HealthStats healthStats); @Override String toString(); static String getKeyName(int key); JSONObject toJSONObject(); @Override boolean equals(Object o); @Override int hashCode(); public String dataType; final SparseArray<Long> measurement; final SparseArray<TimerMetrics> timer; final SparseArray<ArrayMap<String, Long>> measurements; final SparseArray<ArrayMap<String, TimerMetrics>> timers; final SparseArray<ArrayMap<String, HealthStatsMetrics>> stats; }