1 32 33 package com.jeantessier.metrics; 34 35 48 public class CounterMeasurement extends MeasurementBase { 49 private double value; 50 51 public CounterMeasurement(MeasurementDescriptor descriptor, Metrics context, String initText) { 52 super(descriptor, context, initText); 53 54 try { 55 if (initText != null) { 56 value = Double.parseDouble(initText); 57 } 58 } catch (NumberFormatException ex) { 59 value = 0; 60 } 61 } 62 63 public void add(Object object) { 64 if (object instanceof Number ) { 65 value += ((Number ) object).doubleValue(); 66 } else { 67 value++; 68 } 69 70 setEmpty(false); 71 } 72 73 public void add(int i) { 74 value += i; 75 setEmpty(false); 76 } 77 78 public void add(long l) { 79 value += l; 80 setEmpty(false); 81 } 82 83 public void add(float f) { 84 value += f; 85 setEmpty(false); 86 } 87 88 public void add(double d) { 89 value += d; 90 setEmpty(false); 91 } 92 93 public void accept(MeasurementVisitor visitor) { 94 visitor.visitCounterMeasurement(this); 95 } 96 97 protected double compute() { 98 return value; 99 } 100 } 101 | Popular Tags |