Class NSDictionary

java.lang.Object
com.dd.plist.NSObject
com.dd.plist.NSDictionary
All Implemented Interfaces:
Cloneable, Comparable<NSObject>, Map<String,NSObject>

public class NSDictionary extends NSObject implements Map<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 function objectForKey(String key).

See Also:
  • Field Details

  • Constructor Details

    • NSDictionary

      public NSDictionary()
      Creates a new NSDictionary instance.
  • Method Details

    • getHashMap

      public HashMap<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(String key)
      Gets the NSObject stored for the given key.
      Parameters:
      key - The key.
      Returns:
      The object.
    • size

      public int size()
      Specified by:
      size in interface Map<String,NSObject>
    • isEmpty

      public boolean isEmpty()
      Specified by:
      isEmpty in interface Map<String,NSObject>
    • containsKey

      public boolean containsKey(Object key)
      Specified by:
      containsKey in interface Map<String,NSObject>
    • containsValue

      public boolean containsValue(Object value)
      Specified by:
      containsValue in interface Map<String,NSObject>
    • get

      public NSObject get(Object key)
      Specified by:
      get in interface Map<String,NSObject>
    • putAll

      public void putAll(Map<? extends String, ? extends NSObject> values)
      Specified by:
      putAll in interface Map<String,NSObject>
    • put

      public NSObject put(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:
      put in interface Map<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(String key, 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(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(Object key)
      Specified by:
      remove in interface Map<String,NSObject>
    • clear

      public void clear()
      Removes all key-value pairs from this dictionary.
      Specified by:
      clear in interface Map<String,NSObject>
      See Also:
    • keySet

      public Set<String> keySet()
      Specified by:
      keySet in interface Map<String,NSObject>
    • values

      public Collection<NSObject> values()
      Specified by:
      values in interface Map<String,NSObject>
    • entrySet

      public Set<Map.Entry<String,NSObject>> entrySet()
      Specified by:
      entrySet in interface Map<String,NSObject>
    • containsKey

      public boolean containsKey(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(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(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(Object obj)
      Specified by:
      equals in interface Map<String,NSObject>
      Overrides:
      equals in class Object
    • allKeys

      public 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:
      hashCode in interface Map<String,NSObject>
      Overrides:
      hashCode in class Object
    • clone

      public NSDictionary clone()
      Description copied from class: NSObject
      Creates and returns a deep copy of this instance.
      Specified by:
      clone in class NSObject
      Returns:
      A clone of this instance.
    • toJavaObject

      public Object toJavaObject()
      Description copied from class: NSObject
      Converts this NSObject into an equivalent object of the Java Runtime Environment.
      • NSArray objects are converted to arrays.
      • NSDictionary objects are converted to objects extending the Map class.
      • NSSet objects are converted to objects extending the Set class.
      • NSNumber objects are converted to primitive number values (int, long, double or boolean).
      • NSString objects are converted to String objects.
      • NSData objects are converted to byte arrays.
      • NSDate objects are converted to Date objects.
      • UID objects are converted to byte arrays.
      Specified by:
      toJavaObject in class NSObject
      Returns:
      A native java object representing this NSObject's value.
    • compareTo

      public int compareTo(NSObject o)
      Specified by:
      compareTo in interface Comparable<NSObject>
    • toXML

      void toXML(StringBuilder xml, int level)
      Description copied from class: NSObject
      Generates the XML representation of the object (without XML headers or enclosing plist-tags).
      Specified by:
      toXML in class NSObject
      Parameters:
      xml - The StringBuilder onto which the XML representation is appended.
      level - The indentation level of the object.
    • assignIDs

      void assignIDs(BinaryPropertyListWriter out)
      Description copied from class: NSObject
      Assigns IDs to all the objects in this NSObject subtree.
      Overrides:
      assignIDs in class NSObject
      Parameters:
      out - The writer object that handles the binary serialization.
    • toBinary

      void toBinary(BinaryPropertyListWriter out) throws IOException
      Description copied from class: NSObject
      Generates the binary representation of the object.
      Specified by:
      toBinary in class NSObject
      Parameters:
      out - The output stream to serialize the object to.
      Throws:
      IOException - If an I/O error occurs while writing to the stream or the object structure contains data that cannot be saved.
    • toASCIIPropertyList

      public 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 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(StringBuilder ascii, int level)
      Description copied from class: NSObject
      Generates 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.
      Specified by:
      toASCII in class NSObject
      Parameters:
      ascii - The StringBuilder onto which the ASCII representation is appended.
      level - The indentation level of the object.
    • toASCIIGnuStep

      protected void toASCIIGnuStep(StringBuilder ascii, int level)
      Description copied from class: NSObject
      Generates the ASCII representation of this object in the GnuStep format. The generated ASCII representation does not end with a newline.
      Specified by:
      toASCIIGnuStep in class NSObject
      Parameters:
      ascii - The StringBuilder onto which the ASCII representation is appended.
      level - The indentation level of the object.