Class NSNumber

All Implemented Interfaces:
Cloneable, 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.
Author:
Daniel Dreibrodt
See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
    Indicates that the number's value is boolean.
    static final int
    Indicates that the number's value is an integer.
    static final int
    Indicates that the number's value is a real number.
  • 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.
    Create a NSNumber instance from its textual representation.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    Gets this instance's boolean value.
    Creates and returns a deep copy of this instance.
    int
     
    double
    Gets this instance's double value.
    boolean
    Checks whether the other object is a NSNumber of the same value.
    float
    Gets this instance's float value.
    int
     
    int
    Gets this instance's integer value.
    boolean
    Gets a value indicating whether the value of this NSNumber is a boolean.
    boolean
    Gets a value indicating whether the value of this NSNumber is an integer.
    boolean
    Gets a value indicating whether the value of this NSNumber is a real number.
    long
    Gets this instance's long integer value.
    Gets this instance's value expressed as a human-readable string.
    protected void
    toASCII(StringBuilder ascii, int level)
     
    protected void
    toASCIIGnuStep(StringBuilder ascii, int level)
     
    Converts this NSObject into an equivalent object of the Java Runtime Environment.
     
    int
    Gets the type of this instance's value.

    Methods inherited from class com.dd.plist.NSObject

    fromJavaObject, getLocationInformation, indent, toJavaObject, toXMLPropertyList

    Methods inherited from class java.lang.Object

    finalize, getClass, notify, notifyAll, wait, wait, wait
  • Field Details

    • INTEGER

      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.
      See Also:
    • REAL

      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.
      See Also:
    • BOOLEAN

      public static final int BOOLEAN
      Indicates that the number's value is boolean.
      See Also:
  • 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

      public NSNumber(String text)
      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:
      true if the value is true or non-zero and not Double.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's double value.
      Returns:
      The value of the number as a double.
    • floatValue

      public float floatValue()
      Gets this instance's float value. WARNING: Possible loss of precision if the value is outside the float range.
      Returns:
      The value of the number as a float.
    • stringValue

      public 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(Object obj)
      Checks whether the other object is a NSNumber of the same value.
      Overrides:
      equals in class 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:
      hashCode in class Object
    • clone

      public NSNumber 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.
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • 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)
    • toASCII

      protected void toASCII(StringBuilder ascii, int level)
    • toASCIIGnuStep

      protected void toASCIIGnuStep(StringBuilder ascii, int level)