1 | /** |
2 | * |
3 | */ |
4 | package de.uka.ipd.sdq.sensorframework.dao.file.entities; |
5 | |
6 | import java.util.ArrayList; |
7 | import java.util.Collection; |
8 | import java.util.Collections; |
9 | |
10 | import de.uka.ipd.sdq.sensorframework.dao.file.FileDAOFactory; |
11 | import de.uka.ipd.sdq.sensorframework.entities.Experiment; |
12 | import de.uka.ipd.sdq.sensorframework.entities.ExperimentRun; |
13 | import de.uka.ipd.sdq.sensorframework.entities.ScalabilitySensor; |
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.entities.TimeSpanSensor; |
18 | import de.uka.ipd.sdq.sensorframework.entities.dao.IDAOFactory; |
19 | |
20 | /** |
21 | * @author Ihssane El-Oudghiri |
22 | * |
23 | */ |
24 | public class ExperimentImpl extends AbstractFileEntity implements Experiment, SerializableEntity { |
25 | |
26 | /** |
27 | * Serialisation ID |
28 | */ |
29 | private static final long serialVersionUID = 2145970711062278629L; |
30 | |
31 | /** |
32 | * ID of this Experiment |
33 | */ |
34 | private long experimentID; |
35 | |
36 | /** |
37 | * Name of this experiment |
38 | */ |
39 | private String experimentName; |
40 | |
41 | /** |
42 | * Collection of IDs of sensors in this experiment. |
43 | */ |
44 | private Collection<Long> sensors; |
45 | |
46 | /** |
47 | * Collection of IDs of ExperimentRuns of this experiment. |
48 | */ |
49 | private Collection<Long> experimentRuns; |
50 | |
51 | public ExperimentImpl(IDAOFactory factory) { |
52 | super(factory); |
53 | sensors = new ArrayList<Long>(); |
54 | experimentRuns = new ArrayList<Long>(); |
55 | } |
56 | |
57 | public void addExperimentRun(ExperimentRun experimentRun) { |
58 | experimentRuns.add(experimentRun.getExperimentRunID()); |
59 | } |
60 | |
61 | public ExperimentRun addExperimentRun(String experimentdatetime) { |
62 | ExperimentRun expRun = factory.createExperimentRunDAO() |
63 | .addExperimentRun(experimentdatetime); |
64 | experimentRuns.add(expRun.getExperimentRunID()); |
65 | ((ExperimentRunImpl)expRun).setParentExperimentID(this.getID()); |
66 | |
67 | return expRun; |
68 | } |
69 | |
70 | public ExperimentRun addScalabilityExperimentRun(String experimentdatetime) { |
71 | ExperimentRun expRun = factory.createExperimentRunDAO() |
72 | .addScalabilityExperimentRun(experimentdatetime); |
73 | experimentRuns.add(expRun.getExperimentRunID()); |
74 | ((ExperimentRunImpl)expRun).setParentExperimentID(this.getID()); |
75 | |
76 | return expRun; |
77 | } |
78 | |
79 | public ScalabilitySensor addScalabilitySensor(String sensorName) { |
80 | ScalabilitySensor scals = factory.createSensorDAO().addScalabilitySensor( |
81 | sensorName); |
82 | sensors.add(scals.getSensorID()); |
83 | return scals; |
84 | } |
85 | |
86 | public void addSensor(Sensor value) { |
87 | sensors.add(value.getSensorID()); |
88 | } |
89 | |
90 | public StateSensor addStateSensor(State p_initialstate, String p_sensorname) { |
91 | StateSensor stsen = factory.createSensorDAO().addStateSensor( |
92 | p_initialstate, p_sensorname); |
93 | sensors.add(stsen.getSensorID()); |
94 | return stsen; |
95 | } |
96 | |
97 | public TimeSpanSensor addTimeSpanSensor(String sensorName) { |
98 | TimeSpanSensor tss = factory.createSensorDAO().addTimeSpanSensor( |
99 | sensorName); |
100 | sensors.add(tss.getSensorID()); |
101 | return tss; |
102 | } |
103 | |
104 | @Override |
105 | public boolean equals(Object obj) { |
106 | if (!(obj instanceof ExperimentImpl)) |
107 | return false; |
108 | ExperimentImpl exp = (ExperimentImpl) obj; |
109 | |
110 | if (!(experimentID == exp.getExperimentID() && experimentName |
111 | .equals(exp.getExperimentName()))) |
112 | return false; |
113 | |
114 | if (!(experimentRuns.equals(exp.getExperimentRuns()))) |
115 | return false; |
116 | |
117 | if (!(sensors.equals(exp.getSensors()))) |
118 | return false; |
119 | |
120 | return true; |
121 | } |
122 | |
123 | public long getExperimentID() { |
124 | return experimentID; |
125 | } |
126 | |
127 | public String getExperimentName() { |
128 | return experimentName; |
129 | } |
130 | |
131 | public Collection<ExperimentRun> getExperimentRuns() { |
132 | ArrayList<ExperimentRun> result = new ArrayList<ExperimentRun>(); |
133 | for (Long id : experimentRuns) { |
134 | result.add(factory.createExperimentRunDAO().get(id)); |
135 | } |
136 | return Collections.unmodifiableCollection(result); |
137 | } |
138 | |
139 | |
140 | public String getFileName() { |
141 | return FileDAOFactory.EXP_FILE_NAME_PREFIX + getExperimentID(); |
142 | } |
143 | |
144 | public long getID() { |
145 | return this.getExperimentID(); |
146 | } |
147 | |
148 | /* |
149 | * (non-Javadoc) |
150 | * |
151 | * @see de.uka.ipd.sdq.sensorframework.entities.Experiment#getSensors() |
152 | */ |
153 | public Collection<Sensor> getSensors() { |
154 | ArrayList<Sensor> result = new ArrayList<Sensor>(); |
155 | for (Long id : sensors) { |
156 | result.add(factory.createSensorDAO().get(id)); |
157 | } |
158 | return Collections.unmodifiableCollection(result); |
159 | } |
160 | |
161 | public void setExperimentID(long experimentID) { |
162 | this.experimentID = experimentID; |
163 | } |
164 | |
165 | public void setExperimentName(String experimentName) { |
166 | this.experimentName = experimentName; |
167 | } |
168 | |
169 | public void setFactory(FileDAOFactory factory) { |
170 | this.factory = factory; |
171 | } |
172 | |
173 | } |