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.State; |
12 | import de.uka.ipd.sdq.sensorframework.entities.StateSensor; |
13 | |
14 | /** |
15 | * @author Ihssane El-Oudghiri |
16 | * @author Steffen Becker |
17 | */ |
18 | public class StateSensorImpl extends SensorImpl implements StateSensor { |
19 | |
20 | private static final long serialVersionUID = -1981199624361875277L; |
21 | private Long initialStateID; |
22 | private ArrayList<Long> sensorStateIDs; |
23 | |
24 | public StateSensorImpl(FileDAOFactory factory) { |
25 | super(factory); |
26 | sensorStateIDs = new ArrayList<Long>(); |
27 | } |
28 | |
29 | public void addSensorState(State value) { |
30 | sensorStateIDs.add(value.getStateID()); |
31 | } |
32 | |
33 | public State addState(String p_stateliteral) { |
34 | State state = factory.createStateDAO().addState(p_stateliteral); |
35 | sensorStateIDs.add(state.getStateID()); |
36 | return state; |
37 | } |
38 | |
39 | @Override |
40 | public boolean equals(Object obj) { |
41 | if (!(obj instanceof StateSensorImpl)) |
42 | return false; |
43 | StateSensorImpl s = (StateSensorImpl) obj; |
44 | if (!(sensorID == s.getSensorID() && sensorName.equals(s |
45 | .getSensorName()))) |
46 | return false; |
47 | |
48 | return true; |
49 | } |
50 | |
51 | public State getInitialState() { |
52 | return factory.createStateDAO().get(initialStateID); |
53 | } |
54 | |
55 | public Collection<State> getSensorStates() { |
56 | ArrayList<State> result = new ArrayList<State>(); |
57 | for (Long id : this.sensorStateIDs) { |
58 | result.add(factory.createStateDAO().get(id)); |
59 | } |
60 | return Collections.unmodifiableCollection(result); |
61 | } |
62 | |
63 | public void setInitialState(State value) { |
64 | this.initialStateID = value.getStateID(); |
65 | } |
66 | |
67 | } |