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