1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package net.wotonomy.foundation;
20
21 import java.util.Enumeration;
22 import java.util.Map;
23
24 /***
25 * A pure java implementation of NSMutableDictionary that
26 * implements Map for greater java interoperability.
27 *
28 * @author michael@mpowers.net
29 * @author $Author: cgruber $
30 * @version $Revision: 893 $
31 */
32 public class NSMutableDictionary
33 extends NSDictionary
34 {
35 /***
36 * Default constructor produces an empty dictionary.
37 */
38 public NSMutableDictionary ()
39 {
40 super();
41 }
42
43 /***
44 * Default constructor produces an empty dictionary.
45 */
46 public NSMutableDictionary (int initialSize)
47 {
48 super(initialSize);
49 }
50
51 /***
52 * Produces a dictionary that contains one key referencing one value.
53 */
54 public NSMutableDictionary (Object key, Object value)
55 {
56 super( key, value );
57 }
58
59 /***
60 * Produces a dictionary containing the specified keys and values.
61 * An IllegalArgumentException is thrown if the arrays are not
62 * of the same length.
63 */
64 public NSMutableDictionary (Object[] keys, Object[] values)
65 {
66 super( keys, values );
67 }
68
69 /***
70 * Produces a dictionary that is a copy of the specified map (or dictionary).
71 */
72 public NSMutableDictionary (Map aMap)
73 {
74 super( aMap );
75 }
76
77 /***
78 * Removes the key-value pair for the specified key.
79 */
80 public void removeObjectForKey (Object aKey)
81 {
82 remove( aKey );
83 }
84
85 /***
86 * Copies all mappings from the specified dictionary to this dictionary,
87 * replacing any mappings this map had for any keys in the specified map.
88 */
89 public void addEntriesFromDictionary (Map aMap)
90 {
91 putAll( aMap );
92 }
93
94 /***
95 * Removes all mappings from this dictionary.
96 */
97 public void removeAllObjects ()
98 {
99 clear();
100 }
101
102 /***
103 * Removes all keys in the specified array from this dictionary.
104 */
105 public void removeObjectsForKeys (NSArray anArray)
106 {
107 Enumeration enumeration = anArray.objectEnumerator();
108 while ( enumeration.hasMoreElements() )
109 {
110 removeObjectForKey( enumeration.nextElement() );
111 }
112 }
113
114 /***
115 * Clears all mappings in this dictionary and then adds all entries
116 * in the specified dictionary.
117 */
118 public void setDictionary (Map aMap)
119 {
120 removeAllObjects();
121 addEntriesFromDictionary( aMap );
122 }
123
124 /***
125 * Sets the value for the specified key. If the key currently
126 * exists to the dictionary, the old value is replaced with the
127 * specified value. An IllegalArgumentException is thrown if
128 * either the key or value is null.
129 */
130 public void setObjectForKey (Object aValue, Object aKey)
131 {
132 if ( ( aKey == null ) || ( aValue == null ) )
133 {
134 throw new IllegalArgumentException(
135 "Cannot use null objects with an NSMutableDictionary." );
136 }
137 put( aKey, aValue );
138 }
139 }
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166