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.FileManager; |
11 | import de.uka.ipd.sdq.sensorframework.entities.ExperimentRun; |
12 | import de.uka.ipd.sdq.sensorframework.entities.Measurement; |
13 | import de.uka.ipd.sdq.sensorframework.entities.Sensor; |
14 | import de.uka.ipd.sdq.sensorframework.storage.lists.BackgroundMemoryList; |
15 | import de.uka.ipd.sdq.sensorframework.storage.lists.DoubleSerialiser; |
16 | |
17 | /** |
18 | * @author Ihssane El-Oudghiri |
19 | * @author Steffen Becker |
20 | * |
21 | */ |
22 | public class TimeSpanSensorAndMeasurement extends AbstractSensorAndMeasurements { |
23 | |
24 | private static final long serialVersionUID = 3516448762554779531L; |
25 | private BackgroundMemoryList<Double> timeSpans; |
26 | |
27 | public TimeSpanSensorAndMeasurement(FileManager fm, ExperimentRun er, Sensor sensor) throws IOException { |
28 | super(fm, er, sensor); |
29 | timeSpans = new BackgroundMemoryList<Double>(getMeasurementsFileName(),new DoubleSerialiser()); |
30 | fm.addOpenList(timeSpans); |
31 | } |
32 | |
33 | public synchronized void addTimeSpan(double et, double ts) { |
34 | eventTimes.add(et); |
35 | timeSpans.add(ts); |
36 | } |
37 | |
38 | @Override |
39 | public boolean equals(Object obj) { |
40 | if (!(obj instanceof TimeSpanSensorAndMeasurement)) |
41 | return false; |
42 | TimeSpanSensorAndMeasurement sam = (TimeSpanSensorAndMeasurement) obj; |
43 | |
44 | return super.equals(obj) && equalTimeSpans(this,sam); |
45 | } |
46 | |
47 | private boolean equalTimeSpans( |
48 | TimeSpanSensorAndMeasurement sam1, |
49 | TimeSpanSensorAndMeasurement sam2) { |
50 | if (sam1.timeSpans.size() == sam2.timeSpans.size()) { |
51 | for (int i=0; i<sam1.timeSpans.size(); i++){ |
52 | if (sam1.timeSpans.get(i) != sam2.timeSpans.get(i)) |
53 | return false; |
54 | } |
55 | return true; |
56 | } else { |
57 | return false; |
58 | } |
59 | } |
60 | |
61 | @Override |
62 | public synchronized List<Measurement> getMeasurements() { |
63 | return new TimeSpanMeasurementListWithBackgroundStore(eventTimes, timeSpans); |
64 | } |
65 | |
66 | @Override |
67 | public void store() { |
68 | super.store(); |
69 | try { |
70 | timeSpans.flush(); |
71 | } catch (IOException e) { |
72 | throw new RuntimeException(e); |
73 | } |
74 | } |
75 | |
76 | } |