KickJava   Java API By Example, From Geeks To Geeks.

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


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 /**
15  * A performance metric that is the difference of two other metrics.
16  * @keep-all
17  */

18 public class DifferenceMetric extends DerivedMetric {
19
20     private Metric metricA;
21     private Metric metricB;
22     private final int defaultCalc;
23
24     public DifferenceMetric(String JavaDoc name, String JavaDoc displayName, String JavaDoc category,
25             String JavaDoc descr, Metric[] args) {
26         this(name, displayName, category, descr, args[0], args[1],
27                 args[0].getDefaultCalc(), args[0].getDecimals());
28     }
29
30     public DifferenceMetric(String JavaDoc name, String JavaDoc displayName, String JavaDoc category, String JavaDoc descr,
31             Metric metricA, Metric metricB, int defaultCalc, int decimals) {
32         super(name, displayName, category, descr, decimals);
33         this.metricA = metricA;
34         this.metricB = metricB;
35         this.defaultCalc = defaultCalc;
36     }
37
38     /**
39      * How many arguments does this metric accept? Return 0 for any number
40      * of arguments.
41      */

42     public int getArgCount() {
43         return 2;
44     }
45
46     /**
47      * Get the value of this metric for the given range of samples in the
48      * data set.
49      * @param dataSet The raw data
50      * @param firstSampleNo The first sample
51      * @param lastSampleNo The last sample (inclusive)
52      * @param calc The duration of the sample range in seconds
53      */

54     public double get(MetricDataSource dataSet, int firstSampleNo, int lastSampleNo,
55             int calc, double seconds) {
56         return metricA.get(dataSet, firstSampleNo, lastSampleNo, calc, seconds)
57             - metricB.get(dataSet, firstSampleNo, lastSampleNo, calc, seconds);
58     }
59
60     /**
61      * What calculation method makes the most sense for this Metric.
62      */

63     public int getDefaultCalc() {
64         return defaultCalc;
65     }
66
67 }
68
69
Popular Tags