EMMA Coverage Report (generated Tue May 01 18:46:53 CEST 2007)
[all classes][dk.deepthought.sidious.services]

COVERAGE SUMMARY FOR SOURCE FILE [ServiceEngine.java]

nameclass, %method, %block, %line, %
ServiceEngine.java100% (1/1)71%  (5/7)62%  (65/104)74%  (17/23)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class ServiceEngine100% (1/1)71%  (5/7)62%  (65/104)74%  (17/23)
ServiceEngine (): void 0%   (0/1)0%   (0/3)0%   (0/1)
reset (): void 0%   (0/1)0%   (0/5)0%   (0/2)
getSensorValue (SuperLinkID): double 100% (1/1)60%  (47/78)79%  (11/14)
<static initializer> 100% (1/1)100% (8/8)100% (2/2)
getCurrentState (): State 100% (1/1)100% (5/5)100% (1/1)
getEnvironmentSensors (): Collection 100% (1/1)100% (2/2)100% (1/1)
setSensorList (Collection): void 100% (1/1)100% (3/3)100% (2/2)

1package dk.deepthought.sidious.services;
2 
3import java.util.ArrayList;
4import java.util.Collection;
5 
6import org.apache.commons.logging.Log;
7import org.apache.commons.logging.LogFactory;
8 
9import dk.deepthought.sidious.greenhouse.ClimaticState;
10import dk.deepthought.sidious.greenhouse.SensorInput;
11import dk.deepthought.sidious.supportsystem.State;
12import dk.deepthought.sidious.supportsystem.SuperLinkID;
13 
14/**
15 * This class handles interaction with environment. It implements convenience
16 * methods for handling of sensors.
17 * 
18 * @author Deepthought
19 * 
20 */
21public class ServiceEngine {
22 
23        /**
24         * All the sensors in the environment.
25         */
26        private static Collection<SensorInput> sensorList = new ArrayList<SensorInput>();
27 
28        /**
29         * Logger for this class
30         */
31        private static final Log logger = LogFactory.getLog(ServiceEngine.class);
32 
33 
34        /**
35         * Returns a snapshot of the sensors and their current setting in the
36         * system.
37         * 
38         * @return the sensors of the system
39         */
40        private synchronized static Collection<SensorInput> getEnvironmentSensors() {
41                return sensorList;
42        }
43 
44        /**
45         * Method returns the current state of the system.
46         * 
47         * @return the current state
48         */
49        public static State getCurrentState() {
50                return new ClimaticState(getEnvironmentSensors());
51        }
52 
53        /**
54         * Method returns the value of the sensor associated with the given
55         * <code>id</code>.
56         * 
57         * @param id
58         *            the id of the sensor
59         * @return the value of the sensor
60         */
61        public static double getSensorValue(SuperLinkID id) {
62                if (id == null) {
63                        throw new IllegalArgumentException("null not valid id");
64                }
65                if (logger.isDebugEnabled()) {
66                        logger.debug("getSensorValue(SuperLinkID id=" + id + ") - start");
67                }
68                Collection<SensorInput> sensors = getEnvironmentSensors();
69                for (SensorInput input : sensors) {
70                        if (input.getID().equals(id)) {
71                                double returndouble = input.getValue();
72                                if (logger.isDebugEnabled()) {
73                                        logger.debug("getSensorValue(SuperLinkID id=" + id
74                                                        + ") - end - return value=" + returndouble);
75                                }
76                                return returndouble;
77                        }
78                }
79                logger.error("getSensorValue(SuperLinkID id=" + id
80                                + ") - end - return value=" + Double.NaN);
81                return Double.NaN;
82        }
83 
84        /**
85         * @param sensorList
86         *            the sensorList to set
87         */
88        public synchronized static void setSensorList(
89                        Collection<SensorInput> sensorList) {
90                ServiceEngine.sensorList = sensorList;
91        }
92 
93        /**
94         * Resets the service engine.
95         */
96        public static void reset() {
97                sensorList = new ArrayList<SensorInput>();
98        }
99 
100}

[all classes][dk.deepthought.sidious.services]
EMMA 2.0.5312 (C) Vladimir Roubtsov