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: /**
14: * A performance metric that is the sum of two other metrics.
15: * @keep-all
16: */
17: public class SumMetric extends DerivedMetric {
18:
19: private Metric metricA;
20: private Metric metricB;
21:
22: public SumMetric(String name, String displayName, String category,
23: String descr, Metric[] args) {
24: this (name, displayName, category, descr, args[0], args[1]);
25: }
26:
27: public SumMetric(String name, String displayName, String category,
28: String descr, Metric metricA, Metric metricB) {
29: super (name, displayName, category, descr, metricA.getDecimals());
30: this .metricA = metricA;
31: this .metricB = metricB;
32: }
33:
34: /**
35: * How many arguments does this metric accept? Return 0 for any number
36: * of arguments.
37: */
38: public int getArgCount() {
39: return 2;
40: }
41:
42: /**
43: * Get the value of this metric for the given range of samples in the
44: * data set.
45: * @param dataSet The raw data
46: * @param firstSampleNo The first sample
47: * @param lastSampleNo The last sample (inclusive)
48: * @param calc The duration of the sample range in seconds
49: */
50: public double get(MetricDataSource dataSet, int firstSampleNo,
51: int lastSampleNo, int calc, double seconds) {
52: return metricA.get(dataSet, firstSampleNo, lastSampleNo, calc,
53: seconds)
54: + metricB.get(dataSet, firstSampleNo, lastSampleNo,
55: calc, seconds);
56: }
57:
58: /**
59: * What calculation method makes the most sense for this Metric.
60: */
61: public int getDefaultCalc() {
62: return metricA.getDefaultCalc();
63: }
64:
65: }
|