|
WebObjects 5.4.2 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.webobjects.foundation.NSDictionary com.webobjects.foundation.NSMutableDictionary
public class 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)
,
NSMutableDictionary.setObjectForKey(java.lang.Object, java.lang.Object)
,
NSMutableDictionary.removeObjectForKey(java.lang.Object)
,
NSMutableDictionary.removeAllObjects()
,
NSMutableDictionary.addEntriesFromDictionary(com.webobjects.foundation.NSDictionary)
,
Serialized FormNested Class Summary |
---|
Nested classes/interfaces inherited from interface com.webobjects.foundation.NSCoding |
---|
NSCoding.Support |
Nested classes/interfaces inherited from interface com.webobjects.foundation.NSKeyValueCodingAdditions |
---|
NSKeyValueCodingAdditions.DefaultImplementation, NSKeyValueCodingAdditions.Utility |
Nested classes/interfaces inherited from interface java.util.Map |
---|
Map.Entry |
Field Summary |
---|
Fields inherited from class com.webobjects.foundation.NSDictionary |
---|
CheckForNull, EmptyDictionary, IgnoreNull |
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(Map map)
Creates a dictionary containing the keys and values found in Map . |
|
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. |
void |
clear()
Warning: NSDictionaries are immutable and therefore this method does not adhere to the Java specification. |
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. |
Object |
put(Object key,
Object value)
Warning: NSDictionaries are immutable and therefore this method does not adhere to the Java specification. |
void |
putAll(Map t)
Warning: NSDictionaries are immutable and therefore this method does not adhere to the Java specification. |
Object |
remove(Object key)
Warning: NSDictionaries are immutable and therefore this method does not adhere to the Java specification. |
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, containsKey, containsValue, count, decodeObject, emptyDictionary, encodeWithCoder, entrySet, equals, get, hashCode, hashMap, hashtable, isEmpty, isEqualToDictionary, keyEnumerator, keySet, keysNoCopy, objectEnumerator, objectForKey, objectsForKeys, objectsNoCopy, size, takeValueForKeyPath, toString, valueForKey, valueForKeyPath, values |
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.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 keys
IllegalArgumentException
- 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 keys
IllegalArgumentException
- 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 duplicateNSMutableDictionary.mutableClone()
,
NSMutableDictionary.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
public NSMutableDictionary(Map map)
Map
. Throws an IllegalArgumentException
if any key or value in dictionary
is null
. Throws a NullPointerException
if map is null.
map
- the input Map from which the current dictionary is to be created
java.lang.IllegalArgumentException
- when null
is not allowed and a null
is encounteredMap
Method Detail |
---|
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 replace
IllegalArgumentException
- if either the key or value object is null
NSDictionary.objectForKey(java.lang.Object)
,
NSMutableDictionary.removeObjectForKey(java.lang.Object)
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 entry
key
or null
NSMutableDictionary.removeObjectsForKeys(com.webobjects.foundation.NSArray)
,
NSMutableDictionary.removeAllObjects()
public void removeAllObjects()
NSMutableDictionary.removeObjectForKey(java.lang.Object)
,
NSMutableDictionary.removeObjectsForKeys(com.webobjects.foundation.NSArray)
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 oneNSMutableDictionary.removeAllObjects()
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 oneNSMutableDictionary.setObjectForKey(java.lang.Object, java.lang.Object)
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 entriesNSMutableDictionary.removeObjectForKey(java.lang.Object)
,
NSMutableDictionary.removeAllObjects()
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 interface NSKeyValueCoding
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
,
NSMutableDictionary.setObjectForKey(java.lang.Object, java.lang.Object)
,
NSMutableDictionary.removeObjectForKey(java.lang.Object)
public Object clone()
clone
in class NSDictionary
NSMutableDictionary.mutableClone()
,
NSMutableDictionary.immutableClone()
,
Object.clone()
public NSDictionary immutableClone()
immutableClone
in class NSDictionary
NSMutableDictionary.mutableClone()
,
NSMutableDictionary.clone()
public NSMutableDictionary mutableClone()
mutableClone
in class NSDictionary
NSMutableDictionary.immutableClone()
,
NSMutableDictionary.clone()
public Object put(Object key, Object value)
NSDictionary
put
in interface Map
put
in class NSDictionary
Map.put(K, V)
public Object remove(Object key)
NSDictionary
remove
in interface Map
remove
in class NSDictionary
Map.remove(java.lang.Object)
public void putAll(Map t)
NSDictionary
putAll
in interface Map
putAll
in class NSDictionary
Map.putAll(java.util.Map)
public void clear()
NSDictionary
clear
in interface Map
clear
in class NSDictionary
Map.clear()
|
Last updated June 2008 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |