~ubuntu-branches/ubuntu/vivid/gmetrics/vivid

« back to all changes in this revision

Viewing changes to src/main/groovy/org/gmetrics/result/SingleNumberMetricResult.groovy

  • Committer: Package Import Robot
  • Author(s): Miguel Landaeta, Miguel Landaeta, tony mancill
  • Date: 2012-01-18 20:57:50 UTC
  • mfrom: (1.1.1)
  • Revision ID: package-import@ubuntu.com-20120118205750-68fv86p7fs8xz470
Tags: 0.5-1
[Miguel Landaeta]
* New upstream release.
* Remove patch ftbfs_613266.diff since it was merged upstream.
* Update dates in copyright file.

[tony mancill]
* Set DMUA flag.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright 2012 the original author or authors.
 
3
 * 
 
4
 * Licensed under the Apache License, Version 2.0 (the "License");
 
5
 * you may not use this file except in compliance with the License.
 
6
 * You may obtain a copy of the License at
 
7
 * 
 
8
 *      http://www.apache.org/licenses/LICENSE-2.0
 
9
 * 
 
10
 * Unless required by applicable law or agreed to in writing, software
 
11
 * distributed under the License is distributed on an "AS IS" BASIS,
 
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
13
 * See the License for the specific language governing permissions and
 
14
 * limitations under the License.
 
15
 */
 
16
package org.gmetrics.result
 
17
 
 
18
import org.gmetrics.metric.Metric
 
19
import org.gmetrics.metric.MetricLevel
 
20
 
 
21
/**
 
22
 * A MetricResult for numbers (integers, BigDecimals, etc.), that returns the same, single value for
 
23
 * total, average, minimum and maximum. An instance of this class is immutable.
 
24
 *
 
25
 * @author Chris Mair
 
26
 */
 
27
class SingleNumberMetricResult implements MetricResult {
 
28
 
 
29
    final Metric metric
 
30
    final MetricLevel metricLevel
 
31
    final number
 
32
    final Integer lineNumber
 
33
    final int count = 1
 
34
 
 
35
    /**
 
36
     * Construct a new instance
 
37
     * @param metric - the Metric to which this result applies
 
38
     * @param metricLevel - the metric level for this result
 
39
     * @param number - the single value to use for total, average, minimum, and maximum
 
40
     * @param lineNumber - the line number for the source element (AST) that triggered this metric result; may be null
 
41
     */
 
42
    SingleNumberMetricResult(Metric metric, MetricLevel metricLevel, number, Integer lineNumber=null) {
 
43
        assert metric
 
44
        assert metricLevel
 
45
        assert number != null
 
46
        this.metric = metric
 
47
        this.metricLevel = metricLevel
 
48
        this.number = number
 
49
        this.lineNumber = lineNumber
 
50
    }
 
51
 
 
52
    Object getAt(String name) {
 
53
        return name in metric.functions ? number : null
 
54
    }
 
55
 
 
56
    String toString() {
 
57
        "SingleNumberMetricResult[metric=${metric.name}, $number]"
 
58
    }
 
59
 
 
60
}
 
 
b'\\ No newline at end of file'