@Test public void testDiff() { BluetoothMetrics metrics = new BluetoothMetrics(); metrics.bleScanDurationMs = 1000; metrics.bleScanCount = 10; metrics.bleOpportunisticScanDurationMs = 5000; metrics.bleOpportunisticScanCount = 3; BluetoothMetrics olderMetrics = new BluetoothMetrics(); olderMetrics.bleScanDurationMs = 800; olderMetrics.bleScanCount = 7; olderMetrics.bleOpportunisticScanDurationMs = 2000; olderMetrics.bleOpportunisticScanCount = 1; BluetoothMetrics deltaMetrics = new BluetoothMetrics(); deltaMetrics = metrics.diff(olderMetrics, deltaMetrics); assertThat(deltaMetrics.bleScanCount).isEqualTo(3); assertThat(deltaMetrics.bleScanDurationMs).isEqualTo(200); assertThat(deltaMetrics.bleOpportunisticScanCount).isEqualTo(2); assertThat(deltaMetrics.bleOpportunisticScanDurationMs).isEqualTo(3000); }
@Override public BluetoothMetrics diff(@Nullable BluetoothMetrics b, @Nullable BluetoothMetrics output) { if (output == null) { output = new BluetoothMetrics(); } if (b == null) { output.set(this); } else { output.bleScanCount = bleScanCount - b.bleScanCount; output.bleScanDurationMs = bleScanDurationMs - b.bleScanDurationMs; output.bleOpportunisticScanCount = bleOpportunisticScanCount - b.bleOpportunisticScanCount; output.bleOpportunisticScanDurationMs = bleOpportunisticScanDurationMs - b.bleOpportunisticScanDurationMs; } return output; }
BluetoothMetrics extends SystemMetrics<BluetoothMetrics> { @Override public BluetoothMetrics diff(@Nullable BluetoothMetrics b, @Nullable BluetoothMetrics output) { if (output == null) { output = new BluetoothMetrics(); } if (b == null) { output.set(this); } else { output.bleScanCount = bleScanCount - b.bleScanCount; output.bleScanDurationMs = bleScanDurationMs - b.bleScanDurationMs; output.bleOpportunisticScanCount = bleOpportunisticScanCount - b.bleOpportunisticScanCount; output.bleOpportunisticScanDurationMs = bleOpportunisticScanDurationMs - b.bleOpportunisticScanDurationMs; } return output; } }
BluetoothMetrics extends SystemMetrics<BluetoothMetrics> { @Override public BluetoothMetrics diff(@Nullable BluetoothMetrics b, @Nullable BluetoothMetrics output) { if (output == null) { output = new BluetoothMetrics(); } if (b == null) { output.set(this); } else { output.bleScanCount = bleScanCount - b.bleScanCount; output.bleScanDurationMs = bleScanDurationMs - b.bleScanDurationMs; output.bleOpportunisticScanCount = bleOpportunisticScanCount - b.bleOpportunisticScanCount; output.bleOpportunisticScanDurationMs = bleOpportunisticScanDurationMs - b.bleOpportunisticScanDurationMs; } return output; }  }
BluetoothMetrics extends SystemMetrics<BluetoothMetrics> { @Override public BluetoothMetrics diff(@Nullable BluetoothMetrics b, @Nullable BluetoothMetrics output) { if (output == null) { output = new BluetoothMetrics(); } if (b == null) { output.set(this); } else { output.bleScanCount = bleScanCount - b.bleScanCount; output.bleScanDurationMs = bleScanDurationMs - b.bleScanDurationMs; output.bleOpportunisticScanCount = bleOpportunisticScanCount - b.bleOpportunisticScanCount; output.bleOpportunisticScanDurationMs = bleOpportunisticScanDurationMs - b.bleOpportunisticScanDurationMs; } return output; }  @Override BluetoothMetrics sum(@Nullable BluetoothMetrics b, @Nullable BluetoothMetrics output); @Override BluetoothMetrics diff(@Nullable BluetoothMetrics b, @Nullable BluetoothMetrics output); @Override BluetoothMetrics set(BluetoothMetrics b); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString(); }
BluetoothMetrics extends SystemMetrics<BluetoothMetrics> { @Override public BluetoothMetrics diff(@Nullable BluetoothMetrics b, @Nullable BluetoothMetrics output) { if (output == null) { output = new BluetoothMetrics(); } if (b == null) { output.set(this); } else { output.bleScanCount = bleScanCount - b.bleScanCount; output.bleScanDurationMs = bleScanDurationMs - b.bleScanDurationMs; output.bleOpportunisticScanCount = bleOpportunisticScanCount - b.bleOpportunisticScanCount; output.bleOpportunisticScanDurationMs = bleOpportunisticScanDurationMs - b.bleOpportunisticScanDurationMs; } return output; }  @Override BluetoothMetrics sum(@Nullable BluetoothMetrics b, @Nullable BluetoothMetrics output); @Override BluetoothMetrics diff(@Nullable BluetoothMetrics b, @Nullable BluetoothMetrics output); @Override BluetoothMetrics set(BluetoothMetrics b); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString(); public int bleScanCount; public long bleScanDurationMs; public int bleOpportunisticScanCount; public long bleOpportunisticScanDurationMs; }