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