@Test public void testDiffArrayMaps() { ArrayMap<String, Long> a = new ArrayMap<>(); a.put("a", 1L); a.put("c", 2L); ArrayMap<String, Long> b = new ArrayMap<>(); b.put("b", 1L); b.put("c", 3L); ArrayMap<String, Long> sum = HealthStatsMetrics.opArrayMaps(OP_DIFF, a, b); assertThat(sum.get("a")).isEqualTo(1); assertThat(sum.get("c")).isEqualTo(-1); assertThat(sum.size()).isEqualTo(2); }
@VisibleForTesting static <K, V> ArrayMap<K, V> opArrayMaps(int op, ArrayMap<K, V> a, @Nullable ArrayMap<K, V> b) { int aSize = a.size(); ArrayMap<K, V> output = new ArrayMap<>(); for (int i = 0; i < aSize; i++) { K key = a.keyAt(i); V bValue = b == null ? null : b.get(key); output.put(key, bValue == null ? a.valueAt(i) : (V) opValues(op, a.valueAt(i), bValue)); } if (op == OP_SUM) { int bSize = b == null ? 0 : b.size(); for (int i = 0; i < bSize; i++) { K key = b.keyAt(i); if (a.get(key) == null) { output.put(key, b.valueAt(i)); } } } return output; }
HealthStatsMetrics extends SystemMetrics<HealthStatsMetrics> { @VisibleForTesting static <K, V> ArrayMap<K, V> opArrayMaps(int op, ArrayMap<K, V> a, @Nullable ArrayMap<K, V> b) { int aSize = a.size(); ArrayMap<K, V> output = new ArrayMap<>(); for (int i = 0; i < aSize; i++) { K key = a.keyAt(i); V bValue = b == null ? null : b.get(key); output.put(key, bValue == null ? a.valueAt(i) : (V) opValues(op, a.valueAt(i), bValue)); } if (op == OP_SUM) { int bSize = b == null ? 0 : b.size(); for (int i = 0; i < bSize; i++) { K key = b.keyAt(i); if (a.get(key) == null) { output.put(key, b.valueAt(i)); } } } return output; } }
HealthStatsMetrics extends SystemMetrics<HealthStatsMetrics> { @VisibleForTesting static <K, V> ArrayMap<K, V> opArrayMaps(int op, ArrayMap<K, V> a, @Nullable ArrayMap<K, V> b) { int aSize = a.size(); ArrayMap<K, V> output = new ArrayMap<>(); for (int i = 0; i < aSize; i++) { K key = a.keyAt(i); V bValue = b == null ? null : b.get(key); output.put(key, bValue == null ? a.valueAt(i) : (V) opValues(op, a.valueAt(i), bValue)); } if (op == OP_SUM) { int bSize = b == null ? 0 : b.size(); for (int i = 0; i < bSize; i++) { K key = b.keyAt(i); if (a.get(key) == null) { output.put(key, b.valueAt(i)); } } } return output; } HealthStatsMetrics();  HealthStatsMetrics(HealthStats healthStats);  HealthStatsMetrics(HealthStatsMetrics metrics); }
HealthStatsMetrics extends SystemMetrics<HealthStatsMetrics> { @VisibleForTesting static <K, V> ArrayMap<K, V> opArrayMaps(int op, ArrayMap<K, V> a, @Nullable ArrayMap<K, V> b) { int aSize = a.size(); ArrayMap<K, V> output = new ArrayMap<>(); for (int i = 0; i < aSize; i++) { K key = a.keyAt(i); V bValue = b == null ? null : b.get(key); output.put(key, bValue == null ? a.valueAt(i) : (V) opValues(op, a.valueAt(i), bValue)); } if (op == OP_SUM) { int bSize = b == null ? 0 : b.size(); for (int i = 0; i < bSize; i++) { K key = b.keyAt(i); if (a.get(key) == null) { output.put(key, b.valueAt(i)); } } } 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> { @VisibleForTesting static <K, V> ArrayMap<K, V> opArrayMaps(int op, ArrayMap<K, V> a, @Nullable ArrayMap<K, V> b) { int aSize = a.size(); ArrayMap<K, V> output = new ArrayMap<>(); for (int i = 0; i < aSize; i++) { K key = a.keyAt(i); V bValue = b == null ? null : b.get(key); output.put(key, bValue == null ? a.valueAt(i) : (V) opValues(op, a.valueAt(i), bValue)); } if (op == OP_SUM) { int bSize = b == null ? 0 : b.size(); for (int i = 0; i < bSize; i++) { K key = b.keyAt(i); if (a.get(key) == null) { output.put(key, b.valueAt(i)); } } } 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; }