InvocationMetric implements java.io.Externalizable { public void merge(InvocationMetric metric) { if (metric.getCount() > 0) { int myCount=getCount(); int mergeCount=metric.getCount(); setCount(myCount + mergeCount); setCountChange(((getCountChange() * myCount) + (metric.getCountChange() * mergeCount)) / getCount()); setFaults(getFaults() + metric.getFaults()); setAverage(((getAverage() * myCount) + (metric.getAverage() * mergeCount)) / getCount()); setAverageChange(((getAverageChange() * myCount) + (metric.getAverageChange() * mergeCount)) / getCount()); if (getMin() == 0 || metric.getMin() < getMin()) { setMin(metric.getMin()); } setMinChange(((getMinChange() * myCount) + (metric.getMinChange() * mergeCount)) / getCount()); if (metric.getMax() > getMax()) { setMax(metric.getMax()); } setMaxChange(((getMaxChange() * myCount) + (metric.getMaxChange() * mergeCount)) / getCount()); } } InvocationMetric();  InvocationMetric(java.util.List<InvocationMetric> metrics); void setCount(int count); int getCount(); void setFaults(int faults); int getFaults(); void setAverage(long time); long getAverage(); void setMax(long time); long getMax(); void setMin(long time); long getMin(); void setCountChange(int change); int getCountChange(); void setAverageChange(int change); int getAverageChange(); void setMaxChange(int change); int getMaxChange(); void setMinChange(int change); int getMinChange(); void merge(InvocationMetric metric); String toString(); void writeExternal(ObjectOutput out); void readExternal(ObjectInput in);  }
@Test public void testMerge() { InvocationMetric im1=new InvocationMetric(); im1.setAverage(10); im1.setCount(1); im1.setFaults(1); im1.setMin(10); im1.setMax(10); InvocationMetric im2=new InvocationMetric(); im2.setAverage(50); im2.setCount(3); im2.setFaults(1); im2.setMin(10); im2.setMax(70); im1.merge(im2); if (im1.getCount() != 4) { fail("Count should be 4: "+im1.getCount()); } if (im1.getFaults() != 2) { fail("Faults should be 2: "+im1.getFaults()); } if (im1.getAverage() != 40) { fail("Average should be 40: "+im1.getAverage()); } if (im1.getMin() != 10) { fail("Min should be 10: "+im1.getMin()); } if (im1.getMax() != 70) { fail("Max should be 70: "+im1.getMax()); } }