WebObjects 5.3

com.webobjects.foundation
Class NSMutableDictionary

java.lang.Object
  extended bycom.webobjects.foundation.NSDictionary
      extended bycom.webobjects.foundation.NSMutableDictionary
All Implemented Interfaces:
Cloneable, Map, NSCoding, NSKeyValueCoding, NSKeyValueCodingAdditions, Serializable

public class NSMutableDictionary
extends NSDictionary

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.

NSMutableDictionary's Base API
MethodDescription
countReturns the number of entries in the dictionary. Inherited from NSDictionary.
objectForKeyReturns the value associated with a given key. Inherited from NSDictionary.
keysNoCopyReturns a natural language array containing the keys in the dictionary. Inherited from NSDictionary.
objectsNoCopyReturns a natural language array containing the objects in the dictionary. Inherited from NSDictionary.
removeAllObjectsEmpties the dictionary of its entries.
removeObjectForKeyRemoves the specified key object and its associated value object from the dictionary.
setObjectForKeyAdds 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.

See Also:
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 Form

Nested Class Summary
 
Nested classes inherited from class com.webobjects.foundation.NSCoding
NSCoding.Support
 
Nested classes inherited from class com.webobjects.foundation.NSKeyValueCoding
NSKeyValueCoding.DefaultImplementation, NSKeyValueCoding.ErrorHandling, NSKeyValueCoding.Null, NSKeyValueCoding.UnknownKeyException, NSKeyValueCoding.Utility, NSKeyValueCoding.ValueAccessor
 
Nested classes inherited from class com.webobjects.foundation.NSKeyValueCodingAdditions
NSKeyValueCodingAdditions.DefaultImplementation, NSKeyValueCodingAdditions.Utility
 
Nested classes inherited from class java.util.Map
Map.Entry
 
Field Summary
 
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, clear, containsKey, containsValue, count, decodeObject, encodeWithCoder, entrySet, equals, get, hashCode, hashMap, hashtable, isEmpty, isEqualToDictionary, keyEnumerator, keySet, keysNoCopy, objectEnumerator, objectForKey, objectsForKeys, objectsNoCopy, put, putAll, remove, size, takeValueForKeyPath, toString, valueForKey, valueForKeyPath, values
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

NSMutableDictionary

public NSMutableDictionary()
Creates an empty NSMutableDictionary.

For better performance, one should use NSMutableDictionary(int capacity) instead.

See Also:
NSMutableDictionary(int capacity)

NSMutableDictionary

public NSMutableDictionary(int capacity)
Creates an empty NSMutableDictionary prepared to hold at least capacity entries. NSMutableDictionaries grow as necessary, so this is a recommended performance enhancement.

Parameters:
capacity - a size hint for the expected number of entries

NSMutableDictionary

public NSMutableDictionary(Object object,
                           Object key)
Creates an NSMutableDictionary containing a single object 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.

Parameters:
object - the value object with which to initialize this dictionary
key - key corresponding to the value object

NSMutableDictionary

public NSMutableDictionary(Object[] objects,
                           Object[] keys)
Creates an NSMutableDictionary with entries from the contents of the 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.

Parameters:
objects - an array of objects with which to initialize this dictionary
keys - an array of corresponding keys
Throws:
IllegalArgumentException - if the objects and keys do not have the same number of elements, or any element in them is null

NSMutableDictionary

public NSMutableDictionary(NSArray objects,
                           NSArray keys)
Creates an NSMutableDictionary with entries from the contents of the 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.

Parameters:
objects - an array of objects with which to initialize this dictionary
keys - an array of corresponding keys
Throws:
IllegalArgumentException - if the objects and keys do not have the same number of elements

NSMutableDictionary

public NSMutableDictionary(NSDictionary otherDictionary)
Creates a new NSMutableDictionary containing the keys and values found in otherDictionary. One should use mutableClone instead.

Parameters:
otherDictionary - the dictionary to duplicate
See Also:
mutableClone(), clone()

NSMutableDictionary

public NSMutableDictionary(Dictionary dictionary,
                           boolean ignoreNull)
Creates an NSMutableDictionary containing the keys and values found in dictionary.

Parameters:
dictionary - a java.util.Dictionary containing a mapping of keys and values with which to initialize this dictionary
ignoreNull - true if null value is to be ignored, else false
Throws:
IllegalArgumentException - if any key or value in dictionary is null
See Also:
Dictionary
Method Detail

addEntriesFromDictionary

public void addEntriesFromDictionary(NSDictionary otherDictionary)
Adds all the entries from otherDictionary to this dictionary. Entries in otherDictionary which overlap with existing entries in this dictionary replace the current entries.

Parameters:
otherDictionary - a dictionary containing the keys and objects to add to this one
See Also:
setObjectForKey(java.lang.Object, java.lang.Object)

clone

public Object clone()
Creates a new NSMutableDictionary with the same collection of keys and their values as this one currently contains.

Overrides:
clone in class NSDictionary
Returns:
a clone of this NSMutableDictionary
See Also:
mutableClone(), immutableClone(), Object.clone()

immutableClone

public NSDictionary immutableClone()
Creates a new NSDictionary with the same collection of keys and their values as this dictionary currently contains. The new dictionary is immutable.

Overrides:
immutableClone in class NSDictionary
Returns:
an immutable copy (an NSDictionary object) of this dictionary
See Also:
mutableClone(), clone()

mutableClone

public NSMutableDictionary mutableClone()
Creates a new NSMutableDictionary with the same collection of keys and their values as this one currently contains.

Overrides:
mutableClone in class NSDictionary
Returns:
a clone of this NSMutableDictionary
See Also:
immutableClone(), clone()

removeAllObjects

public void removeAllObjects()
Deletes all the entries from the dictionary.

See Also:
removeObjectForKey(java.lang.Object), removeObjectsForKeys(com.webobjects.foundation.NSArray)

removeObjectForKey

public Object removeObjectForKey(Object key)
Removes the dictionary entry identified by key and returns the entry's value object. If no entry identified by key exists, this method returns null.

Parameters:
key - key identifying the dictionary entry
Returns:
the object which previously corresponded to key or null
See Also:
removeObjectsForKeys(com.webobjects.foundation.NSArray), removeAllObjects()

removeObjectsForKeys

public void removeObjectsForKeys(NSArray keys)
Removes one or more objects which may exist in this dictionary. The entries are identified by the keys in keys. This method simply ignores any keys which are not present in this dictionary.

Parameters:
keys - keys in the key array identifying the dictionary entries
See Also:
removeObjectForKey(java.lang.Object), removeAllObjects()

setDictionary

public void setDictionary(NSDictionary otherDictionary)
Replaces this dictionary's entries with those in otherDictionary. This method removes all entries from this dictionary and then adds all the entries from otherDictionary into this dictionary.

Parameters:
otherDictionary - a dictionary containing the new keys and objects for this one
See Also:
removeAllObjects()

setObjectForKey

public void setObjectForKey(Object object,
                            Object key)
Adds or replaces an entry to this dictionary consisting of 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.

Parameters:
object - a new value or a replacement value
key - the key to either insert or replace
Throws:
IllegalArgumentException - if either the key or value object is null
See Also:
NSDictionary.objectForKey(java.lang.Object), removeObjectForKey(java.lang.Object)

takeValueForKey

public void takeValueForKey(Object value,
                            String key)
Conformance to NSKeyValueCoding.

Invokes setObjectForKey with the specified parameters if value is not null. Otherwise if value is is nullremoveObjectForKey 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.

Specified by:
takeValueForKey in interface NSKeyValueCoding
Overrides:
takeValueForKey in class NSDictionary
Parameters:
value - a new value object, or null
key - key whose corresponding value should be updated, or the key to be removed.
See Also:
NSKeyValueCoding, setObjectForKey(java.lang.Object, java.lang.Object), removeObjectForKey(java.lang.Object)

Last updated Thu May 26 13:46:12 PDT 2005.

Copyright © 2005 Apple Computer, Inc.