EMMA Coverage Report (generated Sun Feb 05 10:43:15 CET 2012)
[all classes][de.fzi.se.accuracy.transformation]

COVERAGE SUMMARY FOR SOURCE FILE [PCMRandomVariableSpecificationAccuracyMaximumTrafo.java]

nameclass, %method, %block, %line, %
PCMRandomVariableSpecificationAccuracyMaximumTrafo.java0%   (0/1)0%   (0/10)0%   (0/150)0%   (0/40)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class PCMRandomVariableSpecificationAccuracyMaximumTrafo0%   (0/1)0%   (0/10)0%   (0/150)0%   (0/40)
<static initializer> 0%   (0/1)0%   (0/4)0%   (0/2)
PCMRandomVariableSpecificationAccuracyMaximumTrafo (): void 0%   (0/1)0%   (0/3)0%   (0/1)
caseExactlyAsSpecifiedPrecision (ExactlyAsSpecifiedPrecision): Boolean 0%   (0/1)0%   (0/7)0%   (0/3)
caseLimitedDeviationPrecision (LimitedDeviationPrecision): Boolean 0%   (0/1)0%   (0/60)0%   (0/10)
caseNoPrecision (NoPrecision): Boolean 0%   (0/1)0%   (0/25)0%   (0/8)
casePrecision (Precision): Boolean 0%   (0/1)0%   (0/22)0%   (0/5)
checkModifiedVariable (): void 0%   (0/1)0%   (0/14)0%   (0/5)
reset (): void 0%   (0/1)0%   (0/7)0%   (0/3)
setModifiedVariable (PCMRandomVariable): void 0%   (0/1)0%   (0/4)0%   (0/2)
setUpperLimit (String): void 0%   (0/1)0%   (0/4)0%   (0/2)

1/**
2 *
3 */
4package de.fzi.se.accuracy.transformation;
5 
6import org.apache.log4j.Logger;
7 
8import de.fzi.se.quality.qualityannotation.ExactlyAsSpecifiedPrecision;
9import de.fzi.se.quality.qualityannotation.LimitedDeviationPrecision;
10import de.fzi.se.quality.qualityannotation.NoPrecision;
11import de.fzi.se.quality.qualityannotation.Precision;
12import de.fzi.se.quality.qualityannotation.util.QualityAnnotationSwitch;
13import static de.fzi.se.quality.util.StoExHelper.*;
14import de.uka.ipd.sdq.pcm.core.PCMRandomVariable;
15 
16/**Modifies a given PCM Random Variable according to the maximum allowed by a precision.
17 * First set the random variable by {@link #setModifiedVariable(PCMRandomVariable)} then transform it by {@link #doSwitch(org.eclipse.emf.ecore.EObject)}.
18 
19 * @author groenda
20 *
21 */
22public class PCMRandomVariableSpecificationAccuracyMaximumTrafo extends
23                QualityAnnotationSwitch<Boolean> {
24        /** Logger for this class. */
25        private static final Logger logger = Logger.getLogger(PCMRandomVariableSpecificationAccuracyMaximumTrafo.class);
26 
27        /** The variable modified by the transformation when {@link #doSwitch(org.eclipse.emf.ecore.EObject)} is called. */
28        private PCMRandomVariable modifiedVariable;
29 
30        /** Maximal value reported will not be greater than this bound. */
31        private String upperLimit;
32 
33        /**Sets the upper bound for the maximum.
34         * The transformation will not result in values above this bound.
35         * The bound is automatically reset after an invocation of {@link #doSwitch(org.eclipse.emf.ecore.EObject)}.
36         * @param lowerLimit The lower bound.
37         */
38        public void setUpperLimit(String upperLimit) {
39                this.upperLimit = upperLimit;
40        }
41 
42        /**Set the variable to modify upon invocation of {@link #doSwitch(org.eclipse.emf.ecore.EObject)}.
43         * @param modifiedVariable The variable.
44         */
45        public void setModifiedVariable(PCMRandomVariable modifiedVariable) {
46                this.modifiedVariable = modifiedVariable;
47        }
48 
49        @Override
50        public Boolean caseNoPrecision(NoPrecision object) {
51                checkModifiedVariable();
52                if (upperLimit == null) {
53                        String msg = "Dynamic type inference of specificaitons to determine maximal value is not implemented (yet).";
54                        logger.error(msg);
55                        throw new IllegalArgumentException(msg);
56                } else {
57                        modifiedVariable.setSpecification(upperLimit);
58                }
59                reset();
60                return true;
61        }
62 
63        @Override
64        public Boolean caseExactlyAsSpecifiedPrecision(
65                        ExactlyAsSpecifiedPrecision object) {
66                checkModifiedVariable();
67                reset();
68                // nothing to do
69                return true;
70        }
71 
72        @Override
73        public Boolean caseLimitedDeviationPrecision(
74                        LimitedDeviationPrecision object) {
75                checkModifiedVariable();
76                String spec = modifiedVariable.getSpecification();
77                String abs = "" + object.getAbsolute();
78                String rel = "" + object.getRelative();
79                String max = "MaxDeviation(" + spec + ", " + abs + ", " + rel + ")";
80                if (upperLimit == null) {
81                        modifiedVariable.setSpecification(max);
82                } else {
83                        modifiedVariable.setSpecification(stoExMin(max, upperLimit));
84                }
85                reset();
86                return true;
87        }
88 
89        @Override
90        public Boolean casePrecision(Precision object) {
91                checkModifiedVariable();
92                String msg = "The handling of the provided Precision " + object + " is not implemented.";
93                logger.error(msg);
94                reset();
95                throw new IllegalArgumentException(msg);
96        }
97 
98        /**Checks that the modified variable is set.
99         *
100         */
101        private void checkModifiedVariable() {
102                if (modifiedVariable == null) {
103                        String msg = "You have to set the modified variable before invoking doSwitch(). Note: The modified variable is reset after an execution of doSwitch() to prevent accidental transformations of the same variable.";
104                        logger.error(msg);
105                        throw new IllegalArgumentException(msg);
106                }
107        }
108 
109        /**Prevent accidental re-transformation by resetting this classes instance variables.
110         */
111        private void reset() {
112                modifiedVariable = null;
113                upperLimit = null;
114        }
115}

[all classes][de.fzi.se.accuracy.transformation]
EMMA 2.0.9414 (unsupported private build) (C) Vladimir Roubtsov