### Question:
CpuFrequencyMetrics extends SystemMetrics<CpuFrequencyMetrics> { @Override public CpuFrequencyMetrics sum( @Nullable CpuFrequencyMetrics b, @Nullable CpuFrequencyMetrics output) { if (output == null) { output = new CpuFrequencyMetrics(); } if (b == null) { output.set(this); } else { for (int i = 0; i < timeInStateS.length; i++) { SparseIntArray aCore = timeInStateS[i]; SparseIntArray bCore = b.timeInStateS[i]; SparseIntArray outputCore = output.timeInStateS[i]; for (int j = 0; j < aCore.size(); j++) { int frequency = aCore.keyAt(j); outputCore.put(frequency, aCore.valueAt(j) + bCore.get(frequency, 0)); } for (int j = 0; j < bCore.size(); j++) { int frequency = bCore.keyAt(j); if (aCore.indexOfKey(frequency) < 0) { outputCore.put(frequency, bCore.valueAt(j)); } } } } return output; } CpuFrequencyMetrics(); @Override CpuFrequencyMetrics sum(
      @Nullable CpuFrequencyMetrics b, @Nullable CpuFrequencyMetrics output); @Override CpuFrequencyMetrics diff(
      @Nullable CpuFrequencyMetrics b, @Nullable CpuFrequencyMetrics output); @Override CpuFrequencyMetrics set(CpuFrequencyMetrics b); @Override boolean equals(Object o); static boolean sparseIntArrayEquals(SparseIntArray a, SparseIntArray b); @Override int hashCode(); @Override String toString(); @Nullable JSONObject toJSONObject(); final SparseIntArray[] timeInStateS; }### Answer:
@Test public void testSum() { CpuFrequencyMetrics metricsA = new CpuFrequencyMetrics(); metricsA.timeInStateS[0].put(100, 1); metricsA.timeInStateS[0].put(200, 2); metricsA.timeInStateS[1].put(1000, 1); CpuFrequencyMetrics metricsB = new CpuFrequencyMetrics(); metricsB.timeInStateS[0].put(200, 5); metricsB.timeInStateS[0].put(300, 3); metricsB.timeInStateS[2].put(2000, 2); CpuFrequencyMetrics output = new CpuFrequencyMetrics(); metricsA.sum(metricsB, output); assertThat(output.timeInStateS[0].size()).isEqualTo(3); assertThat(output.timeInStateS[0].get(100)).isEqualTo(1); assertThat(output.timeInStateS[0].get(200)).isEqualTo(7); assertThat(output.timeInStateS[0].get(300)).isEqualTo(3); assertThat(output.timeInStateS[1].size()).isEqualTo(1); assertThat(output.timeInStateS[1].get(1000)).isEqualTo(1); assertThat(output.timeInStateS[2].size()).isEqualTo(1); assertThat(output.timeInStateS[2].get(2000)).isEqualTo(2); assertThat(output.timeInStateS[3].size()).isEqualTo(0); }