1 | package de.uka.ipd.sdq.pipesandfilters.framework.recorder.sensorframework; |
2 | |
3 | import de.uka.ipd.sdq.sensorframework.entities.Experiment; |
4 | import de.uka.ipd.sdq.sensorframework.entities.Sensor; |
5 | import de.uka.ipd.sdq.sensorframework.entities.State; |
6 | import de.uka.ipd.sdq.sensorframework.entities.StateSensor; |
7 | import de.uka.ipd.sdq.sensorframework.entities.TimeSpanSensor; |
8 | import de.uka.ipd.sdq.sensorframework.entities.dao.IDAOFactory; |
9 | import de.uka.ipd.sdq.sensorframework.entities.dao.ISensorDAO; |
10 | import de.uka.ipd.sdq.sensorframework.entities.dao.IStateDAO; |
11 | |
12 | public class SensorHelper { |
13 | public static StateSensor createOrReuseStateSensor(IDAOFactory f, Experiment experiment, String id, State initialState) { |
14 | ISensorDAO sensorDAO = f.createSensorDAO(); |
15 | if (sensorDAO.findBySensorName(id).size() > 0) { |
16 | for (Sensor s : sensorDAO.findBySensorName(id)) { |
17 | if (s instanceof StateSensor && experiment.getSensors().contains(s)) |
18 | return (StateSensor) s; |
19 | } |
20 | } |
21 | return experiment.addStateSensor(initialState,id); |
22 | } |
23 | |
24 | public static State createOrReuseState(IDAOFactory f, String id) { |
25 | IStateDAO stateDAO = f.createStateDAO(); |
26 | if (stateDAO.findByStateLiteral(id).size() == 1) { |
27 | return stateDAO.findByStateLiteral(id).iterator().next(); |
28 | } |
29 | return stateDAO.addState(id); |
30 | } |
31 | |
32 | |
33 | public static TimeSpanSensor createOrReuseTimeSensor( |
34 | IDAOFactory f, Experiment experimentDatastore, String id) { |
35 | ISensorDAO sensorDAO = f.createSensorDAO(); |
36 | if (sensorDAO.findBySensorName(id).size() > 0) { |
37 | for (Sensor s : sensorDAO.findBySensorName(id)) { |
38 | if (s instanceof TimeSpanSensor && experimentDatastore.getSensors().contains(s)) |
39 | return (TimeSpanSensor) s; |
40 | } |
41 | } |
42 | return experimentDatastore.addTimeSpanSensor(id); |
43 | } |
44 | } |