Top Description Fields Constructors Methods
com.dd.plist

public Class NSNumber

extends NSObject
Class Inheritance
Imports
java.io.IOException, java.util.Objects

The NSNumber class wraps a numeric value. The value can be an integer a floating point number or a boolean value.
Author
Daniel Dreibrodt
See Also
Foundation NSNumber documentation

Field Summary

Modifier and TypeField and Description
public static final int
BOOLEAN

Indicates that the number's value is boolean.

private boolean
private double
private static final String
public static final int
INTEGER

Indicates that the number's value is an integer.

private long
private static final String
private static final String
private static final String
private static final String
public static final int
REAL

Indicates that the number's value is a real number.

private static final String
private int
type

Holds the current type of this number

private static final String
Inherited from com.dd.plist.NSObject:
ASCII_LINE_LENGTHNEWLINE

Constructor Summary

AccessConstructor and Description
public
NSNumber(byte[]
The binary representation of this number.
bytes
,
int
The type of number.
type
)

Creates a new NSNumber instance from its binary representation.

public
NSNumber(byte[]
An array of bytes containing the binary representation of the number.
bytes
,
final int
The position in the array at which the number is stored.
startIndex
,
final int
The position in the array at which the number's data ends.
endIndex
,
final int
The type of number
type
)

Creates a new NSNumber instance from its binary representation.

public
NSNumber(String
The textual representation of the number.
text
)

Create a NSNumber instance from its textual representation.

public
NSNumber(int
The integer value.
i
)

Creates a new NSNumber instance with the specified value.

public
NSNumber(long
The long integer value.
l
)

Creates a new NSNumber instance with the specified value.

public
NSNumber(double
The real value.
d
)

Creates a new NSNumber instance with the specified value.

public
NSNumber(boolean
The boolean value.
b
)

Creates a new NSNumber instance with the specified value.

Method Summary

Modifier and TypeMethod and Description
public boolean

Returns:

true if the value is true or non-zero and not Double.NaN; otherwise, false.
boolValue
()

Gets this instance's boolean value.

public NSNumber
clone()

Implements abstract com.dd.plist.NSObject.clone.

Creates and returns a deep copy of this instance.

public int
compareTo(NSObject o)

Implements java.lang.Comparable.compareTo.

Compares this object with the specified object for order.

public double

Returns:

The value of the number as a double.
doubleValue
()

Gets this instance's double value.

public boolean

Returns:

Whether the objects are equal in terms of numeric value and type.
equals
(Object
The object to compare to.
obj
)

Overrides java.lang.Object.equals.

Checks whether the other object is a NSNumber of the same value.

public float

Returns:

The value of the number as a float.
floatValue
()

Gets this instance's float value.

private String
public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for this object.

public int

Returns:

The value of the number as an int.
intValue
()

Gets this instance's integer value.

public boolean

Returns:

Whether the number's value is a boolean.
isBoolean
()

Gets a value indicating whether the value of this NSNumber is a boolean.

public boolean

Returns:

Whether the number's value is an integer.
isInteger
()

Gets a value indicating whether the value of this NSNumber is an integer.

public boolean

Returns:

Whether the number's value is a real number.
isReal
()

Gets a value indicating whether the value of this NSNumber is a real number.

public long

Returns:

The value of the number as a long.
longValue
()

Gets this instance's long integer value.

public 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).
stringValue
()

Gets this instance's value expressed as a human-readable string.

private void
protected void
toASCII(StringBuilder ascii, int level)

Implements abstract com.dd.plist.NSObject.toASCII.

Generates the ASCII representation of this object.

protected void
toASCIIGnuStep(StringBuilder ascii, int level)

Implements abstract com.dd.plist.NSObject.toASCIIGnuStep.

Generates the ASCII representation of this object in the GnuStep format.

pack-priv void
toBinary(BinaryPropertyListWriter out)

Implements abstract com.dd.plist.NSObject.toBinary.

Generates the binary representation of the object.

public Object
toJavaObject()

Implements abstract com.dd.plist.NSObject.toJavaObject.

Converts this NSObject into an equivalent object of the Java Runtime Environment.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

pack-priv void
toXML(StringBuilder xml, int level)

Implements abstract com.dd.plist.NSObject.toXML.

Generates the XML representation of the object (without XML headers or enclosing plist-tags).

public int

Returns:

The type flag.
type
()

Gets the type of this instance's value.

Inherited from com.dd.plist.NSObject:
assignIDsfromJavaObjectgetLocationInformationindentsetLocationInformationtoJavaObjecttoXMLPropertyList

Field Detail

BOOLEANback to summary
public static final int BOOLEAN

Indicates that the number's value is boolean.

boolValueback to summary
private boolean boolValue
doubleValueback to summary
private double doubleValue
FALSE_SYMBOLback to summary
private static final String FALSE_SYMBOL
INTEGERback to summary
public static final int INTEGER

Indicates that the number's value is an integer. The number is stored as a Java long. Its original value could have been char, short, int, long or even long long.

longValueback to summary
private long longValue
NAN_SYMBOLback to summary
private static final String NAN_SYMBOL
NEGATIVE_INFINITY_SYMBOLback to summary
private static final String NEGATIVE_INFINITY_SYMBOL
NO_SYMOBLback to summary
private static final String NO_SYMOBL
POSTIIVE_INFINITY_SYMBOLback to summary
private static final String POSTIIVE_INFINITY_SYMBOL
REALback to summary
public static final int REAL

Indicates that the number's value is a real number. The number is stored as a Java double. Its original value could have been float or double.

TRUE_SYMBOLback to summary
private static final String TRUE_SYMBOL
typeback to summary
private int type

Holds the current type of this number

YES_SYMBOLback to summary
private static final String YES_SYMBOL

Constructor Detail

NSNumberback to summary
public NSNumber(byte[] bytes, int type)

Creates a new NSNumber instance from its binary representation.

Parameters
bytes:byte[]

The binary representation of this number.

type:int

The type of number.

See Also
INTEGER, REAL, BOOLEAN
NSNumberback to summary
public NSNumber(byte[] bytes, final int startIndex, final int endIndex, final int type)

Creates a new NSNumber instance from its binary representation.

Parameters
bytes:byte[]

An array of bytes containing the binary representation of the number.

startIndex:int

The position in the array at which the number is stored.

endIndex:int

The position in the array at which the number's data ends.

type:int

The type of number

See Also
INTEGER, REAL, BOOLEAN
NSNumberback to summary
public NSNumber(String text)

Create a NSNumber instance from its textual representation.

Parameters
text:String

The textual representation of the number.

Exceptions
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)
NSNumberback to summary
public NSNumber(int i)

Creates a new NSNumber instance with the specified value.

Parameters
i:int

The integer value.

NSNumberback to summary
public NSNumber(long l)

Creates a new NSNumber instance with the specified value.

Parameters
l:long

The long integer value.

NSNumberback to summary
public NSNumber(double d)

Creates a new NSNumber instance with the specified value.

Parameters
d:double

The real value.

NSNumberback to summary
public NSNumber(boolean b)

Creates a new NSNumber instance with the specified value.

Parameters
b:boolean

The boolean value.

Method Detail

boolValueback to summary
public boolean boolValue()

Gets this instance's boolean value.

Returns:boolean

true if the value is true or non-zero and not Double.NaN; otherwise, false.

cloneback to summary
public NSNumber clone()

Implements abstract com.dd.plist.NSObject.clone.

Doc from com.dd.plist.NSObject.clone.

Creates and returns a deep copy of this instance.

Annotations
@Override
compareToback to summary
public int compareTo(NSObject o)

Implements java.lang.Comparable.compareTo.

Doc from java.lang.Comparable.compareTo.

Compares this object with the specified object for order. Returns a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.

The implementor must ensure signum(x.compareTo(y)) == -signum(y.compareTo(x)) for all x and y. (This implies that x.compareTo(y) must throw an exception if and only if y.compareTo(x) throws an exception.)

The implementor must also ensure that the relation is transitive: (x.compareTo(y) > 0 && y.compareTo(z) > 0) implies x.compareTo(z) > 0.

Finally, the implementor must ensure that x.compareTo(y)==0 implies that signum(x.compareTo(z)) == signum(y.compareTo(z)), for all z.

Annotations
@Override
doubleValueback to summary
public double doubleValue()

Gets this instance's double value.

Returns:double

The value of the number as a double.

equalsback to summary
public boolean equals(Object obj)

Overrides java.lang.Object.equals.

Checks whether the other object is a NSNumber of the same value.

Parameters
obj:Object

The object to compare to.

Returns:boolean

Whether the objects are equal in terms of numeric value and type.

Annotations
@Override
floatValueback to summary
public float floatValue()

Gets this instance's float value.

Warning

Possible loss of precision if the value is outside the float range.

Returns:float

The value of the number as a float.

getRealStringRepresentationback to summary
private String getRealStringRepresentation()
hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for this object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Annotations
@Override
intValueback to summary
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:int

The value of the number as an int.

Exceptions
IllegalStateException:
The integer value is not available because the value of this NSNumber instance is NaN, positive infinity or negative infinity.
isBooleanback to summary
public boolean isBoolean()

Gets a value indicating whether the value of this NSNumber is a boolean.

Returns:boolean

Whether the number's value is a boolean.

isIntegerback to summary
public boolean isInteger()

Gets a value indicating whether the value of this NSNumber is an integer.

Returns:boolean

Whether the number's value is an integer.

isRealback to summary
public boolean isReal()

Gets a value indicating whether the value of this NSNumber is a real number.

Returns:boolean

Whether the number's value is a real number.

longValueback to summary
public long longValue()

Gets this instance's long integer value.

Returns:long

The value of the number as a long.

Exceptions
IllegalStateException:
The integer value is not available because the value of this NSNumber instance is NaN, positive infinity or negative infinity.
stringValueback to summary
public String stringValue()

Gets this instance's value expressed as a human-readable string.

Returns:String

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).

throwIfIntegerValueNotAvailableback to summary
private void throwIfIntegerValueNotAvailable()
toASCIIback to summary
protected void toASCII(StringBuilder ascii, int level)

Implements abstract com.dd.plist.NSObject.toASCII.

Doc from com.dd.plist.NSObject.toASCII.

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.

Annotations
@Override
toASCIIGnuStepback to summary
protected void toASCIIGnuStep(StringBuilder ascii, int level)

Implements abstract com.dd.plist.NSObject.toASCIIGnuStep.

Doc from com.dd.plist.NSObject.toASCIIGnuStep.

Generates the ASCII representation of this object in the GnuStep format. The generated ASCII representation does not end with a newline.

Annotations
@Override
toBinaryback to summary
pack-priv void toBinary(BinaryPropertyListWriter out) throws IOException

Implements abstract com.dd.plist.NSObject.toBinary.

Doc from com.dd.plist.NSObject.toBinary.

Generates the binary representation of the object.

Annotations
@Override
Exceptions
IOException:
If an I/O error occurs while writing to the stream or the object structure contains data that cannot be saved.
toJavaObjectback to summary
public Object toJavaObject()

Implements abstract com.dd.plist.NSObject.toJavaObject.

Doc from com.dd.plist.NSObject.toJavaObject.

Converts this NSObject into an equivalent object of the Java Runtime Environment.

Annotations
@Override
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Annotations
@Override
toXMLback to summary
pack-priv void toXML(StringBuilder xml, int level)

Implements abstract com.dd.plist.NSObject.toXML.

Doc from com.dd.plist.NSObject.toXML.

Generates the XML representation of the object (without XML headers or enclosing plist-tags).

Annotations
@Override
typeback to summary
public int type()

Gets the type of this instance's value.

Returns:int

The type flag.

See Also
BOOLEAN, INTEGER, REAL