1 2 12 package com.versant.core.metric; 13 14 17 public class BaseMetric extends Metric { 18 19 private int index = -1; 20 private final int defaultCalc; 21 22 public BaseMetric(String name, String displayName, String category, 23 String descr, int decimals, int defaultCalc) { 24 super(name, displayName, category, descr, decimals); 25 this.defaultCalc = defaultCalc; 26 } 27 28 public final int getIndex() { 29 return index; 30 } 31 32 public void setIndex(int index) { 33 this.index = index; 34 } 35 36 public int getDefaultCalc() { 37 return defaultCalc; 38 } 39 40 48 public double get(MetricDataSource dataSet, int firstSampleNo, int lastSampleNo, 49 int calc, double seconds) { 50 int a, b; 53 switch (calc) { 54 55 case CALC_RAW: 56 return dataSet.getSample(lastSampleNo, index) & 0xFFFFFFFFL; 57 58 case CALC_DELTA_PER_SECOND: 59 if (seconds > 0.0) { 60 a = dataSet.getSample(firstSampleNo, index); 61 b = dataSet.getSample(lastSampleNo, index); 62 return ((b & 0xFFFFFFFFL) - (a & 0xFFFFFFFFL)) / seconds; 63 } 64 65 case CALC_DELTA: 66 a = dataSet.getSample(firstSampleNo, index); 67 b = dataSet.getSample(lastSampleNo, index); 68 return (b & 0xFFFFFFFFL) - (a & 0xFFFFFFFFL); 69 70 case CALC_AVERAGE: 71 int n = lastSampleNo - firstSampleNo; 72 if (n <= 1) { return dataSet.getSample(lastSampleNo, index); 74 } 75 double tot = dataSet.getSample(firstSampleNo + 1, index); 76 for (int i = firstSampleNo + 2; i <= lastSampleNo; i++) { 77 tot += dataSet.getSample(i, index); 78 } 79 return tot / n; 80 }; 81 throw new IllegalArgumentException ("Unknown calc: " + calc); 82 } 83 84 } 85 | Popular Tags |