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

COVERAGE SUMMARY FOR SOURCE FILE [ManagedPMF.java]

nameclass, %method, %block, %line, %
ManagedPMF.java0%   (0/1)0%   (0/12)0%   (0/234)0%   (0/63)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class ManagedPMF0%   (0/1)0%   (0/12)0%   (0/234)0%   (0/63)
ManagedPMF (): void 0%   (0/1)0%   (0/8)0%   (0/4)
ManagedPMF (IProbabilityMassFunction): void 0%   (0/1)0%   (0/6)0%   (0/3)
ManagedPMF (ProbabilityMassFunction): void 0%   (0/1)0%   (0/6)0%   (0/3)
createFromString (String): ManagedPMF 0%   (0/1)0%   (0/17)0%   (0/6)
getExpectedValue (): Long 0%   (0/1)0%   (0/37)0%   (0/7)
getExpectedValueDouble (): Double 0%   (0/1)0%   (0/34)0%   (0/7)
getMaxValue (): Object 0%   (0/1)0%   (0/36)0%   (0/10)
getModelPmf (): ProbabilityMassFunction 0%   (0/1)0%   (0/13)0%   (0/3)
getPmfTimeDomain (): IProbabilityMassFunction 0%   (0/1)0%   (0/13)0%   (0/3)
parse (String): ProbabilityFunctionLiteral 0%   (0/1)0%   (0/35)0%   (0/8)
reset (): void 0%   (0/1)0%   (0/10)0%   (0/4)
toString (): String 0%   (0/1)0%   (0/19)0%   (0/5)

1package de.uka.ipd.sdq.probfunction.math;
2 
3import java.util.Iterator;
4import java.util.List;
5 
6import org.antlr.runtime.ANTLRStringStream;
7import org.antlr.runtime.CommonTokenStream;
8import org.antlr.runtime.RecognitionException;
9 
10import de.uka.ipd.sdq.probfunction.ProbabilityMassFunction;
11import de.uka.ipd.sdq.probfunction.math.exception.StringNotPDFException;
12import de.uka.ipd.sdq.probfunction.print.ProbFunctionPrettyPrint;
13import de.uka.ipd.sdq.stoex.ProbabilityFunctionLiteral;
14import de.uka.ipd.sdq.stoex.parser.StochasticExpressionsLexer;
15import de.uka.ipd.sdq.stoex.parser.StochasticExpressionsParser;
16 
17/**
18 * To be continued...
19 * 
20 * @author jens
21 * 
22 */
23public class ManagedPMF {
24 
25        private IProbabilityFunctionFactory pfFactory = IProbabilityFunctionFactory.eINSTANCE;
26 
27        private IProbabilityMassFunction pmfTimeDomain;
28 
29        private ProbabilityMassFunction modelPmf;
30 
31        private String pmfAsString;
32 
33        private ManagedPMF() {
34                reset();
35        }
36 
37        public ManagedPMF(IProbabilityMassFunction pmf) {
38                this();
39                pmfTimeDomain = pmf;
40        }
41 
42        public ManagedPMF(ProbabilityMassFunction modelPMF) {
43                this();
44                this.modelPmf = modelPMF;
45        }
46 
47        private void reset() {
48                pmfTimeDomain = null;
49                modelPmf = null;
50                pmfAsString = null;
51        }
52 
53        public IProbabilityMassFunction getPmfTimeDomain() {
54                if (pmfTimeDomain == null) {
55                        pmfTimeDomain = pfFactory.transformToPMF(modelPmf);
56                }
57                return pmfTimeDomain;
58        }
59 
60        public ProbabilityMassFunction getModelPmf() {
61                if (modelPmf == null) {
62                        modelPmf = pfFactory.transformToModelPMF(pmfTimeDomain);
63                }
64                return modelPmf;
65        }
66 
67        @Override
68        public String toString() {
69                if (pmfAsString == null) {
70                        ProbabilityMassFunction pmf = getModelPmf();
71                        ProbFunctionPrettyPrint pp = new ProbFunctionPrettyPrint();
72                        pmfAsString = (String) pp.doSwitch(pmf);
73                }
74                return pmfAsString;
75        }
76 
77        @SuppressWarnings("unchecked")
78        public Object getMaxValue() {
79                IProbabilityMassFunction pmf = getPmfTimeDomain();
80                if (pmf.hasOrderedDomain()) {
81                        Object max = null;
82                        for (Iterator iter = pmf.getSamples().iterator(); iter.hasNext();) {
83                                ISample sample = (ISample) iter.next();
84                                Object obj = sample.getValue();
85                                if ((max == null) || ( ((Comparable)max).compareTo(obj) < 0)) {
86                                        max = obj;
87                                }
88                        }
89                        return max;
90                } else {
91                        return null;
92                }
93        }
94 
95        public Long getExpectedValue() {
96                IProbabilityMassFunction pmf = getPmfTimeDomain();
97                List<ISample> sampleList = pmf.getSamples();
98                double result = 0.0;
99                for (ISample sample : sampleList){
100                        Integer value = (Integer)sample.getValue();
101                        result += value.doubleValue() * sample.getProbability();
102                }
103                return new Long(Math.round(result));
104        }
105        
106        public Double getExpectedValueDouble() {
107                IProbabilityMassFunction pmf = getPmfTimeDomain();
108                List<ISample> sampleList = pmf.getSamples();
109                double result = 0.0;
110                for (ISample sample : sampleList){
111                        Number value = (Number)sample.getValue();
112                        result += value.doubleValue() * sample.getProbability();
113                }
114                return result;
115        }
116        
117        private static ProbabilityFunctionLiteral parse(String s) throws RecognitionException {
118                try{
119                        int iterInt = Integer.parseInt(s);
120                        s = "IntPMF[("+iterInt+";1.0)]";
121                }
122                catch(NumberFormatException e){
123                }
124                
125                StochasticExpressionsLexer lexer = new StochasticExpressionsLexer(
126                                new ANTLRStringStream(s));
127                StochasticExpressionsParser parser = new StochasticExpressionsParser(
128                                new CommonTokenStream(lexer));
129                return (ProbabilityFunctionLiteral)parser.expression();
130        }
131        
132        @SuppressWarnings("deprecation")
133        public static ManagedPMF createFromString(String pmfAsString)
134                        throws RecognitionException,
135                        StringNotPDFException {
136                ProbabilityFunctionLiteral value = parse(pmfAsString);
137                try {
138                        ProbabilityMassFunction pmf = (ProbabilityMassFunction) value
139                                        .getFunction_ProbabilityFunctionLiteral();
140                        return new ManagedPMF(pmf);
141                } catch (ClassCastException e) {
142                        throw new StringNotPDFException();
143                }
144        }
145}

[all classes][de.uka.ipd.sdq.probfunction.math]
EMMA 2.0.9414 (unsupported private build) (C) Vladimir Roubtsov