Package com.dd.plist

Class 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 function objectForKey(String key).

    See Also:
    Foundation NSDictionary documentation, LinkedHashMap
    • Nested Class Summary

      • Nested classes/interfaces inherited from interface java.util.Map

        java.util.Map.Entry<K extends java.lang.Object,​V extends java.lang.Object>
    • 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) void assignIDs​(BinaryPropertyListWriter out)
      Assigns IDs to all the objects in this NSObject subtree.
      void clear()
      Removes all key-value pairs from this dictionary.
      NSDictionary clone()
      Creates and returns a deep copy of this instance.
      int compareTo​(NSObject o)  
      boolean containsKey​(java.lang.Object key)  
      boolean containsKey​(java.lang.String key)
      Checks whether a given key is contained in this dictionary.
      boolean containsValue​(boolean val)
      Checks whether a given value is contained in this dictionary.
      boolean containsValue​(byte[] val)
      Checks whether a given value is contained in this dictionary.
      boolean containsValue​(double val)
      Checks whether a given value is contained in this dictionary.
      boolean containsValue​(long val)
      Checks whether a given value is contained in this dictionary.
      boolean containsValue​(NSObject val)
      Checks whether a given value is contained in this dictionary.
      boolean containsValue​(java.lang.Object value)  
      boolean containsValue​(java.lang.String val)
      Checks whether a given value is contained in this dictionary.
      boolean containsValue​(java.util.Date val)
      Checks whether a given value is contained in this dictionary.
      int count()
      Counts the number of contained key-value pairs.
      java.util.Set<java.util.Map.Entry<java.lang.String,​NSObject>> entrySet()  
      boolean equals​(java.lang.Object obj)  
      NSObject get​(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.
      int hashCode()  
      boolean isEmpty()  
      java.util.Set<java.lang.String> keySet()  
      NSObject objectForKey​(java.lang.String key)
      Gets the NSObject stored for the given key.
      NSObject put​(java.lang.String key, NSObject obj)
      Puts a new key-value pair into this dictionary.
      NSObject put​(java.lang.String key, java.lang.Object obj)
      Puts a new key-value pair into this dictionary.
      void putAll​(java.util.Map<? extends java.lang.String,​? extends NSObject> values)  
      NSObject remove​(java.lang.Object key)  
      NSObject remove​(java.lang.String key)
      Removes a key-value pair from this dictionary.
      int size()  
      protected void toASCII​(java.lang.StringBuilder ascii, int level)
      Generates the ASCII representation of this object.
      protected void toASCIIGnuStep​(java.lang.StringBuilder ascii, int level)
      Generates the ASCII representation of this object in the GnuStep format.
      java.lang.String toASCIIPropertyList()
      Generates a valid ASCII property list which has this NSDictionary as its root object.
      (package private) void toBinary​(BinaryPropertyListWriter out)
      Generates the binary representation of the object.
      java.lang.String toGnuStepASCIIPropertyList()
      Generates a valid ASCII property list in GnuStep format which has this NSDictionary as its root object.
      java.lang.Object toJavaObject()
      Converts this NSObject into an equivalent object of the Java Runtime Environment.
      (package private) void toXML​(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 java.lang.Object

        finalize, getClass, notify, notifyAll, toString, wait, wait, wait
      • Methods inherited from interface java.util.Map

        compute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, merge, putIfAbsent, remove, replace, replace, replaceAll
    • Field Detail

      • dict

        private final java.util.HashMap<java.lang.String,​NSObject> dict
    • Constructor Detail

      • NSDictionary

        public NSDictionary()
        Creates a new NSDictionary instance.
    • 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:
        size in interface java.util.Map<java.lang.String,​NSObject>
      • isEmpty

        public boolean isEmpty()
        Specified by:
        isEmpty in interface java.util.Map<java.lang.String,​NSObject>
      • containsKey

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

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

        public NSObject get​(java.lang.Object key)
        Specified by:
        get in interface java.util.Map<java.lang.String,​NSObject>
      • putAll

        public void putAll​(java.util.Map<? extends java.lang.String,​? extends NSObject> values)
        Specified by:
        putAll in interface java.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:
        put in interface java.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:
        remove in interface java.util.Map<java.lang.String,​NSObject>
      • clear

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

        public java.util.Set<java.lang.String> keySet()
        Specified by:
        keySet in interface java.util.Map<java.lang.String,​NSObject>
      • values

        public java.util.Collection<NSObject> values()
        Specified by:
        values in interface java.util.Map<java.lang.String,​NSObject>
      • entrySet

        public java.util.Set<java.util.Map.Entry<java.lang.String,​NSObject>> entrySet()
        Specified by:
        entrySet in interface java.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:
        equals in interface java.util.Map<java.lang.String,​NSObject>
        Overrides:
        equals in class java.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:
        hashCode in interface java.util.Map<java.lang.String,​NSObject>
        Overrides:
        hashCode in class java.lang.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 java.lang.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 java.lang.Comparable<NSObject>
      • toXML

        void toXML​(java.lang.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 java.io.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:
        java.io.IOException - If an I/O error occurs while writing to the stream or the object structure contains data that cannot be saved.
      • 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: 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​(java.lang.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.