Class NSNumber
java.lang.Object
com.dd.plist.NSObject
com.dd.plist.NSNumber
- All Implemented Interfaces:
Cloneable, Comparable<NSObject>
The NSNumber class wraps a numeric value. The value can be an integer a floating point number or a boolean value.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intIndicates that the number's value is boolean.private booleanprivate doubleprivate static final Stringstatic final intIndicates that the number's value is an integer.private longprivate static final Stringprivate static final Stringprivate static final Stringprivate static final Stringstatic final intIndicates that the number's value is a real number.private static final Stringprivate intHolds the current type of this numberprivate static final StringFields inherited from class NSObject
ASCII_LINE_LENGTH, NEWLINE -
Constructor Summary
ConstructorsConstructorDescriptionNSNumber(boolean b) Creates a new NSNumber instance with the specified value.NSNumber(byte[] bytes, int type) Creates a new NSNumber instance from its binary representation.NSNumber(byte[] bytes, int startIndex, int endIndex, int type) Creates a new NSNumber instance from its binary representation.NSNumber(double d) Creates a new NSNumber instance with the specified value.NSNumber(int i) Creates a new NSNumber instance with the specified value.NSNumber(long l) Creates a new NSNumber instance with the specified value.Create a NSNumber instance from its textual representation. -
Method Summary
Modifier and TypeMethodDescriptionbooleanGets this instance's boolean value.clone()Creates and returns a deep copy of this instance.intdoubleGets this instance'sdoublevalue.booleanChecks whether the other object is a NSNumber of the same value.floatGets this instance'sfloatvalue.private StringinthashCode()intintValue()Gets this instance's integer value.booleanGets a value indicating whether the value of this NSNumber is a boolean.booleanGets a value indicating whether the value of this NSNumber is an integer.booleanisReal()Gets a value indicating whether the value of this NSNumber is a real number.longGets this instance's long integer value.Gets this instance's value expressed as a human-readable string.private voidprotected voidtoASCII(StringBuilder ascii, int level) Generates the ASCII representation of this object.protected voidtoASCIIGnuStep(StringBuilder ascii, int level) Generates the ASCII representation of this object in the GnuStep format.(package private) voidGenerates the binary representation of the object.Converts this NSObject into an equivalent object of the Java Runtime Environment.toString()(package private) voidtoXML(StringBuilder xml, int level) Generates the XML representation of the object (without XML headers or enclosing plist-tags).inttype()Gets the type of this instance's value.Methods inherited from class NSObject
assignIDs, fromJavaObject, indent, toJavaObject, toXMLPropertyList
-
Field Details
-
INTEGER
public static final int INTEGERIndicates that the number's value is an integer. The number is stored as a Javalong. Its original value could have been char, short, int, long or even long long.- See Also:
-
REAL
public static final int REALIndicates that the number's value is a real number. The number is stored as a Javadouble. Its original value could have been float or double.- See Also:
-
BOOLEAN
public static final int BOOLEANIndicates that the number's value is boolean.- See Also:
-
NAN_SYMBOL
- See Also:
-
POSTIIVE_INFINITY_SYMBOL
- See Also:
-
NEGATIVE_INFINITY_SYMBOL
- See Also:
-
TRUE_SYMBOL
- See Also:
-
YES_SYMBOL
- See Also:
-
FALSE_SYMBOL
- See Also:
-
NO_SYMOBL
- See Also:
-
type
private int typeHolds the current type of this number -
longValue
private long longValue -
doubleValue
private double doubleValue -
boolValue
private boolean boolValue
-
-
Constructor Details
-
NSNumber
public NSNumber(byte[] bytes, int type) Creates a new NSNumber instance from its binary representation.- Parameters:
bytes- The binary representation of this number.type- The type of number.- See Also:
-
NSNumber
public NSNumber(byte[] bytes, int startIndex, int endIndex, int type) Creates a new NSNumber instance from its binary representation.- Parameters:
bytes- An array of bytes containing the binary representation of the number.startIndex- The position in the array at which the number is stored.endIndex- The position in the array at which the number's data ends.type- The type of number- See Also:
-
NSNumber
Create a NSNumber instance from its textual representation.- Parameters:
text- The textual representation of the number.- Throws:
IllegalArgumentException- If the text does not represent an integer, real number or boolean value.- See Also:
-
NSNumber
public NSNumber(int i) Creates a new NSNumber instance with the specified value.- Parameters:
i- The integer value.
-
NSNumber
public NSNumber(long l) Creates a new NSNumber instance with the specified value.- Parameters:
l- The long integer value.
-
NSNumber
public NSNumber(double d) Creates a new NSNumber instance with the specified value.- Parameters:
d- The real value.
-
NSNumber
public NSNumber(boolean b) Creates a new NSNumber instance with the specified value.- Parameters:
b- The boolean value.
-
-
Method Details
-
type
public int type()Gets the type of this instance's value.- Returns:
- The type flag.
- See Also:
-
isBoolean
public boolean isBoolean()Gets a value indicating whether the value of this NSNumber is a boolean.- Returns:
- Whether the number's value is a boolean.
-
isInteger
public boolean isInteger()Gets a value indicating whether the value of this NSNumber is an integer.- Returns:
- Whether the number's value is an integer.
-
isReal
public boolean isReal()Gets a value indicating whether the value of this NSNumber is a real number.- Returns:
- Whether the number's value is a real number.
-
boolValue
public boolean boolValue()Gets this instance's boolean value.- Returns:
trueif the value is true or non-zero and notDouble.NaN; otherwise,false.
-
longValue
public long longValue()Gets this instance's long integer value.- Returns:
- The value of the number as a
long. - Throws:
IllegalStateException- The integer value is not available because the value of this NSNumber instance is NaN, positive infinity or negative infinity.
-
intValue
public int intValue()Gets this instance's integer value. Note: Even though the number's type might be INTEGER it can be larger than a Java int. Use intValue() only if you are certain that it contains a number from the int range. Otherwise the value might be inaccurate.- Returns:
- The value of the number as an
int. - Throws:
IllegalStateException- The integer value is not available because the value of this NSNumber instance is NaN, positive infinity or negative infinity.
-
doubleValue
public double doubleValue()Gets this instance'sdoublevalue.- Returns:
- The value of the number as a
double.
-
floatValue
public float floatValue()Gets this instance'sfloatvalue. WARNING: Possible loss of precision if the value is outside the float range.- Returns:
- The value of the number as a
float.
-
stringValue
Gets this instance's value expressed as a human-readable string.- Returns:
- The human-readable string representation of this number. "+infinity" is returned for the positive infinity value (1 / 0). "-infinity" is returned for the negative infinity value (-1 / 0). "nan" is returned if the value is invalid (i.e. not a number).
-
equals
-
hashCode
-
clone
-
toString
-
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
-
toXML
Description copied from class:NSObjectGenerates the XML representation of the object (without XML headers or enclosing plist-tags).- Specified by:
toXMLin classNSObject- Parameters:
xml- TheStringBuilderonto which the XML representation is appended.level- The indentation level of the object.
-
toBinary
Description copied from class:NSObjectGenerates the binary representation of the object.- Specified by:
toBinaryin classNSObject- 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.
-
toASCII
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.- Specified by:
toASCIIin classNSObject- Parameters:
ascii- TheStringBuilderonto which the ASCII representation is appended.level- The indentation level of the object.
-
toASCIIGnuStep
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.
-
throwIfIntegerValueNotAvailable
private void throwIfIntegerValueNotAvailable() -
getRealStringRepresentation
-