KickJava   Java API By Example, From Geeks To Geeks.

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


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 sum of two other metrics.
16  * @keep-all
17  */

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

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

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

60     public int getDefaultCalc() {
61         return metricA.getDefaultCalc();
62     }
63
64 }
65
66
Popular Tags