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.*;
5
6
7
8
9
10
11
12
13
14
15 public class SensorsContainerQueued extends HashMap<String, Map<String, Queue<SuperSensor>>>
16 {
17
18
19
20
21
22
23
24 public List<SuperSensor> getSensorsByType(String type)
25 {
26 if(this.isEmpty() || type == null)
27 {
28 return null;
29 }
30 if(this.containsKey(type))
31 {
32 List<SuperSensor> allAvailible = new ArrayList<SuperSensor>();
33 for(String string : this.get(type).keySet())
34 {
35 allAvailible.addAll(this.get(type).get(string));
36 this.get(type).get(string).clear();
37 }
38 return allAvailible;
39 }
40 return null;
41 }
42
43
44
45
46
47
48
49
50
51 public List<SuperSensor> getSensorsBySensorType(SensorType type)
52 {
53 if(this.isEmpty() || type == null)
54 {
55 return null;
56 }
57 List<SuperSensor> allAvailible = new ArrayList<SuperSensor>();
58 for(Map<String, Queue<SuperSensor>> map : this.values())
59 {
60 if(map == null || map.isEmpty())
61 {
62 continue;
63 }
64 for(String string : map.keySet())
65 {
66 if(map.get(string).isEmpty())
67 {
68 continue;
69 }
70 if(map.get(string).peek().getSensorType() == type)
71 {
72 allAvailible.addAll(map.get(string));
73 map.get(string).clear();
74 }
75 }
76 }
77 return allAvailible;
78 }
79
80
81
82
83
84
85
86
87
88
89 public List<SuperSensor> getSensorsByClass(Class c)
90 {
91 if(c == null)
92 {
93 return null;
94 }
95 List<SuperSensor> allAvailible = new ArrayList<SuperSensor>();
96 for(Map<String, Queue<SuperSensor>> map : this.values())
97 {
98 for(Queue<SuperSensor> queue : map.values())
99 {
100 if(queue.isEmpty())
101 {
102 continue;
103 }
104 if(c.isInstance(queue.peek()))
105 {
106 allAvailible.addAll(queue);
107 queue.clear();
108 }
109 }
110 }
111 return allAvailible;
112 }
113
114
115
116
117
118
119
120
121
122 public List<SuperSensor> getSensorByTypeName(String type, String name)
123 {
124 if(this.isEmpty())
125 {
126 return null;
127 }
128 if(this.containsKey(type) && !this.get(type).isEmpty())
129 {
130 List<SuperSensor> allAvailible = new ArrayList<SuperSensor>();
131 allAvailible.addAll(this.get(type).get(name));
132 this.get(type).get(name).clear();
133 }
134 return null;
135 }
136
137
138
139
140
141
142
143
144 public List<MessageDescriptor> getNonEmptyDescription()
145 {
146 if(this.isEmpty())
147 {
148 return null;
149 }
150 List<MessageDescriptor> list = new ArrayList<MessageDescriptor>();
151 for(String type : this.keySet())
152 {
153 for(String name : this.get(type).keySet())
154 {
155 list.add(new MessageDescriptor(type, name));
156 }
157 }
158 return list;
159 }
160
161
162
163
164
165
166
167
168
169
170 public boolean isReady(SensorType type)
171 {
172 if(this.isEmpty())
173 {
174 return false;
175 }
176 for(Map<String, Queue<SuperSensor>> map : this.values())
177 {
178 if(map == null || map.isEmpty())
179 {
180 continue;
181 }
182 for(String string : map.keySet())
183 {
184 if(map.get(string).isEmpty())
185 {
186 continue;
187 }
188 if(map.get(string).peek().getSensorType() == type)
189 {
190 return true;
191 }
192 }
193 }
194 return false;
195 }
196 }