1 package cz.cuni.amis.pogamut.usar2004.agent.module.datatypes;
2
3 import cz.cuni.amis.pogamut.usar2004.agent.module.sensor.SuperSensor;
4 import java.util.ArrayList;
5 import java.util.HashMap;
6 import java.util.List;
7 import java.util.Map;
8
9
10
11
12
13
14
15
16
17
18 public class SensorsContainer extends HashMap<String, Map<String, SuperSensor>>
19 {
20
21
22
23
24
25
26
27 public List<SuperSensor> getSensorsByType(String type)
28 {
29 if(this.isEmpty() || type == null)
30 {
31 return null;
32 }
33 if(this.containsKey(type))
34 {
35 return new ArrayList<SuperSensor>(this.get(type).values());
36 }
37 return null;
38 }
39
40
41
42
43
44
45
46
47
48 public List<SuperSensor> getSensorsBySensorType(SensorType type)
49 {
50 if(this.isEmpty() || type == null)
51 {
52 return null;
53 }
54 List<SuperSensor> list = new ArrayList<SuperSensor>();
55 for(Map<String, SuperSensor> map : this.values())
56 {
57 if(map == null || map.isEmpty())
58 {
59 continue;
60 }
61 if(map.values().iterator().next().getSensorType() == type)
62 {
63 list.addAll(map.values());
64 }
65 }
66 return list;
67 }
68
69
70
71
72
73
74
75
76
77
78 public List<SuperSensor> getSensorsByClass(Class c)
79 {
80 if(c == null)
81 {
82 return null;
83 }
84 List<SuperSensor> list = new ArrayList<SuperSensor>();
85 for(Map<String, SuperSensor> map : this.values())
86 {
87 for(SuperSensor sensor : map.values())
88 {
89 if(c.isInstance(sensor))
90 {
91 list.add(sensor);
92 }
93 }
94 }
95 return list;
96 }
97
98
99
100
101
102
103
104
105
106 public SuperSensor getSensorByTypeName(String type, String name)
107 {
108 if(this.isEmpty())
109 {
110 return null;
111 }
112 if(this.containsKey(type) && !this.get(type).isEmpty())
113 {
114 return this.get(type).get(name);
115 }
116 return null;
117 }
118
119
120
121
122
123
124
125
126 public List<MessageDescriptor> getNonEmptyDescription()
127 {
128 if(this.isEmpty())
129 {
130 return null;
131 }
132 List<MessageDescriptor> list = new ArrayList<MessageDescriptor>();
133 for(String type : this.keySet())
134 {
135 for(String name : this.get(type).keySet())
136 {
137 list.add(new MessageDescriptor(type, name));
138 }
139 }
140 return list;
141 }
142 }