@Test public void testGetAverage() { Measurements mes = new Measurements(); Measurement m1 = new Measurement("value", 10); Measurement m2 = new Measurement("value", 6); mes.addMeasurement(m1); mes.addMeasurement(m2); Measurement res = mes.getAverage(); PositiveFloatValue fv = (PositiveFloatValue) res.getValue(); Assert.assertTrue(fv.getValue() == 8); }
public Measurement getAverage() { if (list.size() == 0) { return null; } Measurement m = list.get(0); if (!(m.getValue() instanceof INumericValue)) { throw new IllegalArgumentException("cannot calculate average of nun-numeric value: " + m.getMeasureId()); } double average = 0.0; for (Measurement meas : list) { INumericValue value = (INumericValue) meas.getValue(); average += value.value(); } average = average / list.size(); Measurement measurement = new Measurement(m.getMeasureId() + ":accumulated:average(" + list.size() + ")", average); return measurement; }
Measurements implements Serializable { public Measurement getAverage() { if (list.size() == 0) { return null; } Measurement m = list.get(0); if (!(m.getValue() instanceof INumericValue)) { throw new IllegalArgumentException("cannot calculate average of nun-numeric value: " + m.getMeasureId()); } double average = 0.0; for (Measurement meas : list) { INumericValue value = (INumericValue) meas.getValue(); average += value.value(); } average = average / list.size(); Measurement measurement = new Measurement(m.getMeasureId() + ":accumulated:average(" + list.size() + ")", average); return measurement; } }
Measurements implements Serializable { public Measurement getAverage() { if (list.size() == 0) { return null; } Measurement m = list.get(0); if (!(m.getValue() instanceof INumericValue)) { throw new IllegalArgumentException("cannot calculate average of nun-numeric value: " + m.getMeasureId()); } double average = 0.0; for (Measurement meas : list) { INumericValue value = (INumericValue) meas.getValue(); average += value.value(); } average = average / list.size(); Measurement measurement = new Measurement(m.getMeasureId() + ":accumulated:average(" + list.size() + ")", average); return measurement; }  }
Measurements implements Serializable { public Measurement getAverage() { if (list.size() == 0) { return null; } Measurement m = list.get(0); if (!(m.getValue() instanceof INumericValue)) { throw new IllegalArgumentException("cannot calculate average of nun-numeric value: " + m.getMeasureId()); } double average = 0.0; for (Measurement meas : list) { INumericValue value = (INumericValue) meas.getValue(); average += value.value(); } average = average / list.size(); Measurement measurement = new Measurement(m.getMeasureId() + ":accumulated:average(" + list.size() + ")", average); return measurement; }  void addMeasurement(Measurement measurement); Measurement getAverage(); int getSize(); int getId(); void setId(int id); List<Measurement> getList(); void setList(List<Measurement> list); }
Measurements implements Serializable { public Measurement getAverage() { if (list.size() == 0) { return null; } Measurement m = list.get(0); if (!(m.getValue() instanceof INumericValue)) { throw new IllegalArgumentException("cannot calculate average of nun-numeric value: " + m.getMeasureId()); } double average = 0.0; for (Measurement meas : list) { INumericValue value = (INumericValue) meas.getValue(); average += value.value(); } average = average / list.size(); Measurement measurement = new Measurement(m.getMeasureId() + ":accumulated:average(" + list.size() + ")", average); return measurement; }  void addMeasurement(Measurement measurement); Measurement getAverage(); int getSize(); int getId(); void setId(int id); List<Measurement> getList(); void setList(List<Measurement> list);  }