Package com.dd.plist
Class NSArray
- java.lang.Object
-
- com.dd.plist.NSObject
-
- com.dd.plist.NSArray
-
- All Implemented Interfaces:
java.lang.Cloneable,java.lang.Comparable<NSObject>
public class NSArray extends NSObject
The NSArray class is a wrapper for an array of NSObject instances.- See Also:
- Foundation NSArray documentation
-
-
Field Summary
Fields Modifier and Type Field Description private NSObject[]array-
Fields inherited from class com.dd.plist.NSObject
ASCII_LINE_LENGTH, NEWLINE
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) voidassignIDs(BinaryPropertyListWriter out)Assigns IDs to all the objects in this NSObject subtree.NSArrayclone()Creates and returns a deep copy of this instance.intcompareTo(NSObject o)booleancontainsObject(java.lang.Object obj)Checks whether an object is present in the array or whether it is equal to any of the objects in the array.intcount()Returns the size of the array.booleanequals(java.lang.Object obj)NSObject[]getArray()Returns the array of NSObjects represented by this NSArray.inthashCode()intindexOfIdenticalObject(java.lang.Object obj)Searches for a specific object in the array.intindexOfObject(java.lang.Object obj)Searches for an object in the array.NSObjectlastObject()Returns the last object contained in this array.NSObjectobjectAtIndex(int i)Returns the object stored at the given index.NSObject[]objectsAtIndexes(int... indexes)Returns a new array containing only the values stored at the given indices.voidremove(int i)Removes the i-th element from the array.voidsetValue(int key, java.lang.Object value)Stores an object at the specified index.protected voidtoASCII(java.lang.StringBuilder ascii, int level)Generates the ASCII representation of this object.private voidtoASCII(java.lang.StringBuilder ascii, int level, boolean gnustep)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 NSArray 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 NSArray 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).-
Methods inherited from class com.dd.plist.NSObject
fromJavaObject, indent, toJavaObject, toXMLPropertyList
-
-
-
-
Field Detail
-
array
private NSObject[] array
-
-
Constructor Detail
-
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 Detail
-
objectAtIndex
public NSObject objectAtIndex(int i)
Returns the object stored at the given index. Equivalent togetArray()[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, java.lang.Object value)Stores an object at the specified index. If there was another object stored at that index it will be replaced. Equivalent togetArray()[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(java.lang.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.falseotherwise.- See Also:
Object.equals(java.lang.Object)
-
indexOfObject
public int indexOfObject(java.lang.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:
Object.equals(java.lang.Object),indexOfIdenticalObject(Object)
-
indexOfIdenticalObject
public int indexOfIdenticalObject(java.lang.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:
indexOfObject(Object)
-
lastObject
public NSObject lastObject()
Returns the last object contained in this array. Equivalent togetArray()[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(java.lang.Object obj)
- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
clone
public NSArray 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)
-
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 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 java.lang.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(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.
-
toASCII
private void toASCII(java.lang.StringBuilder ascii, int level, boolean gnustep)
-
-