EMMA Coverage Report (generated Sun Feb 05 10:43:15 CET 2012)
[all classes][de.uka.ipd.sdq.sensorframework.dao.memory]

COVERAGE SUMMARY FOR SOURCE FILE [MemorySensorDAO.java]

nameclass, %method, %block, %line, %
MemorySensorDAO.java100% (1/1)30%  (3/10)38%  (73/190)40%  (16/40)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class MemorySensorDAO100% (1/1)30%  (3/10)38%  (73/190)40%  (16/40)
addScalabilitySensor (String): ScalabilitySensor 0%   (0/1)0%   (0/28)0%   (0/5)
findBySensorName (String): Collection 0%   (0/1)0%   (0/29)0%   (0/5)
get (long): Sensor 0%   (0/1)0%   (0/18)0%   (0/3)
getSensors (): Collection 0%   (0/1)0%   (0/5)0%   (0/1)
removeSensor (Sensor, boolean): void 0%   (0/1)0%   (0/35)0%   (0/8)
store (Sensor): void 0%   (0/1)0%   (0/1)0%   (0/1)
storeAll (): void 0%   (0/1)0%   (0/1)0%   (0/1)
MemorySensorDAO (IDAOFactory): void 100% (1/1)100% (14/14)100% (5/5)
addStateSensor (State, String): StateSensor 100% (1/1)100% (31/31)100% (6/6)
addTimeSpanSensor (String): TimeSpanSensor 100% (1/1)100% (28/28)100% (5/5)

1package de.uka.ipd.sdq.sensorframework.dao.memory;
2 
3import java.util.ArrayList;
4import java.util.Collection;
5import java.util.Collections;
6import java.util.HashMap;
7 
8import de.uka.ipd.sdq.sensorframework.entities.ScalabilitySensor;
9import de.uka.ipd.sdq.sensorframework.entities.Sensor;
10import de.uka.ipd.sdq.sensorframework.entities.State;
11import de.uka.ipd.sdq.sensorframework.entities.StateSensor;
12import de.uka.ipd.sdq.sensorframework.entities.TimeSpanSensor;
13import de.uka.ipd.sdq.sensorframework.entities.dao.IDAOFactory;
14import de.uka.ipd.sdq.sensorframework.entities.dao.ISensorDAO;
15import de.uka.ipd.sdq.sensorframework.entities.impl.ScalabilitySensorImpl;
16import de.uka.ipd.sdq.sensorframework.entities.impl.StateSensorImpl;
17import de.uka.ipd.sdq.sensorframework.entities.impl.TimeSpanSensorImpl;
18 
19/**
20 * TODO
21 *
22 */
23public class MemorySensorDAO implements ISensorDAO {
24 
25        private IDAOFactory myFactory;
26        private long nextID = 0;
27        private HashMap<Long,Sensor> index = new HashMap<Long,Sensor>();
28        
29        public MemorySensorDAO(IDAOFactory memoryDAOFactory) {
30                this.myFactory = memoryDAOFactory;
31        }
32 
33        public synchronized StateSensor addStateSensor(State p_initialstate, String p_sensorname) {
34                StateSensor result = new StateSensorImpl(myFactory);
35                result.setSensorID(nextID++);
36                result.setInitialState(p_initialstate);
37                result.setSensorName(p_sensorname);
38 
39                index.put(result.getSensorID(), result);
40                return result;
41        }
42 
43        public synchronized TimeSpanSensor addTimeSpanSensor(String p_sensorname) {
44                TimeSpanSensor result = new TimeSpanSensorImpl(myFactory);
45                result.setSensorID(nextID++);
46                result.setSensorName(p_sensorname);
47                
48                index.put(result.getSensorID(), result);
49                return result;
50        }
51        
52        public synchronized ScalabilitySensor addScalabilitySensor(String p_sensorname) {
53                ScalabilitySensor result = new ScalabilitySensorImpl(myFactory);
54                result.setSensorID(nextID++);
55                result.setSensorName(p_sensorname);
56                
57                index.put(result.getSensorID(), result);
58                return result;
59        }
60 
61        public synchronized Sensor get(long id) {
62                if (!index.containsKey(id))
63                        throw new RuntimeException("Attempt to retrieve non-existing sensor.");
64                return index.get(id);
65        }
66 
67        public synchronized Collection<Sensor> getSensors() {
68                return Collections.unmodifiableCollection(index.values());
69        }
70 
71        public synchronized Collection<Sensor> findBySensorName(String searchKey) {
72                ArrayList<Sensor> result = new ArrayList<Sensor>();
73                for (Sensor e:this.index.values()){
74                        if (e.getSensorName().equals(searchKey))
75                                result.add(e);
76                }
77                return Collections.unmodifiableCollection(result);
78        }
79 
80        public synchronized void removeSensor(Sensor sensor, boolean doCascade) {
81                if (sensor == null) {
82                        return;
83                }
84                
85                if ( doCascade == true ) {
86                        if (sensor instanceof StateSensor) {
87                                //remove the states
88                                for (State state: ((StateSensor)sensor).getSensorStates()) {
89                                        myFactory.createStateDAO().removeState(state, true);
90                                }
91                        }
92                }
93                
94                index.remove(sensor.getSensorID());
95        }
96 
97        public void store(Sensor s) {
98        }
99        
100        public void storeAll() {
101                // Nothing to do here
102        }
103        
104}

[all classes][de.uka.ipd.sdq.sensorframework.dao.memory]
EMMA 2.0.9414 (unsupported private build) (C) Vladimir Roubtsov