1 | /** |
2 | * |
3 | */ |
4 | package de.uka.ipd.sdq.sensorframework.dao.file.entities; |
5 | |
6 | import java.io.IOException; |
7 | import java.util.ArrayList; |
8 | import java.util.List; |
9 | |
10 | import de.uka.ipd.sdq.sensorframework.dao.file.FileDAOFactory; |
11 | import de.uka.ipd.sdq.sensorframework.dao.file.FileManager; |
12 | import de.uka.ipd.sdq.sensorframework.entities.ExperimentRun; |
13 | import de.uka.ipd.sdq.sensorframework.entities.Measurement; |
14 | import de.uka.ipd.sdq.sensorframework.entities.Sensor; |
15 | import de.uka.ipd.sdq.sensorframework.entities.State; |
16 | import de.uka.ipd.sdq.sensorframework.entities.StateSensor; |
17 | import de.uka.ipd.sdq.sensorframework.storage.lists.BackgroundMemoryList; |
18 | |
19 | /** |
20 | * @author Ihssane El-Oudghiri |
21 | */ |
22 | public class StateSensorAndMeasurement extends AbstractSensorAndMeasurements { |
23 | |
24 | private static final long serialVersionUID = -7553464522648015852L; |
25 | private BackgroundMemoryList<State> states; |
26 | |
27 | public StateSensorAndMeasurement(FileManager fm, ExperimentRun er, Sensor sensor) throws IOException { |
28 | super(fm, er, sensor); |
29 | states = new BackgroundMemoryList<State>(getMeasurementsFileName(),new StateSerializer((StateSensor) sensor)); |
30 | fm.addOpenList(states); |
31 | } |
32 | |
33 | public void addState(double et, State state) { |
34 | eventTimes.add(et); |
35 | states.add(state); |
36 | } |
37 | |
38 | @Override |
39 | public boolean equals(Object obj) { |
40 | if (!(obj instanceof StateSensorAndMeasurement)) |
41 | return false; |
42 | StateSensorAndMeasurement sam = (StateSensorAndMeasurement) obj; |
43 | return (super.equals(obj)) && (getStates().equals(sam.getStates())); |
44 | } |
45 | |
46 | @Override |
47 | public List<Measurement> getMeasurements() { |
48 | return new StateMeasurementListWithBackgroundStore(eventTimes, states); |
49 | } |
50 | |
51 | public List<State> getStates() { |
52 | return states; |
53 | } |
54 | |
55 | public void serializeChildren() { |
56 | // Nothing to serialize here |
57 | } |
58 | |
59 | public void setFactory(FileDAOFactory factory) { |
60 | } |
61 | |
62 | @Override |
63 | public void store() { |
64 | super.store(); |
65 | try { |
66 | states.flush(); |
67 | } catch (IOException e) { |
68 | throw new RuntimeException(e); |
69 | } |
70 | } |
71 | |
72 | } |