in metrics/src/main/java/com/facebook/battery/metrics/healthstats/HealthStatsMetrics.java [229:261]
private static <V> Object opValues(int op, V a, @Nullable V b) {
if (a instanceof Long) {
return (Long) a + (b == null ? 0 : (op * (Long) b));
}
if (a instanceof TimerMetrics) {
TimerMetrics timerMetricsA = (TimerMetrics) a;
TimerMetrics timerMetricsB = (TimerMetrics) b;
if (b == null) {
return new TimerMetrics(timerMetricsA);
}
TimerMetrics timerMetrics = new TimerMetrics();
timerMetrics.count = timerMetricsA.count + op * timerMetricsB.count;
timerMetrics.timeMs = timerMetricsA.timeMs + op * timerMetricsB.timeMs;
return timerMetrics;
}
if (a instanceof HealthStatsMetrics) {
if (op == OP_SUM) {
return ((HealthStatsMetrics) a).sum((HealthStatsMetrics) b, null);
} else {
return ((HealthStatsMetrics) a).diff((HealthStatsMetrics) b, null);
}
}
if (a instanceof ArrayMap) {
return opArrayMaps(op, (ArrayMap) a, (ArrayMap) b);
}
throw new IllegalArgumentException("Handling unsupported values");
}