Package com.dd.plist
Class NSNumber
- java.lang.Object
-
- com.dd.plist.NSObject
-
- com.dd.plist.NSNumber
-
- All Implemented Interfaces:
java.lang.Cloneable,java.lang.Comparable<NSObject>
public class NSNumber extends NSObject
The NSNumber class wraps a numeric value. The value can be an integer a floating point number or a boolean value.- See Also:
- Foundation NSNumber documentation
-
-
Field Summary
Fields Modifier and Type Field Description static intBOOLEANIndicates that the number's value is boolean.private booleanboolValueprivate doubledoubleValueprivate static java.lang.StringFALSE_SYMBOLstatic intINTEGERIndicates that the number's value is an integer.private longlongValueprivate static java.lang.StringNAN_SYMBOLprivate static java.lang.StringNEGATIVE_INFINITY_SYMBOLprivate static java.lang.StringNO_SYMOBLprivate static java.lang.StringPOSTIIVE_INFINITY_SYMBOLstatic intREALIndicates that the number's value is a real number.private static java.lang.StringTRUE_SYMBOLprivate inttypeHolds the current type of this numberprivate static java.lang.StringYES_SYMBOL-
Fields inherited from class com.dd.plist.NSObject
ASCII_LINE_LENGTH, NEWLINE
-
-
Constructor Summary
Constructors Constructor Description NSNumber(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.NSNumber(java.lang.String text)Create a NSNumber instance from its textual representation.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanboolValue()Gets this instance's boolean value.NSNumberclone()Creates and returns a deep copy of this instance.intcompareTo(NSObject o)doubledoubleValue()Gets this instance'sdoublevalue.booleanequals(java.lang.Object obj)Checks whether the other object is a NSNumber of the same value.floatfloatValue()Gets this instance'sfloatvalue.private java.lang.StringgetRealStringRepresentation()inthashCode()intintValue()Gets this instance's integer value.booleanisBoolean()Gets a value indicating whether the value of this NSNumber is a boolean.booleanisInteger()Gets 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.longlongValue()Gets this instance's long integer value.java.lang.StringstringValue()Gets this instance's value expressed as a human-readable string.private voidthrowIfIntegerValueNotAvailable()protected voidtoASCII(java.lang.StringBuilder ascii, int level)Generates the ASCII representation of this object.protected voidtoASCIIGnuStep(java.lang.StringBuilder ascii, int level)Generates the ASCII representation of this object in the GnuStep format.(package private) voidtoBinary(BinaryPropertyListWriter out)Generates the binary representation of the object.java.lang.ObjecttoJavaObject()Converts this NSObject into an equivalent object of the Java Runtime Environment.java.lang.StringtoString()(package private) voidtoXML(java.lang.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 com.dd.plist.NSObject
assignIDs, fromJavaObject, indent, toJavaObject, toXMLPropertyList
-
-
-
-
Field Detail
-
INTEGER
public static final int INTEGER
Indicates 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:
- Constant Field Values
-
REAL
public static final int REAL
Indicates 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:
- Constant Field Values
-
BOOLEAN
public static final int BOOLEAN
Indicates that the number's value is boolean.- See Also:
- Constant Field Values
-
NAN_SYMBOL
private static final java.lang.String NAN_SYMBOL
- See Also:
- Constant Field Values
-
POSTIIVE_INFINITY_SYMBOL
private static final java.lang.String POSTIIVE_INFINITY_SYMBOL
- See Also:
- Constant Field Values
-
NEGATIVE_INFINITY_SYMBOL
private static final java.lang.String NEGATIVE_INFINITY_SYMBOL
- See Also:
- Constant Field Values
-
TRUE_SYMBOL
private static final java.lang.String TRUE_SYMBOL
- See Also:
- Constant Field Values
-
YES_SYMBOL
private static final java.lang.String YES_SYMBOL
- See Also:
- Constant Field Values
-
FALSE_SYMBOL
private static final java.lang.String FALSE_SYMBOL
- See Also:
- Constant Field Values
-
NO_SYMOBL
private static final java.lang.String NO_SYMOBL
- See Also:
- Constant Field Values
-
type
private int type
Holds the current type of this number
-
longValue
private long longValue
-
doubleValue
private double doubleValue
-
boolValue
private boolean boolValue
-
-
Constructor Detail
-
NSNumber
public NSNumber(byte[] bytes, int type)Creates a new NSNumber instance from its binary representation.
-
NSNumber
public NSNumber(byte[] bytes, int startIndex, int endIndex, int type)Creates a new NSNumber instance from its binary representation.
-
NSNumber
public NSNumber(java.lang.String text)
Create a NSNumber instance from its textual representation.- Parameters:
text- The textual representation of the number.- Throws:
java.lang.IllegalArgumentException- If the text does not represent an integer, real number or boolean value.- See Also:
Boolean.parseBoolean(java.lang.String),Long.parseLong(java.lang.String),Double.parseDouble(java.lang.String)
-
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 Detail
-
type
public int type()
Gets the type of this instance's value.
-
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:
java.lang.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:
java.lang.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
public java.lang.String 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
public boolean equals(java.lang.Object obj)
Checks whether the other object is a NSNumber of the same value.- Overrides:
equalsin classjava.lang.Object- Parameters:
obj- The object to compare to.- Returns:
- Whether the objects are equal in terms of numeric value and type.
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
clone
public NSNumber clone()
Description copied from class:NSObjectCreates and returns a deep copy of this instance.
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
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).
-
toBinary
void toBinary(BinaryPropertyListWriter out) throws java.io.IOException
Description copied from class:NSObjectGenerates the binary representation of the 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.
-
throwIfIntegerValueNotAvailable
private void throwIfIntegerValueNotAvailable()
-
getRealStringRepresentation
private java.lang.String getRealStringRepresentation()
-
-