1 package fr.ove.openmath.courses;
2
3 import java.util.Hashtable;
4 import java.util.Enumeration;
5 import fr.ove.openmath.OpenMathizable;
6 /***
7 * This class to register the pair element name / value (it is a hashtable)
8 * and indicates if all the registrations have been done.
9 */
10 public class CheckedRegistry {
11 private Hashtable hashtable;
12
13 /***
14 * The constructor.
15 */
16 public CheckedRegistry() {
17 hashtable = new Hashtable();
18 }
19
20 /***
21 * Adds an element in the registery.
22 * @param id the identifier.
23 * @param omizable the object to identify.
24 * @param arg the argument number.
25 */
26 public void add(String id, OpenMathizable omizable, String arg) {
27
28 System.out.println("On ajoute [" + id + ", "+ arg +"]");
29
30 hashtable.put(id, new Association(arg, omizable));
31 }
32
33 /***
34 * Removes the specified element form the registery.
35 * @param id the elment to remove.
36 */
37 public void remove(String id) {
38 hashtable.remove(id);
39 }
40
41 /***
42 * Set the value of the specified element.
43 * @param id the identifier.
44 * @param omizable the object to identify.
45 */
46 public void setOMizable(String id, OpenMathizable omizable) {
47 Association pair = (Association) hashtable.get(id);
48 if (pair != null)
49 pair.omizable = omizable;
50 }
51
52
53 /***
54 * Returns <CODE>true</CODE> if each key has a non-null associated value.
55 * <CODE>false</CODE> otherwise.
56 */
57 public boolean gotAll() {
58 boolean gotAll = true;
59 Association pair;
60 for (Enumeration e = hashtable.elements(); e.hasMoreElements(); ) {
61 pair = (Association) e.nextElement();
62 if (pair.omizable == null)
63 return false;
64 }
65 return gotAll;
66 }
67
68 /***
69 * Returns the argument name of the element with the specified identifier.
70 * @param id the spcified identifier.
71 */
72 public String getArg(String id) {
73 Association pair = (Association) hashtable.get(id);
74
75 if (pair != null)
76 return pair.arg;
77 else
78 return null;
79 }
80
81
82
83
84 /***
85 * Association of an identifier and the object it identifies.
86 */
87 private class Association {
88 /***
89 * The identifier.
90 */
91 public String arg;
92
93 /****
94 * The object to identify.
95 */
96 public OpenMathizable omizable;
97
98 /***
99 * The constructor.
100 * @param arg the identifier.
101 * @param the object to identify.
102 */
103 public Association(String arg, OpenMathizable omizable) {
104 this.arg = arg;
105 this.omizable = omizable;
106 }
107 }
108 }