Révision 3067
tmp/org.txm.analec.rcp/src/visuAnalec/donnees/Structure.java (revision 3067) | ||
---|---|---|
13 | 13 |
* @author Bernard |
14 | 14 |
*/ |
15 | 15 |
public class Structure implements Serializable { |
16 |
public final static String FORME = "#forme#"; |
|
17 |
private HashMap<Class<? extends Element>, HashSet<String>> types = |
|
18 |
new HashMap<Class<? extends Element>, HashSet<String>>(); |
|
19 |
private HashMap<Class<? extends Element>, HashMap<String, HashSet<String>>> nomsProps = |
|
20 |
new HashMap<Class<? extends Element>, HashMap<String, HashSet<String>>>(); |
|
21 |
private HashMap<Class<? extends Element>, HashMap<String, HashMap<String, HashSet<String>>>> valeursProps = |
|
22 |
new HashMap<Class<? extends Element>, HashMap<String, HashMap<String, HashSet<String>>>>(); |
|
23 |
private HashMap<Class<? extends Element>, HashMap<String, HashMap<String, String>>> valeursParDefaut = |
|
24 |
new HashMap<Class<? extends Element>, HashMap<String, HashMap<String, String>>>(); |
|
25 |
|
|
26 |
@SuppressWarnings("unchecked") |
|
27 |
public Structure() { |
|
28 |
for (Class<? extends Element> classe : new Class[]{Unite.class, Relation.class, Schema.class}) { |
|
29 |
types.put(classe, new HashSet<String>()); |
|
30 |
nomsProps.put(classe, new HashMap<String, HashSet<String>>()); |
|
31 |
valeursProps.put(classe, new HashMap<String, HashMap<String, HashSet<String>>>()); |
|
32 |
valeursParDefaut.put(classe, new HashMap<String, HashMap<String, String>>()); |
|
33 |
} |
|
34 |
} |
|
35 |
|
|
36 |
public HashSet<String> getSchemas() { |
|
37 |
return this.getTypes(Schema.class); |
|
38 |
} |
|
39 |
|
|
40 |
public HashSet<String> getRelations() { |
|
41 |
return this.getTypes(Relation.class); |
|
42 |
} |
|
43 |
|
|
44 |
public HashSet<String> getUnites() { |
|
45 |
return this.getTypes(Unite.class); |
|
46 |
} |
|
47 |
|
|
48 |
public HashSet<String> getSchemaProperties(String schema_type) { |
|
49 |
return getNomsProps(Schema.class, schema_type); |
|
50 |
} |
|
51 |
|
|
52 |
public HashSet<String> getUniteProperties(String schema_type) { |
|
53 |
return getNomsProps(Unite.class, schema_type); |
|
54 |
} |
|
55 |
|
|
56 |
public HashSet<String> getRelationProperties(String schema_type) { |
|
57 |
return getNomsProps(Relation.class, schema_type); |
|
58 |
} |
|
59 |
|
|
60 |
@Override |
|
61 |
public String toString() { |
|
62 |
String dump = "STRUCTURE :"; |
|
63 |
dump += "\n\tUNITES : "; |
|
64 |
dump += "\n\t\tTYPES : "; |
|
65 |
for (String type : types.get(Unite.class)) { |
|
66 |
dump += type+"; "; |
|
67 |
} |
|
68 |
dump += "\n\t\tNOMSPROP : "; |
|
69 |
for (String type : nomsProps.get(Unite.class).keySet()) { |
|
70 |
dump += "\n\t\t\t"+type+" : "; |
|
71 |
for (String prop : nomsProps.get(Unite.class).get(type)) { |
|
72 |
dump += prop+"; "; |
|
73 |
} |
|
74 |
} |
|
75 |
dump += "\n\t\tVALEURSPROP : "; |
|
76 |
for (String type : valeursProps.get(Unite.class).keySet()) { |
|
77 |
dump += "\n\t\t\t"+type+" : "; |
|
78 |
for (String prop : valeursProps.get(Unite.class).get(type).keySet()) { |
|
79 |
dump += "\n\t\t\t\t"+prop+" : "; |
|
80 |
for (String val : valeursProps.get(Unite.class).get(type).get(prop)) { |
|
81 |
dump += val+"; "; |
|
82 |
} |
|
83 |
} |
|
84 |
} |
|
85 |
|
|
86 |
dump += "\n\tRELATIONS : "; |
|
87 |
dump += "\n\t\tTYPES : "; |
|
88 |
for (String type : types.get(Relation.class)) { |
|
89 |
dump += type+"; "; |
|
90 |
} |
|
91 |
dump += "\n\t\tNOMSPROP : "; |
|
92 |
for (String type : nomsProps.get(Relation.class).keySet()) { |
|
93 |
dump += "\n\t\t\t"+type+" : "; |
|
94 |
for (String prop : nomsProps.get(Relation.class).get(type)) { |
|
95 |
dump += prop+"; "; |
|
96 |
} |
|
97 |
} |
|
98 |
dump += "\n\t\tVALEURSPROP : "; |
|
99 |
for (String type : valeursProps.get(Relation.class).keySet()) { |
|
100 |
dump += "\n\t\t\t"+type+" : "; |
|
101 |
for (String prop : valeursProps.get(Relation.class).get(type).keySet()) { |
|
102 |
dump += "\n\t\t\t\t"+prop+" : "; |
|
103 |
for (String val : valeursProps.get(Relation.class).get(type).get(prop)) { |
|
104 |
dump += val+"; "; |
|
105 |
} |
|
106 |
} |
|
107 |
} |
|
108 |
|
|
109 |
dump += "\n\tSCHEMAS : "; |
|
110 |
dump += "\n\t\tTYPES : "; |
|
111 |
for (String type : types.get(Schema.class)) { |
|
112 |
dump += type+"; "; |
|
113 |
} |
|
114 |
dump += "\n\t\tNOMSPROP : "; |
|
115 |
for (String type : nomsProps.get(Schema.class).keySet()) { |
|
116 |
dump += "\n\t\t\t"+type+" : "; |
|
117 |
for (String prop : nomsProps.get(Schema.class).get(type)) { |
|
118 |
dump += prop+"; "; |
|
119 |
} |
|
120 |
} |
|
121 |
dump += "\n\t\tVALEURSPROP : "; |
|
122 |
for (String type : valeursProps.get(Schema.class).keySet()) { |
|
123 |
dump += "\n\t\t\t"+type+" : "; |
|
124 |
for (String prop : valeursProps.get(Schema.class).get(type).keySet()) { |
|
125 |
dump += "\n\t\t\t\t"+prop+" : "; |
|
126 |
for (String val : valeursProps.get(Schema.class).get(type).get(prop)) { |
|
127 |
dump += val+"; "; |
|
128 |
} |
|
129 |
} |
|
130 |
} |
|
131 |
|
|
132 |
|
|
133 |
return dump; |
|
134 |
} |
|
135 |
|
|
136 |
public HashSet<String> getNomsProps(Class<? extends Element> classe, String type) { |
|
137 |
if (nomsProps.get(classe).containsKey(type)) { |
|
138 |
return nomsProps.get(classe).get(type); |
|
139 |
} |
|
140 |
return new HashSet<String>(); |
|
141 |
} |
|
142 |
|
|
143 |
public HashSet<String> getValeursProp(Class<? extends Element> classe, String type, String prop) { |
|
144 |
if (valeursProps.get(classe).containsKey(type)&&valeursProps.get(classe).get(type).containsKey(prop)) { |
|
145 |
return (valeursProps.get(classe).get(type).get(prop)); |
|
146 |
} |
|
147 |
return new HashSet<String>(); |
|
148 |
} |
|
149 |
|
|
150 |
public String getValeurParDefaut(Class<? extends Element> classe, String type, String prop) { |
|
151 |
if (valeursParDefaut.get(classe).containsKey(type)&&valeursParDefaut.get(classe).get(type).containsKey(prop)) { |
|
152 |
return (valeursParDefaut.get(classe).get(type).get(prop)); |
|
153 |
} |
|
154 |
return ""; |
|
155 |
} |
|
156 |
|
|
157 |
public HashSet<String> getTypes(Class<? extends Element> classe) { |
|
158 |
return (types.get(classe)); |
|
159 |
} |
|
160 |
|
|
161 |
public boolean isVide() { |
|
162 |
for (Class<? extends Element> classe : new Class[]{Unite.class, Relation.class, Schema.class}) { |
|
163 |
if (!types.get(classe).isEmpty()) return false; |
|
164 |
} |
|
165 |
return true; |
|
166 |
} |
|
167 |
|
|
168 |
void clear() { |
|
169 |
for (Class<? extends Element> classe : new Class[]{Unite.class, Relation.class, Schema.class}) { |
|
170 |
types.get(classe).clear(); |
|
171 |
nomsProps.get(classe).clear(); |
|
172 |
valeursProps.get(classe).clear(); |
|
173 |
valeursParDefaut.get(classe).clear(); |
|
174 |
} |
|
175 |
} |
|
176 |
|
|
177 |
public void ajouterVal(Class<? extends Element> classe, String type, String prop, String val) { |
|
178 |
valeursProps.get(classe).get(type).get(prop).add(val); |
|
179 |
} |
|
180 |
|
|
181 |
void renommerVal(Class<? extends Element> classe, String type, String prop, String oldNom, String newNom) { |
|
182 |
valeursProps.get(classe).get(type).get(prop).add(newNom); |
|
183 |
valeursProps.get(classe).get(type).get(prop).remove(oldNom); |
|
184 |
if (oldNom.equals(valeursParDefaut.get(classe).get(type).get(prop))) { |
|
185 |
valeursParDefaut.get(classe).get(type).put(prop, newNom); |
|
186 |
} |
|
187 |
} |
|
188 |
|
|
189 |
void supprimerVal(Class<? extends Element> classe, String type, String prop, String oldNom) { |
|
190 |
valeursProps.get(classe).get(type).get(prop).remove(oldNom); |
|
191 |
if (oldNom.equals(valeursParDefaut.get(classe).get(type).get(prop))) { |
|
192 |
valeursParDefaut.get(classe).get(type).put(prop, ""); |
|
193 |
} |
|
194 |
} |
|
195 |
|
|
196 |
public void modifierValParDefaut(Class<? extends Element> classe, String type, String prop, String val) { |
|
197 |
valeursParDefaut.get(classe).get(type).put(prop, val); |
|
198 |
} |
|
199 |
|
|
200 |
public void ajouterProp(Class<? extends Element> classe, String type, String prop) { |
|
201 |
nomsProps.get(classe).get(type).add(prop); |
|
202 |
valeursProps.get(classe).get(type).put(prop, new HashSet<String>()); |
|
203 |
valeursParDefaut.get(classe).get(type).put(prop, ""); |
|
204 |
} |
|
205 |
|
|
206 |
void renommerProp(Class<? extends Element> classe, String type, String oldNom, String newNom) { |
|
207 |
nomsProps.get(classe).get(type).add(newNom); |
|
208 |
nomsProps.get(classe).get(type).remove(oldNom); |
|
209 |
valeursProps.get(classe).get(type).put(newNom, valeursProps.get(classe).get(type).get(oldNom)); |
|
210 |
valeursProps.get(classe).get(type).remove(oldNom); |
|
211 |
valeursParDefaut.get(classe).get(type).put(newNom, valeursParDefaut.get(classe).get(type).get(oldNom)); |
|
212 |
valeursParDefaut.get(classe).get(type).remove(oldNom); |
|
213 |
} |
|
214 |
|
|
215 |
void fusionnerProp(Class<? extends Element> classe, String type, String oldNom, String newNom) { |
|
216 |
nomsProps.get(classe).get(type).remove(oldNom); |
|
217 |
valeursProps.get(classe).get(type).get(newNom).addAll(valeursProps.get(classe).get(type).get(oldNom)); |
|
218 |
valeursProps.get(classe).get(type).remove(oldNom); |
|
219 |
if (!valeursParDefaut.get(classe).get(type).get(oldNom).isEmpty()) { |
|
220 |
valeursParDefaut.get(classe).get(type).put(newNom, valeursParDefaut.get(classe).get(type).get(oldNom)); |
|
221 |
} |
|
222 |
valeursParDefaut.get(classe).get(type).remove(oldNom); |
|
223 |
} |
|
224 |
|
|
225 |
void supprimerProp(Class<? extends Element> classe, String type, String prop) { |
|
226 |
nomsProps.get(classe).get(type).remove(prop); |
|
227 |
valeursProps.get(classe).get(type).remove(prop); |
|
228 |
valeursParDefaut.get(classe).get(type).remove(prop); |
|
229 |
} |
|
230 |
|
|
231 |
@SuppressWarnings("unchecked") |
|
232 |
public void ajouterType(Class<? extends Element> classe, String type) { |
|
233 |
types.get(classe).add(type); |
|
234 |
nomsProps.get(classe).put(type, new HashSet<String>()); |
|
235 |
valeursProps.get(classe).put(type, new HashMap<String, HashSet<String>>()); |
|
236 |
valeursParDefaut.get(classe).put(type, new HashMap<String, String>()); |
|
237 |
} |
|
238 |
// } |
|
239 |
|
|
240 |
void renommerType(Class<? extends Element> classe, String oldType, String newType) { |
|
241 |
types.get(classe).add(newType); |
|
242 |
types.get(classe).remove(oldType); |
|
243 |
nomsProps.get(classe).put(newType, nomsProps.get(classe).get(oldType)); |
|
244 |
nomsProps.get(classe).remove(oldType); |
|
245 |
valeursProps.get(classe).put(newType, valeursProps.get(classe).get(oldType)); |
|
246 |
valeursProps.get(classe).remove(oldType); |
|
247 |
valeursParDefaut.get(classe).put(newType, valeursParDefaut.get(classe).get(oldType)); |
|
248 |
valeursParDefaut.get(classe).remove(oldType); |
|
249 |
} |
|
250 |
|
|
251 |
void fusionnerType(Class<? extends Element> classe, String oldType, String newType) { |
|
252 |
types.get(classe).remove(oldType); |
|
253 |
for (String prop : nomsProps.get(classe).get(oldType)) { |
|
254 |
if (!nomsProps.get(classe).get(newType).contains(prop)) |
|
255 |
ajouterProp(classe, newType, prop); |
|
256 |
for (String val : valeursProps.get(classe).get(oldType).get(prop)) |
|
257 |
if (!valeursProps.get(classe).get(newType).get(prop).contains(val)) |
|
258 |
ajouterVal(classe, newType, prop, val); |
|
259 |
String valdef1 = getValeurParDefaut(classe, oldType, prop); |
|
260 |
String valdef = getValeurParDefaut(classe, newType, prop); |
|
261 |
if (!valdef1.isEmpty()&&!valdef1.equals(valdef)) { |
|
262 |
modifierValParDefaut(classe, newType, prop, valdef1); |
|
263 |
} |
|
264 |
} |
|
265 |
nomsProps.get(classe).remove(oldType); |
|
266 |
valeursProps.get(classe).remove(oldType); |
|
267 |
valeursParDefaut.get(classe).remove(oldType); |
|
268 |
|
|
269 |
} |
|
270 |
|
|
271 |
void supprimerType(Class<? extends Element> classe, String type) { |
|
272 |
types.get(classe).remove(type); |
|
273 |
nomsProps.get(classe).remove(type); |
|
274 |
valeursProps.get(classe).remove(type); |
|
275 |
valeursParDefaut.get(classe).remove(type); |
|
276 |
} |
|
277 |
|
|
278 |
void majNewElement(Element element) { // appelé par corpus.addUniteLue, addRelationLue, addSchemaLu |
|
279 |
String type = element.getType(); |
|
280 |
Class<? extends Element> classe = element.getClass(); |
|
281 |
if (!types.get(classe).contains(type)) { |
|
282 |
ajouterType(classe, type); |
|
283 |
} |
|
284 |
HashMap<String, String> props = element.getProps(); |
|
285 |
for (String prop : props.keySet()) { |
|
286 |
if (!nomsProps.get(classe).get(type).contains(prop)) { |
|
287 |
ajouterProp(classe, type, prop); |
|
288 |
} |
|
289 |
String val = props.get(prop); |
|
290 |
if (val!=null&&!val.isEmpty()&&!valeursProps.get(classe).get(type).get(prop).contains(val)) { |
|
291 |
ajouterVal(classe, type, prop, val); |
|
292 |
} |
|
293 |
} |
|
294 |
} |
|
295 |
|
|
296 |
@SuppressWarnings("unchecked") |
|
297 |
public static Structure lireJava(ObjectInputStream ois) throws IOException, ClassNotFoundException { |
|
298 |
Structure structure = new Structure(); |
|
299 |
structure.types = (HashMap<Class<? extends Element>, HashSet<String>>) ois.readObject(); |
|
300 |
structure.nomsProps = (HashMap<Class<? extends Element>, HashMap<String, HashSet<String>>>) ois.readObject(); |
|
301 |
structure.valeursProps = (HashMap<Class<? extends Element>, HashMap<String, HashMap<String, HashSet<String>>>>) ois.readObject(); |
|
302 |
structure.valeursParDefaut = (HashMap<Class<? extends Element>, HashMap<String, HashMap<String, String>>>) ois.readObject(); |
|
303 |
return structure; |
|
304 |
} |
|
305 |
|
|
306 |
public void ecrireJava(ObjectOutputStream oos) throws IOException { |
|
307 |
oos.writeObject(types); |
|
308 |
oos.writeObject(nomsProps); |
|
309 |
oos.writeObject(valeursProps); |
|
310 |
oos.writeObject(valeursParDefaut); |
|
311 |
} |
|
16 |
|
|
17 |
public final static String FORME = "#forme#"; |
|
18 |
|
|
19 |
private HashMap<Class<? extends Element>, HashSet<String>> types = new HashMap<>(); |
|
20 |
|
|
21 |
private HashMap<Class<? extends Element>, HashMap<String, HashSet<String>>> nomsProps = new HashMap<>(); |
|
22 |
|
|
23 |
private HashMap<Class<? extends Element>, HashMap<String, HashMap<String, HashSet<String>>>> valeursProps = new HashMap<>(); |
|
24 |
|
|
25 |
private HashMap<Class<? extends Element>, HashMap<String, HashMap<String, String>>> valeursParDefaut = new HashMap<>(); |
|
26 |
|
|
27 |
@SuppressWarnings("unchecked") |
|
28 |
public Structure() { |
|
29 |
for (Class<? extends Element> classe : new Class[] { Unite.class, Relation.class, Schema.class }) { |
|
30 |
types.put(classe, new HashSet<String>()); |
|
31 |
nomsProps.put(classe, new HashMap<String, HashSet<String>>()); |
|
32 |
valeursProps.put(classe, new HashMap<String, HashMap<String, HashSet<String>>>()); |
|
33 |
valeursParDefaut.put(classe, new HashMap<String, HashMap<String, String>>()); |
|
34 |
} |
|
35 |
} |
|
36 |
|
|
37 |
public HashSet<String> getSchemas() { |
|
38 |
return this.getTypes(Schema.class); |
|
39 |
} |
|
40 |
|
|
41 |
public HashSet<String> getRelations() { |
|
42 |
return this.getTypes(Relation.class); |
|
43 |
} |
|
44 |
|
|
45 |
public HashSet<String> getUnites() { |
|
46 |
return this.getTypes(Unite.class); |
|
47 |
} |
|
48 |
|
|
49 |
public HashSet<String> getSchemaProperties(String schema_type) { |
|
50 |
return getNomsProps(Schema.class, schema_type); |
|
51 |
} |
|
52 |
|
|
53 |
public HashSet<String> getUniteProperties(String schema_type) { |
|
54 |
return getNomsProps(Unite.class, schema_type); |
|
55 |
} |
|
56 |
|
|
57 |
public HashSet<String> getRelationProperties(String schema_type) { |
|
58 |
return getNomsProps(Relation.class, schema_type); |
|
59 |
} |
|
60 |
|
|
61 |
@Override |
|
62 |
public String toString() { |
|
63 |
String dump = "STRUCTURE :"; |
|
64 |
dump += "\n\tUNITES : "; |
|
65 |
dump += "\n\t\tTYPES : "; |
|
66 |
for (String type : types.get(Unite.class)) { |
|
67 |
dump += type + "; "; |
|
68 |
} |
|
69 |
dump += "\n\t\tNOMSPROP : "; |
|
70 |
for (String type : nomsProps.get(Unite.class).keySet()) { |
|
71 |
dump += "\n\t\t\t" + type + " : "; |
|
72 |
for (String prop : nomsProps.get(Unite.class).get(type)) { |
|
73 |
dump += prop + "; "; |
|
74 |
} |
|
75 |
} |
|
76 |
dump += "\n\t\tVALEURSPROP : "; |
|
77 |
for (String type : valeursProps.get(Unite.class).keySet()) { |
|
78 |
dump += "\n\t\t\t" + type + " : "; |
|
79 |
for (String prop : valeursProps.get(Unite.class).get(type).keySet()) { |
|
80 |
dump += "\n\t\t\t\t" + prop + " : "; |
|
81 |
for (String val : valeursProps.get(Unite.class).get(type).get(prop)) { |
|
82 |
dump += val + "; "; |
|
83 |
} |
|
84 |
} |
|
85 |
} |
|
86 |
|
|
87 |
dump += "\n\tRELATIONS : "; |
|
88 |
dump += "\n\t\tTYPES : "; |
|
89 |
for (String type : types.get(Relation.class)) { |
|
90 |
dump += type + "; "; |
|
91 |
} |
|
92 |
dump += "\n\t\tNOMSPROP : "; |
|
93 |
for (String type : nomsProps.get(Relation.class).keySet()) { |
|
94 |
dump += "\n\t\t\t" + type + " : "; |
|
95 |
for (String prop : nomsProps.get(Relation.class).get(type)) { |
|
96 |
dump += prop + "; "; |
|
97 |
} |
|
98 |
} |
|
99 |
dump += "\n\t\tVALEURSPROP : "; |
|
100 |
for (String type : valeursProps.get(Relation.class).keySet()) { |
|
101 |
dump += "\n\t\t\t" + type + " : "; |
|
102 |
for (String prop : valeursProps.get(Relation.class).get(type).keySet()) { |
|
103 |
dump += "\n\t\t\t\t" + prop + " : "; |
|
104 |
for (String val : valeursProps.get(Relation.class).get(type).get(prop)) { |
|
105 |
dump += val + "; "; |
|
106 |
} |
|
107 |
} |
|
108 |
} |
|
109 |
|
|
110 |
dump += "\n\tSCHEMAS : "; |
|
111 |
dump += "\n\t\tTYPES : "; |
|
112 |
for (String type : types.get(Schema.class)) { |
|
113 |
dump += type + "; "; |
|
114 |
} |
|
115 |
dump += "\n\t\tNOMSPROP : "; |
|
116 |
for (String type : nomsProps.get(Schema.class).keySet()) { |
|
117 |
dump += "\n\t\t\t" + type + " : "; |
|
118 |
for (String prop : nomsProps.get(Schema.class).get(type)) { |
|
119 |
dump += prop + "; "; |
|
120 |
} |
|
121 |
} |
|
122 |
dump += "\n\t\tVALEURSPROP : "; |
|
123 |
for (String type : valeursProps.get(Schema.class).keySet()) { |
|
124 |
dump += "\n\t\t\t" + type + " : "; |
|
125 |
for (String prop : valeursProps.get(Schema.class).get(type).keySet()) { |
|
126 |
dump += "\n\t\t\t\t" + prop + " : "; |
|
127 |
for (String val : valeursProps.get(Schema.class).get(type).get(prop)) { |
|
128 |
dump += val + "; "; |
|
129 |
} |
|
130 |
} |
|
131 |
} |
|
132 |
|
|
133 |
|
|
134 |
return dump; |
|
135 |
} |
|
136 |
|
|
137 |
public HashSet<String> getNomsProps(Class<? extends Element> classe, String type) { |
|
138 |
if (nomsProps.get(classe).containsKey(type)) { |
|
139 |
return nomsProps.get(classe).get(type); |
|
140 |
} |
|
141 |
return new HashSet<>(); |
|
142 |
} |
|
143 |
|
|
144 |
public HashSet<String> getValeursProp(Class<? extends Element> classe, String type, String prop) { |
|
145 |
if (valeursProps.get(classe).containsKey(type) && valeursProps.get(classe).get(type).containsKey(prop)) { |
|
146 |
return (valeursProps.get(classe).get(type).get(prop)); |
|
147 |
} |
|
148 |
return new HashSet<>(); |
|
149 |
} |
|
150 |
|
|
151 |
public String getValeurParDefaut(Class<? extends Element> classe, String type, String prop) { |
|
152 |
if (valeursParDefaut.get(classe).containsKey(type) && valeursParDefaut.get(classe).get(type).containsKey(prop)) { |
|
153 |
return (valeursParDefaut.get(classe).get(type).get(prop)); |
|
154 |
} |
|
155 |
return ""; |
|
156 |
} |
|
157 |
|
|
158 |
public HashSet<String> getTypes(Class<? extends Element> classe) { |
|
159 |
return (types.get(classe)); |
|
160 |
} |
|
161 |
|
|
162 |
public boolean isVide() { |
|
163 |
for (Class<? extends Element> classe : new Class[] { Unite.class, Relation.class, Schema.class }) { |
|
164 |
if (!types.get(classe).isEmpty()) return false; |
|
165 |
} |
|
166 |
return true; |
|
167 |
} |
|
168 |
|
|
169 |
void clear() { |
|
170 |
for (Class<? extends Element> classe : new Class[] { Unite.class, Relation.class, Schema.class }) { |
|
171 |
types.get(classe).clear(); |
|
172 |
nomsProps.get(classe).clear(); |
|
173 |
valeursProps.get(classe).clear(); |
|
174 |
valeursParDefaut.get(classe).clear(); |
|
175 |
} |
|
176 |
} |
|
177 |
|
|
178 |
public void ajouterVal(Class<? extends Element> classe, String type, String prop, String val) { |
|
179 |
valeursProps.get(classe).get(type).get(prop).add(val); |
|
180 |
} |
|
181 |
|
|
182 |
void renommerVal(Class<? extends Element> classe, String type, String prop, String oldNom, String newNom) { |
|
183 |
valeursProps.get(classe).get(type).get(prop).add(newNom); |
|
184 |
valeursProps.get(classe).get(type).get(prop).remove(oldNom); |
|
185 |
if (oldNom.equals(valeursParDefaut.get(classe).get(type).get(prop))) { |
|
186 |
valeursParDefaut.get(classe).get(type).put(prop, newNom); |
|
187 |
} |
|
188 |
} |
|
189 |
|
|
190 |
void supprimerVal(Class<? extends Element> classe, String type, String prop, String oldNom) { |
|
191 |
valeursProps.get(classe).get(type).get(prop).remove(oldNom); |
|
192 |
if (oldNom.equals(valeursParDefaut.get(classe).get(type).get(prop))) { |
|
193 |
valeursParDefaut.get(classe).get(type).put(prop, ""); |
|
194 |
} |
|
195 |
} |
|
196 |
|
|
197 |
public void modifierValParDefaut(Class<? extends Element> classe, String type, String prop, String val) { |
|
198 |
valeursParDefaut.get(classe).get(type).put(prop, val); |
|
199 |
} |
|
200 |
|
|
201 |
public void ajouterProp(Class<? extends Element> classe, String type, String prop) { |
|
202 |
nomsProps.get(classe).get(type).add(prop); |
|
203 |
valeursProps.get(classe).get(type).put(prop, new HashSet<String>()); |
|
204 |
valeursParDefaut.get(classe).get(type).put(prop, ""); |
|
205 |
} |
|
206 |
|
|
207 |
void renommerProp(Class<? extends Element> classe, String type, String oldNom, String newNom) { |
|
208 |
nomsProps.get(classe).get(type).add(newNom); |
|
209 |
nomsProps.get(classe).get(type).remove(oldNom); |
|
210 |
valeursProps.get(classe).get(type).put(newNom, valeursProps.get(classe).get(type).get(oldNom)); |
|
211 |
valeursProps.get(classe).get(type).remove(oldNom); |
|
212 |
valeursParDefaut.get(classe).get(type).put(newNom, valeursParDefaut.get(classe).get(type).get(oldNom)); |
|
213 |
valeursParDefaut.get(classe).get(type).remove(oldNom); |
|
214 |
} |
|
215 |
|
|
216 |
void fusionnerProp(Class<? extends Element> classe, String type, String oldNom, String newNom) { |
|
217 |
nomsProps.get(classe).get(type).remove(oldNom); |
|
218 |
if (!valeursProps.get(classe).containsKey(type)) { |
|
219 |
ajouterType(classe, type); |
|
220 |
} |
|
221 |
if (!valeursProps.get(classe).get(type).containsKey(newNom)) { |
|
222 |
ajouterProp(classe, type, newNom); |
|
223 |
} |
|
224 |
valeursProps.get(classe).get(type).get(newNom).addAll(valeursProps.get(classe).get(type).get(oldNom)); |
|
225 |
valeursProps.get(classe).get(type).remove(oldNom); |
|
226 |
if (!valeursParDefaut.get(classe).get(type).get(oldNom).isEmpty()) { |
|
227 |
valeursParDefaut.get(classe).get(type).put(newNom, valeursParDefaut.get(classe).get(type).get(oldNom)); |
|
228 |
} |
|
229 |
valeursParDefaut.get(classe).get(type).remove(oldNom); |
|
230 |
} |
|
231 |
|
|
232 |
void supprimerProp(Class<? extends Element> classe, String type, String prop) { |
|
233 |
nomsProps.get(classe).get(type).remove(prop); |
|
234 |
valeursProps.get(classe).get(type).remove(prop); |
|
235 |
valeursParDefaut.get(classe).get(type).remove(prop); |
|
236 |
} |
|
237 |
|
|
238 |
@SuppressWarnings("unchecked") |
|
239 |
public void ajouterType(Class<? extends Element> classe, String type) { |
|
240 |
types.get(classe).add(type); |
|
241 |
nomsProps.get(classe).put(type, new HashSet<String>()); |
|
242 |
valeursProps.get(classe).put(type, new HashMap<String, HashSet<String>>()); |
|
243 |
valeursParDefaut.get(classe).put(type, new HashMap<String, String>()); |
|
244 |
} |
|
245 |
// } |
|
246 |
|
|
247 |
void renommerType(Class<? extends Element> classe, String oldType, String newType) { |
|
248 |
types.get(classe).add(newType); |
|
249 |
types.get(classe).remove(oldType); |
|
250 |
nomsProps.get(classe).put(newType, nomsProps.get(classe).get(oldType)); |
|
251 |
nomsProps.get(classe).remove(oldType); |
|
252 |
valeursProps.get(classe).put(newType, valeursProps.get(classe).get(oldType)); |
|
253 |
valeursProps.get(classe).remove(oldType); |
|
254 |
valeursParDefaut.get(classe).put(newType, valeursParDefaut.get(classe).get(oldType)); |
|
255 |
valeursParDefaut.get(classe).remove(oldType); |
|
256 |
} |
|
257 |
|
|
258 |
void fusionnerType(Class<? extends Element> classe, String oldType, String newType) { |
|
259 |
types.get(classe).remove(oldType); |
|
260 |
for (String prop : nomsProps.get(classe).get(oldType)) { |
|
261 |
if (!nomsProps.get(classe).get(newType).contains(prop)) |
|
262 |
ajouterProp(classe, newType, prop); |
|
263 |
for (String val : valeursProps.get(classe).get(oldType).get(prop)) |
|
264 |
if (!valeursProps.get(classe).get(newType).get(prop).contains(val)) |
|
265 |
ajouterVal(classe, newType, prop, val); |
|
266 |
String valdef1 = getValeurParDefaut(classe, oldType, prop); |
|
267 |
String valdef = getValeurParDefaut(classe, newType, prop); |
|
268 |
if (!valdef1.isEmpty() && !valdef1.equals(valdef)) { |
|
269 |
modifierValParDefaut(classe, newType, prop, valdef1); |
|
270 |
} |
|
271 |
} |
|
272 |
nomsProps.get(classe).remove(oldType); |
|
273 |
valeursProps.get(classe).remove(oldType); |
|
274 |
valeursParDefaut.get(classe).remove(oldType); |
|
275 |
|
|
276 |
} |
|
277 |
|
|
278 |
void supprimerType(Class<? extends Element> classe, String type) { |
|
279 |
types.get(classe).remove(type); |
|
280 |
nomsProps.get(classe).remove(type); |
|
281 |
valeursProps.get(classe).remove(type); |
|
282 |
valeursParDefaut.get(classe).remove(type); |
|
283 |
} |
|
284 |
|
|
285 |
void majNewElement(Element element) { // appelé par corpus.addUniteLue, addRelationLue, addSchemaLu |
|
286 |
String type = element.getType(); |
|
287 |
Class<? extends Element> classe = element.getClass(); |
|
288 |
if (!types.get(classe).contains(type)) { |
|
289 |
ajouterType(classe, type); |
|
290 |
} |
|
291 |
HashMap<String, String> props = element.getProps(); |
|
292 |
for (String prop : props.keySet()) { |
|
293 |
if (!nomsProps.get(classe).get(type).contains(prop)) { |
|
294 |
ajouterProp(classe, type, prop); |
|
295 |
} |
|
296 |
String val = props.get(prop); |
|
297 |
if (val != null && !val.isEmpty() && !valeursProps.get(classe).get(type).get(prop).contains(val)) { |
|
298 |
ajouterVal(classe, type, prop, val); |
|
299 |
} |
|
300 |
} |
|
301 |
} |
|
302 |
|
|
303 |
@SuppressWarnings("unchecked") |
|
304 |
public static Structure lireJava(ObjectInputStream ois) throws IOException, ClassNotFoundException { |
|
305 |
Structure structure = new Structure(); |
|
306 |
structure.types = (HashMap<Class<? extends Element>, HashSet<String>>) ois.readObject(); |
|
307 |
structure.nomsProps = (HashMap<Class<? extends Element>, HashMap<String, HashSet<String>>>) ois.readObject(); |
|
308 |
structure.valeursProps = (HashMap<Class<? extends Element>, HashMap<String, HashMap<String, HashSet<String>>>>) ois.readObject(); |
|
309 |
structure.valeursParDefaut = (HashMap<Class<? extends Element>, HashMap<String, HashMap<String, String>>>) ois.readObject(); |
|
310 |
return structure; |
|
311 |
} |
|
312 |
|
|
313 |
public void ecrireJava(ObjectOutputStream oos) throws IOException { |
|
314 |
oos.writeObject(types); |
|
315 |
oos.writeObject(nomsProps); |
|
316 |
oos.writeObject(valeursProps); |
|
317 |
oos.writeObject(valeursParDefaut); |
|
318 |
} |
|
312 | 319 |
} |
Formats disponibles : Unified diff