|
WebObjects 5.2 | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--com.webobjects.foundation.NSDictionary | +--com.webobjects.foundation.NSMutableDictionary
The NSMutableDictionary class adds methods to insert, modify, and remove elements to the API of its parent class NSDictionary
These methods add each key object directly to the
dictionary, which means that you must ensure that the keys do not
change. If you expect your keys to change for any reason, you should
make copies of the keys and add the copies to the dictionary or otherwise
guarentee that the keys do not change with respect to either the equals
or
hashCode
methods. java.lang.String
objects are immutable
and make good keys
The following table describes NSMutableDictionary methods that provide the basis for all NSMutableDictionary's other methods; that is, all other methods are implemented in terms of these seven. If you create a subclass of NSMutableDictionary, you need only ensure that these base methods work properly. Having done so, you can be sure that all your subclass's inherited methods operate properly.
Method | Description |
count | Returns the number of entries in the dictionary. Inherited from NSDictionary. |
objectForKey | Returns the value associated with a given key. Inherited from NSDictionary. |
keysNoCopy | Returns a natural language array containing the keys in the dictionary. Inherited from NSDictionary. |
objectsNoCopy | Returns a natural language array containing the objects in the dictionary. Inherited from NSDictionary. |
removeAllObjects | Empties the dictionary of its entries. |
removeObjectForKey | Removes the specified key object and its associated value object from the dictionary. |
setObjectForKey | Adds or replaces an entry to the receiver consisting of the specified key and value objects. |
The other methods declared here provide convenient ways of adding or removing multiple entries at a time.
Map
,
HashMap
,
Hashtable
,
NSDictionary.count()
,
NSDictionary.objectForKey(java.lang.Object)
,
setObjectForKey(java.lang.Object, java.lang.Object)
,
removeObjectForKey(java.lang.Object)
,
removeAllObjects()
,
addEntriesFromDictionary(com.webobjects.foundation.NSDictionary)
, Serialized FormInner classes inherited from class com.webobjects.foundation.NSCoding |
NSCoding.Support |
Inner classes inherited from class com.webobjects.foundation.NSKeyValueCoding |
NSKeyValueCoding.DefaultImplementation, NSKeyValueCoding.ErrorHandling, NSKeyValueCoding.Null, NSKeyValueCoding.UnknownKeyException, NSKeyValueCoding.Utility, NSKeyValueCoding.ValueAccessor |
Inner classes inherited from class com.webobjects.foundation.NSKeyValueCodingAdditions |
NSKeyValueCodingAdditions.DefaultImplementation, NSKeyValueCodingAdditions.Utility |
Fields inherited from class com.webobjects.foundation.NSDictionary |
EmptyDictionary |
Fields inherited from interface com.webobjects.foundation.NSKeyValueCoding |
NullValue |
Fields inherited from interface com.webobjects.foundation.NSKeyValueCodingAdditions |
KeyPathSeparator |
Constructor Summary | |
NSMutableDictionary()
Creates an empty NSMutableDictionary. |
|
NSMutableDictionary(Dictionary dictionary,
boolean ignoreNull)
Creates an NSMutableDictionary containing the keys and values found in dictionary . |
|
NSMutableDictionary(int capacity)
Creates an empty NSMutableDictionary prepared to hold at least capacity entries. |
|
NSMutableDictionary(NSArray objects,
NSArray keys)
Creates an NSMutableDictionary with entries from the contents of the keys and objects NSArrays. |
|
NSMutableDictionary(NSDictionary otherDictionary)
Creates a new NSMutableDictionary containing the keys and values found in otherDictionary . |
|
NSMutableDictionary(Object[] objects,
Object[] keys)
Creates an NSMutableDictionary with entries from the contents of the keys and objects arrays. |
|
NSMutableDictionary(Object object,
Object key)
Creates an NSMutableDictionary containing a single object object
for a single key key . |
Method Summary | |
void |
addEntriesFromDictionary(NSDictionary otherDictionary)
Adds all the entries from otherDictionary to this dictionary. |
Object |
clone()
Creates a new NSMutableDictionary with the same collection of keys and their values as this one currently contains. |
NSDictionary |
immutableClone()
Creates a new NSDictionary with the same collection of keys and their values as this dictionary currently contains. |
NSMutableDictionary |
mutableClone()
Creates a new NSMutableDictionary with the same collection of keys and their values as this one currently contains. |
void |
removeAllObjects()
Deletes all the entries from the dictionary. |
Object |
removeObjectForKey(Object key)
Removes the dictionary entry identified by key and returns the
entry's value object. |
void |
removeObjectsForKeys(NSArray keys)
Removes one or more objects which may exist in this dictionary. |
void |
setDictionary(NSDictionary otherDictionary)
Replaces this dictionary's entries with those in otherDictionary . |
void |
setObjectForKey(Object object,
Object key)
Adds or replaces an entry to this dictionary consisting of key
and its corresponding value object . |
void |
takeValueForKey(Object value,
String key)
Conformance to NSKeyValueCoding. |
Methods inherited from class com.webobjects.foundation.NSDictionary |
allKeys, allKeysForObject, allValues, classForCoder, count, decodeObject, encodeWithCoder, equals, hashCode, hashtable, isEqualToDictionary, keyEnumerator, keysNoCopy, objectEnumerator, objectForKey, objectsForKeys, objectsNoCopy, takeValueForKeyPath, toString, valueForKey, valueForKeyPath |
Methods inherited from class java.lang.Object |
finalize, getClass, notify, notifyAll, wait, wait, wait |
Constructor Detail |
public NSMutableDictionary()
For better performance, one should use NSMutableDictionary(int capacity) instead.
NSMutableDictionary(int capacity)
public NSMutableDictionary(int capacity)
capacity
entries. NSMutableDictionaries grow as
necessary, so this is a recommended performance enhancement.capacity
- a size hint for the expected number of entriespublic NSMutableDictionary(Object object, Object key)
object
for a single key key
. Neither argument is permitted to be null
Note: NSMutableDictionary assumes that key objects are immutable. If the key objects are mutable, you should make copies of them and add the copies to the dictionary.
object
- the value object with which to initialize this dictionarykey
- key corresponding to the value objectpublic NSMutableDictionary(Object[] objects, Object[] keys)
keys
and objects
arrays.
This method steps through objects
and keys
,
creating entries in the new dictionary as
it goes. A key corresponds to the object which shares the same index
in each of the array arguments.Note: NSMutableDictionary assumes that key objects are immutable. If the key objects are mutable, you should make copies of them and add the copies to the dictionary.
objects
- an array of objects with which to initialize this dictionarykeys
- an array of corresponding keysIllegalArgumentException
- if the objects
and
keys
do not have the same number of elements, or any element in them is null
public NSMutableDictionary(NSArray objects, NSArray keys)
keys
and objects
NSArrays.
This method steps through objects
and keys
,
creating entries in the new dictionary as it goes. A key corresponds to
the object which shares the same index in each of the array arguments.Note: NSMutableDictionary assumes that key objects are immutable. If your key objects are mutable, you should make copies of them and add the copies to the dictionary.
objects
- an array of objects with which to initialize this dictionarykeys
- an array of corresponding keysIllegalArgumentException
- if the objects
and
keys
do not have the same number of elementspublic NSMutableDictionary(NSDictionary otherDictionary)
otherDictionary
.
One should use mutableClone
instead.otherDictionary
- the dictionary to duplicatemutableClone()
,
clone()
public NSMutableDictionary(Dictionary dictionary, boolean ignoreNull)
dictionary
.dictionary
- a java.util.Dictionary containing a mapping of keys and values with which to initialize this dictionaryignoreNull
- true
if null value is to be ignored, else false
IllegalArgumentException
- if any key or value in
dictionary
is null
Dictionary
Method Detail |
public void addEntriesFromDictionary(NSDictionary otherDictionary)
otherDictionary
to this dictionary.
Entries in otherDictionary
which overlap with existing entries
in this dictionary replace the current entries.otherDictionary
- a dictionary containing the keys and objects to add to this onesetObjectForKey(java.lang.Object, java.lang.Object)
public Object clone()
clone
in class NSDictionary
mutableClone()
,
immutableClone()
,
Object.clone()
public NSDictionary immutableClone()
immutableClone
in class NSDictionary
mutableClone()
,
clone()
public NSMutableDictionary mutableClone()
mutableClone
in class NSDictionary
immutableClone()
,
clone()
public void removeAllObjects()
removeObjectForKey(java.lang.Object)
,
removeObjectsForKeys(com.webobjects.foundation.NSArray)
public Object removeObjectForKey(Object key)
key
and returns the
entry's value object. If no entry identified by key
exists, this
method returns null
.key
- key identifying the dictionary entrykey
or null
removeObjectsForKeys(com.webobjects.foundation.NSArray)
,
removeAllObjects()
public void removeObjectsForKeys(NSArray keys)
keys
. This method
simply ignores any keys which are not present in this dictionary.keys
- keys in the key array identifying the dictionary entriesremoveObjectForKey(java.lang.Object)
,
removeAllObjects()
public void setDictionary(NSDictionary otherDictionary)
otherDictionary
.
This method removes all entries from this dictionary and then
adds all the entries from otherDictionary
into this dictionary.otherDictionary
- a dictionary containing the new keys and objects for this oneremoveAllObjects()
public void setObjectForKey(Object object, Object key)
key
and its corresponding value object
.Note: NSMutableDictionary assumes that key objects are immutable. If the key objects are mutable, copies should be made and added to the dictionary.
object
- a new value or a replacement valuekey
- the key to either insert or replaceIllegalArgumentException
- if either the key or value object is null
NSDictionary.objectForKey(java.lang.Object)
,
removeObjectForKey(java.lang.Object)
public void takeValueForKey(Object value, String key)
Invokes setObjectForKey
with the specified parameters if value
is
not null
. Otherwise if value
is
is null
removeObjectForKey with the specified key.
Note: NSMutableDictionary assumes that key objects are immutable. If your key objects are mutable, you should make copies of them and add the copies to the dictionary.
takeValueForKey
in class NSDictionary
value
- a new value object, or null
key
- key whose corresponding value should be updated, or the key to be removed.NSKeyValueCoding
,
setObjectForKey(java.lang.Object, java.lang.Object)
,
removeObjectForKey(java.lang.Object)
|
Last updated Fri Feb 21 13:15:00 PST 2003. | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |