public void subtract(AggregatedMetricValues other) {
    for (Map.Entry<Short, MetricValues> entry : other.metricValues().entrySet()) {
      short metricId = entry.getKey();
      MetricValues otherValuesForMetric = entry.getValue();
      MetricValues valuesForMetric = valuesFor(metricId);
      if (valuesForMetric == null) {
        throw new IllegalStateException("Cannot subtract a values from a non-existing MetricValues");
      }
      if (valuesForMetric.length() != otherValuesForMetric.length()) {
        throw new IllegalStateException("The two values arrays have different lengths " + valuesForMetric.length()
                                            + " and " + otherValuesForMetric.length());
      }
      valuesForMetric.subtract(otherValuesForMetric);
    }
  }
@Test
  public void testDeduct() {
    Map<Short, MetricValues> valuesByMetricId = getValuesByMetricId();

    AggregatedMetricValues aggregatedMetricValues = new AggregatedMetricValues(valuesByMetricId);
    aggregatedMetricValues.subtract(aggregatedMetricValues);

    for (Map.Entry<Short, MetricValues> entry : valuesByMetricId.entrySet()) {
      MetricValues values = entry.getValue();
      for (int j = 0; j < 10; j++) {
        assertEquals(0, values.get(j), 0.01);
      }
    }
  }