01: /*
02: * Copyright (c) 1998 - 2005 Versant Corporation
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * Versant Corporation - initial API and implementation
10: */
11: package com.versant.core.metric;
12:
13: import java.io.Serializable;
14:
15: /**
16: * A performance metric. Flyweight GOF pattern.
17: */
18: public abstract class Metric implements Serializable, Comparable {
19:
20: private final String name;
21: private final String displayName;
22: private final String category;
23: private final String descr;
24: private final int decimals;
25:
26: public static final int CALC_RAW = 1;
27: public static final int CALC_AVERAGE = 2;
28: public static final int CALC_DELTA = 3;
29: public static final int CALC_DELTA_PER_SECOND = 4;
30:
31: public Metric(String name, String displayName, String category,
32: String descr, int decimals) {
33: this .name = name;
34: this .displayName = displayName;
35: this .category = category;
36: this .descr = descr;
37: this .decimals = decimals;
38: }
39:
40: public String getName() {
41: return name;
42: }
43:
44: public String getDisplayName() {
45: return displayName;
46: }
47:
48: public String getCategory() {
49: return category;
50: }
51:
52: public String getDescr() {
53: return descr;
54: }
55:
56: public int getDecimals() {
57: return decimals;
58: }
59:
60: public String toString() {
61: return name;
62: }
63:
64: /**
65: * What calculation method makes the most sense for this Metric.
66: */
67: public abstract int getDefaultCalc();
68:
69: /**
70: * Get the value of this metric for the given range of samples in the
71: * data set.
72: * @param dataSet The raw data
73: * @param firstSampleNo The first sample
74: * @param lastSampleNo The last sample (inclusive)
75: * @param calc The duration of the sample range
76: */
77: public abstract double get(MetricDataSource dataSet,
78: int firstSampleNo, int lastSampleNo, int calc,
79: double seconds);
80:
81: /**
82: * Sort by name.
83: */
84: public int compareTo(Object o) {
85: return getName().compareTo(((Metric) o).getName());
86: }
87:
88: }
|