KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > versant > core > metric > Metric


1
2 /*
3  * Copyright (c) 1998 - 2005 Versant Corporation
4  * All rights reserved. This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License v1.0
6  * which accompanies this distribution, and is available at
7  * http://www.eclipse.org/legal/epl-v10.html
8  *
9  * Contributors:
10  * Versant Corporation - initial API and implementation
11  */

12 package com.versant.core.metric;
13
14 import java.io.Serializable JavaDoc;
15
16 /**
17  * A performance metric. Flyweight GOF pattern.
18  */

19 public abstract class Metric implements Serializable JavaDoc, Comparable JavaDoc {
20
21     private final String JavaDoc name;
22     private final String JavaDoc displayName;
23     private final String JavaDoc category;
24     private final String JavaDoc descr;
25     private final int decimals;
26
27     public static final int CALC_RAW = 1;
28     public static final int CALC_AVERAGE = 2;
29     public static final int CALC_DELTA = 3;
30     public static final int CALC_DELTA_PER_SECOND = 4;
31
32     public Metric(String JavaDoc name, String JavaDoc displayName, String JavaDoc category, String JavaDoc descr,
33             int decimals) {
34         this.name = name;
35         this.displayName = displayName;
36         this.category = category;
37         this.descr = descr;
38         this.decimals = decimals;
39     }
40
41     public String JavaDoc getName() {
42         return name;
43     }
44
45     public String JavaDoc getDisplayName() {
46         return displayName;
47     }
48
49     public String JavaDoc getCategory() {
50         return category;
51     }
52
53     public String JavaDoc getDescr() {
54         return descr;
55     }
56
57     public int getDecimals() {
58         return decimals;
59     }
60
61     public String JavaDoc toString() {
62         return name;
63     }
64
65     /**
66      * What calculation method makes the most sense for this Metric.
67      */

68     public abstract int getDefaultCalc();
69
70     /**
71      * Get the value of this metric for the given range of samples in the
72      * data set.
73      * @param dataSet The raw data
74      * @param firstSampleNo The first sample
75      * @param lastSampleNo The last sample (inclusive)
76      * @param calc The duration of the sample range
77      */

78     public abstract double get(MetricDataSource dataSet, int firstSampleNo,
79             int lastSampleNo, int calc, double seconds);
80
81     /**
82      * Sort by name.
83      */

84     public int compareTo(Object JavaDoc o) {
85         return getName().compareTo(((Metric)o).getName());
86     }
87
88 }
89
Popular Tags