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

COVERAGE SUMMARY FOR SOURCE FILE [ExperimentRunImpl.java]

nameclass, %method, %block, %line, %
ExperimentRunImpl.java100% (1/1)72%  (13/18)53%  (144/272)58%  (37/64)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class ExperimentRunImpl100% (1/1)72%  (13/18)53%  (144/272)58%  (37/64)
addMeasurement (Measurement): void 0%   (0/1)0%   (0/4)0%   (0/1)
addScalabilityMeasurement (ScalabilitySensor, Double [], double): Scalability... 0%   (0/1)0%   (0/11)0%   (0/3)
equals (Object): boolean 0%   (0/1)0%   (0/24)0%   (0/7)
getMeasurements (): Collection 0%   (0/1)0%   (0/26)0%   (0/4)
setParentExperimentID (long): void 0%   (0/1)0%   (0/4)0%   (0/2)
createMeasurementStorage (Sensor): AbstractSensorAndMeasurements 100% (1/1)53%  (40/76)50%  (7/14)
addStateMeasurement (StateSensor, State, double): StateMeasurement 100% (1/1)58%  (15/26)80%  (4/5)
getMeasurementsOfSensor (Sensor): SensorAndMeasurements 100% (1/1)59%  (17/29)60%  (3/5)
ExperimentRunImpl (IDAOFactory): void 100% (1/1)100% (9/9)100% (3/3)
addTimeSpanMeasurement (TimeSpanSensor, double, double): TimeSpanMeasurement 100% (1/1)100% (11/11)100% (3/3)
getExperimentDateTime (): String 100% (1/1)100% (3/3)100% (1/1)
getExperimentRunID (): long 100% (1/1)100% (3/3)100% (1/1)
getID (): long 100% (1/1)100% (3/3)100% (1/1)
getParentExperiment (): Experiment 100% (1/1)100% (7/7)100% (1/1)
saveGetSensorAndMeasurements (Sensor): AbstractSensorAndMeasurements 100% (1/1)100% (16/16)100% (5/5)
setExperimentDateTime (String): void 100% (1/1)100% (4/4)100% (2/2)
setExperimentRunID (long): void 100% (1/1)100% (4/4)100% (2/2)
setFactory (FileDAOFactory): void 100% (1/1)100% (12/12)100% (4/4)

1/**
2 * 
3 */
4package de.uka.ipd.sdq.sensorframework.dao.file.entities;
5 
6import java.io.IOException;
7import java.io.Serializable;
8import java.util.ArrayList;
9import java.util.Collection;
10import java.util.HashMap;
11 
12import de.uka.ipd.sdq.sensorframework.dao.file.FileDAOFactory;
13import de.uka.ipd.sdq.sensorframework.entities.Experiment;
14import de.uka.ipd.sdq.sensorframework.entities.ExperimentRun;
15import de.uka.ipd.sdq.sensorframework.entities.Measurement;
16import de.uka.ipd.sdq.sensorframework.entities.ScalabilityMeasurement;
17import de.uka.ipd.sdq.sensorframework.entities.ScalabilitySensor;
18import de.uka.ipd.sdq.sensorframework.entities.Sensor;
19import de.uka.ipd.sdq.sensorframework.entities.SensorAndMeasurements;
20import de.uka.ipd.sdq.sensorframework.entities.State;
21import de.uka.ipd.sdq.sensorframework.entities.StateMeasurement;
22import de.uka.ipd.sdq.sensorframework.entities.StateSensor;
23import de.uka.ipd.sdq.sensorframework.entities.TimeSpanMeasurement;
24import de.uka.ipd.sdq.sensorframework.entities.TimeSpanSensor;
25import de.uka.ipd.sdq.sensorframework.entities.dao.IDAOFactory;
26 
27/**
28 * Entity implementation for Experiment Runs. Contains BackgroundMemoryLists to quickly store the 
29 * huge amounts of sensor data generated by simulations.
30 * 
31 * @author Ihssane El-Oudghiri 
32 * @author Steffen Becker
33 * 
34 */
35public class ExperimentRunImpl extends AbstractFileEntity implements ExperimentRun, Serializable {
36 
37        private static final long serialVersionUID = 6496657460961660218L;
38        
39        /**
40         * Persistent ID of this entity
41         */
42        private long experimentRunID;
43        
44        /**
45         * Date and Time of the experiment run 
46         */
47        private String experimentDateTime;
48        
49        /**
50         * Contains the measurements and event times for each sensor in this experiment run.
51         * Hashes sensor ID on the sensor's measurements. It is transient as it uses fast 
52         * BackgroundMemoryLists which persist themselves
53         */
54        private transient HashMap<Long, AbstractSensorAndMeasurements> measurementsForSensor;
55        
56        /**
57         * ID of the Experiment of this Experiment Run. Used for internal checks
58         */
59        public long idOfParentExperiment;
60        
61        public ExperimentRunImpl(IDAOFactory factory) {
62                super(factory);
63                measurementsForSensor = new HashMap<Long, AbstractSensorAndMeasurements>();
64        }
65        
66        /* Operation is unsupported as the file provider relies on fast SensorAndMeasurement objects
67         *  (non-Javadoc)
68         * @see de.uka.ipd.sdq.sensorframework.entities.ExperimentRun#addMeasurement(de.uka.ipd.sdq.sensorframework.entities.Measurement)
69         */
70        public void addMeasurement(Measurement value) {
71                throw new UnsupportedOperationException();
72        }
73 
74        public ScalabilityMeasurement addScalabilityMeasurement(ScalabilitySensor p_sensor,
75                        Double[] p_parameters, double p_result) {
76                AbstractSensorAndMeasurements sam = saveGetSensorAndMeasurements(p_sensor);
77                ((ScalabilitySensorAndMeasurement) sam).addResult(p_parameters, p_result);
78 
79                // We do not really have a DAO, hence we do not support returning an measurement entity.
80                // This is uncritical as our caller is also not expecting to get one
81                return null;
82        }
83 
84        public StateMeasurement addStateMeasurement(StateSensor p_sensor,
85                        State p_sensorstate, double p_eventtime) {
86                if (p_sensor == null || p_sensorstate == null)
87                        throw new IllegalArgumentException("p_sensor or p_sensorstate is null, eventtime is " + p_eventtime);
88                
89                AbstractSensorAndMeasurements sam = saveGetSensorAndMeasurements(p_sensor);
90                ((StateSensorAndMeasurement) sam).addState(p_eventtime, p_sensorstate);
91 
92                // We do not really have a DAO, hence we do not support returning an measurement entity.
93                // This is uncritical as our caller is also not expecting to get one
94                return null;
95        }
96 
97        public TimeSpanMeasurement addTimeSpanMeasurement(TimeSpanSensor p_sensor,
98                        double p_eventtime, double p_timespan) {
99                AbstractSensorAndMeasurements sam = saveGetSensorAndMeasurements(p_sensor);
100                ((TimeSpanSensorAndMeasurement) sam).addTimeSpan(p_eventtime, p_timespan);
101 
102                // We do not really have a DAO, hence we do not support returning an measurement entity.
103                // This is uncritical as our caller is also not expecting to get one
104                return null;
105        }
106 
107        private AbstractSensorAndMeasurements createMeasurementStorage(
108                        Sensor sensor) {
109                AbstractSensorAndMeasurements sam = null;
110                try {
111                        if (sensor instanceof TimeSpanSensor)
112                                sam = new TimeSpanSensorAndMeasurement(((FileDAOFactory)factory).getFileManager(),this,sensor);
113                        else if (sensor instanceof StateSensor)
114                                sam = new StateSensorAndMeasurement(((FileDAOFactory)factory).getFileManager(),this,sensor);
115                        else if (sensor instanceof ScalabilitySensor)
116                                sam = new ScalabilitySensorAndMeasurement(((FileDAOFactory)factory).getFileManager(),this,sensor);
117                        else
118                                throw new RuntimeException("Invalid sensor type found: " +
119                                                sensor.getClass()+" is not a TimeSpanSensor, a StateSensor, " +
120                                                                "or a Scalability sensor - fix your implementation, please!");
121                } catch(IOException e) {
122                        throw new RuntimeException(e);
123                }
124                measurementsForSensor.put(sensor.getSensorID(), sam);
125                return sam;
126        }
127 
128        @Override
129        public boolean equals(Object obj) {
130                if (!(obj instanceof ExperimentRunImpl))
131                        return false;
132                ExperimentRunImpl er = (ExperimentRunImpl) obj;
133 
134                if (!(experimentRunID == er.getExperimentRunID() && experimentDateTime
135                                .equals(er.getExperimentDateTime())))
136                        return false;
137                
138                return true;
139        }
140 
141        public String getExperimentDateTime() {
142                return experimentDateTime;
143        }
144        
145        public long getExperimentRunID() {
146                return experimentRunID;
147        }
148 
149        public long getID() {
150                return this.getExperimentRunID();
151        }
152 
153        public Collection<Measurement> getMeasurements() {
154                ArrayList<Measurement> m = new ArrayList<Measurement>();
155 
156                for (Sensor s : getParentExperiment().getSensors()) {
157                        m.addAll(getMeasurementsOfSensor(s).getMeasurements());
158                }
159                return m;
160        }
161 
162        public SensorAndMeasurements getMeasurementsOfSensor(Sensor sensor) {
163                if (!getParentExperiment().getSensors().contains(sensor)) {
164                        throw new IllegalArgumentException("Error: Sensor given is not part of this experiment "
165                                        + sensor.getSensorName());
166                }
167                AbstractSensorAndMeasurements sam = saveGetSensorAndMeasurements(sensor);
168                return new SensorAndMeasurements(sensor, sam.getMeasurements());
169        }
170 
171        private Experiment getParentExperiment() {
172                return factory.createExperimentDAO().get(idOfParentExperiment);
173        }
174 
175        /** Returns the sensor and measurement object to the given sensor - creating it if neccessary
176         * @param sensor The sensor of the SAM
177         * @return The created SAM
178         */
179        private AbstractSensorAndMeasurements saveGetSensorAndMeasurements(
180                        Sensor sensor) {
181                AbstractSensorAndMeasurements sam = measurementsForSensor.get(sensor
182                                .getSensorID());
183                if (sam == null) {
184                        sam = createMeasurementStorage(sensor);
185                }
186                return sam;
187        }
188 
189        public void setExperimentDateTime(String experimetDateTime) {
190                this.experimentDateTime = experimetDateTime;
191        }
192 
193        public void setExperimentRunID(long experimentRunID) {
194                this.experimentRunID = experimentRunID;
195        }
196        
197        @Override
198        public void setFactory(FileDAOFactory factory) {
199                super.setFactory(factory);
200                if (measurementsForSensor == null)
201                        measurementsForSensor = new HashMap<Long, AbstractSensorAndMeasurements>();
202        }
203 
204        public void setParentExperimentID(long id) {
205                this.idOfParentExperiment = id;
206        }
207        
208        
209}

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