EMMA Coverage Report (generated Sun Feb 05 10:43:15 CET 2012)
[all classes][de.uka.ipd.sdq.probespec.framework.calculator]

COVERAGE SUMMARY FOR SOURCE FILE [TimeSpanCalculator.java]

nameclass, %method, %block, %line, %
TimeSpanCalculator.java0%   (0/1)0%   (0/3)0%   (0/98)0%   (0/28)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class TimeSpanCalculator0%   (0/1)0%   (0/3)0%   (0/98)0%   (0/28)
TimeSpanCalculator (ProbeSpecContext, Integer, Integer): void 0%   (0/1)0%   (0/6)0%   (0/2)
calculate (ProbeSetSample, ProbeSetSample): Vector 0%   (0/1)0%   (0/66)0%   (0/19)
obtainCurrentTimeProbeSample (ProbeSetSample): ProbeSample 0%   (0/1)0%   (0/26)0%   (0/7)

1package de.uka.ipd.sdq.probespec.framework.calculator;
2 
3import java.math.BigDecimal;
4import java.util.Vector;
5 
6import javax.measure.Measure;
7import javax.measure.quantity.Duration;
8import javax.measure.quantity.Quantity;
9 
10import de.uka.ipd.sdq.probespec.framework.ProbeSample;
11import de.uka.ipd.sdq.probespec.framework.ProbeSetSample;
12import de.uka.ipd.sdq.probespec.framework.ProbeSpecContext;
13import de.uka.ipd.sdq.probespec.framework.ProbeType;
14import de.uka.ipd.sdq.probespec.framework.exceptions.CalculatorException;
15import de.uka.ipd.sdq.probespec.framework.matching.IMatchRule;
16import de.uka.ipd.sdq.probespec.framework.matching.ProbeTypeMatchRule;
17 
18/**
19 * Calculates a time span. It expects two ProbeSets each containing at least a
20 * {@link ProbeType#CURRENT_TIME} probe.
21 * 
22 * @author Faber, Philipp Merkle
23 * 
24 */
25public abstract class TimeSpanCalculator extends BinaryCalculator {
26 
27    public TimeSpanCalculator(ProbeSpecContext ctx, Integer startProbeSetID, Integer endProbeSetID) {
28        super(ctx, startProbeSetID, endProbeSetID);
29    }
30 
31        /**
32         * Calculates the time span.
33         * 
34         * @param start
35         *            the ProbeSample of the start ProbeSet (ProbeType.CURRENT_TIME)
36         * @param end
37         *            the ProbeSample of the end ProbeSet (ProbeType.CURRENT_TIME)
38         * @return a result tuple containing two components. The first component is
39         *         the calculated time span, the second component is the end time of
40         *         the time span.
41         */
42        @Override
43        protected Vector<Measure<?, ? extends Quantity>> calculate(
44                        ProbeSetSample start, ProbeSetSample end)
45                        throws CalculatorException {
46                // Obtain start time sample
47                ProbeSample<Double, Duration> startTimeSample = obtainCurrentTimeProbeSample(start);
48                if (startTimeSample == null) {
49                        throw new CalculatorException(
50                                        "Could not access start probe sample.");
51                }
52 
53                // Obtain end time sample
54                ProbeSample<Double, Duration> endTimeSample = obtainCurrentTimeProbeSample(end);
55                if (endTimeSample == null) {
56                        throw new CalculatorException("Could not access end probe sample.");
57                }
58 
59                // Calculate time span
60                BigDecimal endTime = BigDecimal.valueOf(endTimeSample.getMeasure().doubleValue(
61                                startTimeSample.getMeasure().getUnit()));
62                BigDecimal startTime = BigDecimal.valueOf(startTimeSample.getMeasure().doubleValue(
63                                startTimeSample.getMeasure().getUnit()));
64                
65                BigDecimal responseTime = endTime.subtract(startTime);
66 
67                // Create result tuple
68                Measure<Double, Duration> timeSpanMeasure = Measure.valueOf(
69                                responseTime.doubleValue(), startTimeSample.getMeasure().getUnit());
70                Measure<Double, Duration> endTimeMeasure = endTimeSample.getMeasure();
71                Vector<Measure<?, ? extends Quantity>> resultTuple = new Vector<Measure<?, ? extends Quantity>>();
72                resultTuple.add(timeSpanMeasure);
73                resultTuple.add(endTimeMeasure);
74 
75                return resultTuple;
76        }
77 
78        @SuppressWarnings("unchecked")
79        private ProbeSample<Double, Duration> obtainCurrentTimeProbeSample(
80                        ProbeSetSample probeSetSample) {
81                IMatchRule[] rules = new IMatchRule[1];
82                rules[0] = new ProbeTypeMatchRule(ProbeType.CURRENT_TIME);
83                Vector<ProbeSample<?, ? extends Quantity>> result = probeSetSample
84                                .getProbeSamples(rules);
85 
86                if (result != null && result.size() > 0)
87                        return (ProbeSample<Double, Duration>) result.get(0);
88 
89                return null;
90        }
91 
92}

[all classes][de.uka.ipd.sdq.probespec.framework.calculator]
EMMA 2.0.9414 (unsupported private build) (C) Vladimir Roubtsov