KickJava   Java API By Example, From Geeks To Geeks.

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


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 fraction a / (a + b) expressed
16  * as a percentage.
17  * @keep-all
18  */

19 public class PercentageSumMetric extends DerivedMetric {
20
21     private final Metric a;
22     private final Metric b;
23
24     public PercentageSumMetric(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     }
28
29     public PercentageSumMetric(String JavaDoc name, String JavaDoc displayName, String JavaDoc category,
30             String JavaDoc descr, Metric a, Metric b) {
31         super(name, displayName, category, descr, 1);
32         this.a = a;
33         this.b = b;
34     }
35
36     /**
37      * How many arguments does this metric accept? Return 0 for any number
38      * of arguments.
39      */

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

52     public double get(MetricDataSource dataSet, int firstSampleNo, int lastSampleNo,
53             int calc, double seconds) {
54         double a = this.a.get(dataSet, firstSampleNo, lastSampleNo, calc, seconds);
55         double b = this.b.get(dataSet, firstSampleNo, lastSampleNo, calc, seconds);
56         double tot = a + b;
57         if (tot == 0.0) return 0.0;
58         return a * 100.0 / tot;
59     }
60
61     /**
62      * What calculation method makes the most sense for this Metric.
63      */

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