@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); } } }
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); } }
AggregatedMetricValues { 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); } } }
AggregatedMetricValues { 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); } } AggregatedMetricValues();  AggregatedMetricValues(Map<Short, MetricValues> valuesByMetricId); }
AggregatedMetricValues { 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); } } AggregatedMetricValues();  AggregatedMetricValues(Map<Short, MetricValues> valuesByMetricId); MetricValues valuesFor(short metricId); AggregatedMetricValues valuesFor(Collection<Short> metricIds, boolean shareValueArray); MetricValues valuesForGroup(String group, MetricDef metricDef, boolean shareValueArray); int length(); boolean isEmpty(); Set<Short> metricIds(); void add(short metricId, MetricValues metricValuesToAdd); void add(AggregatedMetricValues other); void subtract(AggregatedMetricValues other); void clear(); void writeTo(OutputStream out); @Override String toString(); }
AggregatedMetricValues { 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); } } AggregatedMetricValues();  AggregatedMetricValues(Map<Short, MetricValues> valuesByMetricId); MetricValues valuesFor(short metricId); AggregatedMetricValues valuesFor(Collection<Short> metricIds, boolean shareValueArray); MetricValues valuesForGroup(String group, MetricDef metricDef, boolean shareValueArray); int length(); boolean isEmpty(); Set<Short> metricIds(); void add(short metricId, MetricValues metricValuesToAdd); void add(AggregatedMetricValues other); void subtract(AggregatedMetricValues other); void clear(); void writeTo(OutputStream out); @Override String toString();  }