Class NSArray

All Implemented Interfaces:
Cloneable, Comparable<NSObject>

public class NSArray extends NSObject
The NSArray class is a wrapper for an array of NSObject instances.
See Also:
  • Field Details

  • Constructor Details

    • NSArray

      public NSArray(int length)
      Creates a new NSArray instance of the specified size.
      Parameters:
      length - The number of elements the NSArray instance will be able to hold.
    • NSArray

      public NSArray(NSObject... a)
      Creates a new NSArray instance containing the specified elements.
      Parameters:
      a - The elements to be contained by the NSArray instance.
  • Method Details

    • objectAtIndex

      public NSObject objectAtIndex(int i)
      Returns the object stored at the given index. Equivalent to getArray()[i].
      Parameters:
      i - The index of the object.
      Returns:
      The object at the given index.
    • remove

      public void remove(int i)
      Removes the i-th element from the array. The array will be resized.
      Parameters:
      i - The index of the object
    • setValue

      public void setValue(int key, Object value)
      Stores an object at the specified index. If there was another object stored at that index it will be replaced. Equivalent to getArray()[key] = value.
      Parameters:
      key - The index where to store the object.
      value - The object.
    • getArray

      public NSObject[] getArray()
      Returns the array of NSObjects represented by this NSArray. Any changes to the values of this array will also affect the NSArray.
      Returns:
      The actual array represented by this NSArray.
    • count

      public int count()
      Returns the size of the array.
      Returns:
      The number of elements that this array can store.
    • containsObject

      public boolean containsObject(Object obj)
      Checks whether an object is present in the array or whether it is equal to any of the objects in the array.
      Parameters:
      obj - The object to look for.
      Returns:
      true, when the object could be found. false otherwise.
      See Also:
    • indexOfObject

      public int indexOfObject(Object obj)
      Searches for an object in the array. If the specified object or an object equal to it is found, its index is returned. Otherwise, -1 is returned.
      Parameters:
      obj - The object to look for.
      Returns:
      The index of the object, if it was found. -1 otherwise.
      See Also:
    • indexOfIdenticalObject

      public int indexOfIdenticalObject(Object obj)
      Searches for a specific object in the array. If the specified object is found (reference equality), its index is returned. Otherwise, -1 is returned.
      Parameters:
      obj - The object to look for.
      Returns:
      The index of the object, if it was found. -1 otherwise.
      See Also:
    • lastObject

      public NSObject lastObject()
      Returns the last object contained in this array. Equivalent to getArray()[getArray().length-1].
      Returns:
      The value of the highest index in the array.
    • objectsAtIndexes

      public NSObject[] objectsAtIndexes(int... indexes)
      Returns a new array containing only the values stored at the given indices. The values are sorted by their index.
      Parameters:
      indexes - The indices of the objects.
      Returns:
      The new array containing the objects stored at the given indices.
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • clone

      public NSArray 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)
    • 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 NSArray 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 NSArray 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.
    • toASCII

      private void toASCII(StringBuilder ascii, int level, boolean gnustep)