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

COVERAGE SUMMARY FOR SOURCE FILE [StateSensorToPieAdapter.java]

nameclass, %method, %block, %line, %
StateSensorToPieAdapter.java0%   (0/1)0%   (0/3)0%   (0/89)0%   (0/19)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class StateSensorToPieAdapter0%   (0/1)0%   (0/3)0%   (0/89)0%   (0/19)
StateSensorToPieAdapter (SensorAndMeasurements): void 0%   (0/1)0%   (0/6)0%   (0/3)
createPie (HashMap, double): AbstractPie 0%   (0/1)0%   (0/70)0%   (0/13)
getAdaptedObject (): Object 0%   (0/1)0%   (0/13)0%   (0/3)

1package de.uka.ipd.sdq.sensorframework.adapter;
2 
3import java.text.DecimalFormat;
4import java.text.DecimalFormatSymbols;
5import java.util.HashMap;
6import java.util.Locale;
7import java.util.Map.Entry;
8 
9import de.uka.ipd.sdq.codegen.simudatavisualisation.datatypes.AbstractPie;
10import de.uka.ipd.sdq.codegen.simudatavisualisation.datatypes.PieEntity;
11import de.uka.ipd.sdq.sensorframework.entities.SensorAndMeasurements;
12import de.uka.ipd.sdq.sensorframework.entities.StateSensor;
13 
14/**
15 * Provides an adapter that allows to convert StateSensors to Pies.
16 * 
17 * @author Henning Groenda
18 */
19public abstract class StateSensorToPieAdapter extends DataAdapter {
20 
21        /** Factor to display values in percent. */
22        private static final int FACTOR_PERCENT = 100;
23 
24        /** Information about the StateSensor and the measurements. */
25        protected SensorAndMeasurements samInformation;
26 
27        /**
28         * Initializes the adapter with the given StateSensor measurements.
29         * 
30         * @param samInformation
31         *            Information about the StateSensor and the measurements.
32         */
33        protected StateSensorToPieAdapter(final SensorAndMeasurements samInformation) {
34                super();
35                this.samInformation = samInformation;
36        }
37 
38        /**
39         * {@inheritDoc}
40         */
41        public Object getAdaptedObject() {
42                HashMap<String, Double> fractions = new HashMap<String, Double>();
43                double sum = calculateFractions(fractions);
44                return createPie(fractions, sum);
45        }
46 
47        /**
48         * Takes sum of the time in which all states were active and creates a Pie
49         * from it
50         * 
51         * @param timeSums
52         *            A map which associates to each state the sum of the time this
53         *            state has been active
54         * @param sum
55         *            Total sum of times
56         * @return A pie representation of the data
57         */
58        private AbstractPie createPie(final HashMap<String, Double> timeSums,
59                        final double sum) {
60                AbstractPie p = instantiatePie(((StateSensor) samInformation.getSensor())
61                                .getSensorName());
62                DecimalFormat df = new DecimalFormat("#0.0", new DecimalFormatSymbols(
63                                Locale.US));
64                for (Entry<String, Double> e : timeSums.entrySet()) {
65                        if (e.getValue() > 0.0) {
66                                p
67                                                .addEntity(new PieEntity(e.getValue(), e.getKey()
68                                                                + " ("
69                                                                + df
70                                                                                .format(e.getValue() * FACTOR_PERCENT
71                                                                                                / sum) + "%)"));
72                        }
73                }
74                return p;
75        }
76 
77        /**
78         * Calculates the fractions of the pie chart to create.
79         * 
80         * @param fractions
81         *            the fractions to calculate
82         * @return the sum of all fractions
83         */
84        protected abstract double calculateFractions(
85                        final HashMap<String, Double> fractions);
86 
87        /**
88         * Instantiates a Pie object.
89         * 
90         * @param sensorName
91         *            the sensor name
92         * @return the Pie object
93         */
94        protected abstract AbstractPie instantiatePie(String sensorName);
95}

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