Package com.dd.plist
Class NSDictionary
- java.lang.Object
-
- com.dd.plist.NSObject
-
- com.dd.plist.NSDictionary
-
- All Implemented Interfaces:
java.lang.Cloneable,java.lang.Comparable<NSObject>,java.util.Map<java.lang.String,NSObject>
public class NSDictionary extends NSObject implements java.util.Map<java.lang.String,NSObject>
The NSDictionary class is a collection of NSObject instances that are identified by strings. It represents a hash map where the keys are strings and the values NSObject instances. The implementation is based on a linked hash map, so that the order of the elements in the dictionary is preserved.You can access the keys through the function
allKeys(). Access to the objects stored for each key is given through the functionobjectForKey(String key).- See Also:
- Foundation NSDictionary documentation,
LinkedHashMap
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.HashMap<java.lang.String,NSObject>dict-
Fields inherited from class com.dd.plist.NSObject
ASCII_LINE_LENGTH, NEWLINE
-
-
Constructor Summary
Constructors Constructor Description NSDictionary()Creates a new NSDictionary instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.String[]allKeys()Gets a list of all keys used in this NSDictionary.(package private) voidassignIDs(BinaryPropertyListWriter out)Assigns IDs to all the objects in this NSObject subtree.voidclear()Removes all key-value pairs from this dictionary.NSDictionaryclone()Creates and returns a deep copy of this instance.intcompareTo(NSObject o)booleancontainsKey(java.lang.Object key)booleancontainsKey(java.lang.String key)Checks whether a given key is contained in this dictionary.booleancontainsValue(boolean val)Checks whether a given value is contained in this dictionary.booleancontainsValue(byte[] val)Checks whether a given value is contained in this dictionary.booleancontainsValue(double val)Checks whether a given value is contained in this dictionary.booleancontainsValue(long val)Checks whether a given value is contained in this dictionary.booleancontainsValue(NSObject val)Checks whether a given value is contained in this dictionary.booleancontainsValue(java.lang.Object value)booleancontainsValue(java.lang.String val)Checks whether a given value is contained in this dictionary.booleancontainsValue(java.util.Date val)Checks whether a given value is contained in this dictionary.intcount()Counts the number of contained key-value pairs.java.util.Set<java.util.Map.Entry<java.lang.String,NSObject>>entrySet()booleanequals(java.lang.Object obj)NSObjectget(java.lang.Object key)java.util.HashMap<java.lang.String,NSObject>getHashMap()Gets the hash map which stores the keys and values of this dictionary.inthashCode()booleanisEmpty()java.util.Set<java.lang.String>keySet()NSObjectobjectForKey(java.lang.String key)Gets the NSObject stored for the given key.NSObjectput(java.lang.String key, NSObject obj)Puts a new key-value pair into this dictionary.NSObjectput(java.lang.String key, java.lang.Object obj)Puts a new key-value pair into this dictionary.voidputAll(java.util.Map<? extends java.lang.String,? extends NSObject> values)NSObjectremove(java.lang.Object key)NSObjectremove(java.lang.String key)Removes a key-value pair from this dictionary.intsize()protected voidtoASCII(java.lang.StringBuilder ascii, int level)Generates the ASCII representation of this object.protected voidtoASCIIGnuStep(java.lang.StringBuilder ascii, int level)Generates the ASCII representation of this object in the GnuStep format.java.lang.StringtoASCIIPropertyList()Generates a valid ASCII property list which has this NSDictionary as its root object.(package private) voidtoBinary(BinaryPropertyListWriter out)Generates the binary representation of the object.java.lang.StringtoGnuStepASCIIPropertyList()Generates a valid ASCII property list in GnuStep format which has this NSDictionary as its root object.java.lang.ObjecttoJavaObject()Converts this NSObject into an equivalent object of the Java Runtime Environment.(package private) voidtoXML(java.lang.StringBuilder xml, int level)Generates the XML representation of the object (without XML headers or enclosing plist-tags).java.util.Collection<NSObject>values()-
Methods inherited from class com.dd.plist.NSObject
fromJavaObject, indent, toJavaObject, toXMLPropertyList
-
-
-
-
Field Detail
-
dict
private final java.util.HashMap<java.lang.String,NSObject> dict
-
-
Method Detail
-
getHashMap
public java.util.HashMap<java.lang.String,NSObject> getHashMap()
Gets the hash map which stores the keys and values of this dictionary. Changes to the hash map are directly reflected in this dictionary.- Returns:
- The hash map which is used by this dictionary to store its contents.
-
objectForKey
public NSObject objectForKey(java.lang.String key)
Gets the NSObject stored for the given key.- Parameters:
key- The key.- Returns:
- The object.
-
size
public int size()
- Specified by:
sizein interfacejava.util.Map<java.lang.String,NSObject>
-
isEmpty
public boolean isEmpty()
- Specified by:
isEmptyin interfacejava.util.Map<java.lang.String,NSObject>
-
containsKey
public boolean containsKey(java.lang.Object key)
- Specified by:
containsKeyin interfacejava.util.Map<java.lang.String,NSObject>
-
containsValue
public boolean containsValue(java.lang.Object value)
- Specified by:
containsValuein interfacejava.util.Map<java.lang.String,NSObject>
-
get
public NSObject get(java.lang.Object key)
- Specified by:
getin interfacejava.util.Map<java.lang.String,NSObject>
-
putAll
public void putAll(java.util.Map<? extends java.lang.String,? extends NSObject> values)
- Specified by:
putAllin interfacejava.util.Map<java.lang.String,NSObject>
-
put
public NSObject put(java.lang.String key, NSObject obj)
Puts a new key-value pair into this dictionary. If the value is null, no operation will be performed on the dictionary.- Specified by:
putin interfacejava.util.Map<java.lang.String,NSObject>- Parameters:
key- The key.obj- The value.- Returns:
- The value previously associated to the given key, or null, if no value was associated to it.
-
put
public NSObject put(java.lang.String key, java.lang.Object obj)
Puts a new key-value pair into this dictionary. If key or value are null, no operation will be performed on the dictionary.- Parameters:
key- The key.obj- The value. Supported object types are numbers, byte-arrays, dates, strings and arrays or sets of those.- Returns:
- The value previously associated to the given key, or null, if no value was associated to it.
-
remove
public NSObject remove(java.lang.String key)
Removes a key-value pair from this dictionary.- Parameters:
key- The key- Returns:
- the value previously associated to the given key.
-
remove
public NSObject remove(java.lang.Object key)
- Specified by:
removein interfacejava.util.Map<java.lang.String,NSObject>
-
clear
public void clear()
Removes all key-value pairs from this dictionary.- Specified by:
clearin interfacejava.util.Map<java.lang.String,NSObject>- See Also:
Map.clear()
-
keySet
public java.util.Set<java.lang.String> keySet()
- Specified by:
keySetin interfacejava.util.Map<java.lang.String,NSObject>
-
values
public java.util.Collection<NSObject> values()
- Specified by:
valuesin interfacejava.util.Map<java.lang.String,NSObject>
-
entrySet
public java.util.Set<java.util.Map.Entry<java.lang.String,NSObject>> entrySet()
- Specified by:
entrySetin interfacejava.util.Map<java.lang.String,NSObject>
-
containsKey
public boolean containsKey(java.lang.String key)
Checks whether a given key is contained in this dictionary.- Parameters:
key- The key that will be searched for.- Returns:
- Whether the key is contained in this dictionary.
-
containsValue
public boolean containsValue(NSObject val)
Checks whether a given value is contained in this dictionary.- Parameters:
val- The value that will be searched for.- Returns:
- Whether the key is contained in this dictionary.
-
containsValue
public boolean containsValue(java.lang.String val)
Checks whether a given value is contained in this dictionary.- Parameters:
val- The value that will be searched for.- Returns:
- Whether the key is contained in this dictionary.
-
containsValue
public boolean containsValue(long val)
Checks whether a given value is contained in this dictionary.- Parameters:
val- The value that will be searched for.- Returns:
- Whether the key is contained in this dictionary.
-
containsValue
public boolean containsValue(double val)
Checks whether a given value is contained in this dictionary.- Parameters:
val- The value that will be searched for.- Returns:
- Whether the key is contained in this dictionary.
-
containsValue
public boolean containsValue(boolean val)
Checks whether a given value is contained in this dictionary.- Parameters:
val- The value that will be searched for.- Returns:
- Whether the key is contained in this dictionary.
-
containsValue
public boolean containsValue(java.util.Date val)
Checks whether a given value is contained in this dictionary.- Parameters:
val- The value that will be searched for.- Returns:
- Whether the key is contained in this dictionary.
-
containsValue
public boolean containsValue(byte[] val)
Checks whether a given value is contained in this dictionary.- Parameters:
val- The value that will be searched for.- Returns:
- Whether the key is contained in this dictionary.
-
count
public int count()
Counts the number of contained key-value pairs.- Returns:
- The size of this NSDictionary.
-
equals
public boolean equals(java.lang.Object obj)
- Specified by:
equalsin interfacejava.util.Map<java.lang.String,NSObject>- Overrides:
equalsin classjava.lang.Object
-
allKeys
public java.lang.String[] allKeys()
Gets a list of all keys used in this NSDictionary.- Returns:
- The list of all keys used in this NSDictionary.
-
hashCode
public int hashCode()
- Specified by:
hashCodein interfacejava.util.Map<java.lang.String,NSObject>- Overrides:
hashCodein classjava.lang.Object
-
clone
public NSDictionary clone()
Description copied from class:NSObjectCreates and returns a deep copy of this instance.
-
toJavaObject
public java.lang.Object toJavaObject()
Description copied from class:NSObjectConverts this NSObject into an equivalent object of the Java Runtime Environment.NSArrayobjects are converted to arrays.NSDictionaryobjects are converted to objects extending theMapclass.NSSetobjects are converted to objects extending theSetclass.NSNumberobjects are converted to primitive number values (int, long, double or boolean).NSStringobjects are converted toStringobjects.NSDataobjects are converted to byte arrays.NSDateobjects are converted toDateobjects.UIDobjects are converted to byte arrays.
- Specified by:
toJavaObjectin classNSObject- Returns:
- A native java object representing this NSObject's value.
-
compareTo
public int compareTo(NSObject o)
- Specified by:
compareToin interfacejava.lang.Comparable<NSObject>
-
toXML
void toXML(java.lang.StringBuilder xml, int level)Description copied from class:NSObjectGenerates the XML representation of the object (without XML headers or enclosing plist-tags).
-
assignIDs
void assignIDs(BinaryPropertyListWriter out)
Description copied from class:NSObjectAssigns IDs to all the objects in this NSObject subtree.
-
toBinary
void toBinary(BinaryPropertyListWriter out) throws java.io.IOException
Description copied from class:NSObjectGenerates the binary representation of the object.
-
toASCIIPropertyList
public java.lang.String toASCIIPropertyList()
Generates a valid ASCII property list which has this NSDictionary as its root object. The generated property list complies with the format as described in Property List Programming Guide - Old-Style ASCII Property Lists.- Returns:
- ASCII representation of this object.
-
toGnuStepASCIIPropertyList
public java.lang.String toGnuStepASCIIPropertyList()
Generates a valid ASCII property list in GnuStep format which has this NSDictionary as its root object. The generated property list complies with the format as described in GnuStep - NSPropertyListSerialization class documentation- Returns:
- GnuStep ASCII representation of this object.
-
toASCII
protected void toASCII(java.lang.StringBuilder ascii, int level)Description copied from class:NSObjectGenerates the ASCII representation of this object. The generated ASCII representation does not end with a newline. Complies with the Old-Style ASCII Property Lists definition.
-
toASCIIGnuStep
protected void toASCIIGnuStep(java.lang.StringBuilder ascii, int level)Description copied from class:NSObjectGenerates the ASCII representation of this object in the GnuStep format. The generated ASCII representation does not end with a newline.- Specified by:
toASCIIGnuStepin classNSObject- Parameters:
ascii- TheStringBuilderonto which the ASCII representation is appended.level- The indentation level of the object.
-
-