Class NumericValue

    • Constructor Detail

      • NumericValue

        public NumericValue()
    • Method Detail

      • parseNumber

        public static NumericValue parseNumber​(java.lang.String in)
        Get a numeric value by parsing a string; the type of numeric value depends on the lexical form of the string, following the rules for XPath numeric literals.
        in - the input string
        a NumericValue representing the value of the string. Returns Double.NaN if the value cannot be parsed as a string.
      • getDoubleValue

        public abstract double getDoubleValue()
        Get the numeric value as a double
        A double representing this numeric value; NaN if it cannot be converted
      • getFloatValue

        public abstract float getFloatValue()
        Get the numeric value converted to a float
        a float representing this numeric value; NaN if it cannot be converted
      • getDecimalValue

        public abstract java.math.BigDecimal getDecimalValue()
                                                      throws ValidationException
        Get the numeric value converted to a decimal
        a decimal representing this numeric value;
        ValidationException - if the value cannot be converted, for example if it is NaN or infinite
      • effectiveBooleanValue

        public abstract boolean effectiveBooleanValue()
        Get the effective boolean value of the value. This override of this method throws no exceptions.
        Specified by:
        effectiveBooleanValue in interface GroundedValue
        effectiveBooleanValue in class AtomicValue
        true, unless the value is boolean false, numeric zero, or zero-length string
      • isInteger

        public static boolean isInteger​(AtomicValue value)
        Test whether a value is an integer (an instance of a subtype of xs:integer)
        value - the value being tested
        true if the value is an instance of xs:integer or a type derived therefrom
      • longValue

        public abstract long longValue()
                                throws XPathException
        Return the numeric value as a Java long.
        the numeric value as a Java long. This performs truncation towards zero.
        XPathException - if the value cannot be converted
      • negate

        public abstract NumericValue negate()
        Change the sign of the number
        a value, of the same type as the original, with its sign inverted
      • floor

        public abstract NumericValue floor()
        Implement the XPath floor() function
        a value, of the same type as that supplied, rounded towards minus infinity
      • ceiling

        public abstract NumericValue ceiling()
        Implement the XPath ceiling() function
        a value, of the same type as that supplied, rounded towards plus infinity
      • round

        public abstract NumericValue round​(int scale)
        Implement the XPath round() function
        scale - the number of decimal places required in the result (supply 0 for rounding to an integer)
        a value, of the same type as that supplied, rounded towards the nearest whole number (0.5 rounded up)
      • roundHalfToEven

        public abstract NumericValue roundHalfToEven​(int scale)
        Implement the XPath 2.0 round-half-to-even() function
        scale - the decimal position for rounding: e.g. 2 rounds to a multiple of 0.01, while -2 rounds to a multiple of 100
        a value, of the same type as the original, rounded towards the nearest multiple of 10**(-scale), with rounding towards the nearest even number if two values are equally near
      • signum

        public abstract int signum()
        Ask whether the value is negative, zero, or positive
        -1 if negative, 0 if zero (including negative zero) or NaN, +1 if positive
      • isNegativeZero

        public boolean isNegativeZero()
        Ask whether this value is negative zero
        true if this value is float or double negative zero
      • isWholeNumber

        public abstract boolean isWholeNumber()
        Ask whether the value is a whole number, that is, whether it compares equal to some integer
        true if the value is a whole number
      • asSubscript

        public abstract int asSubscript()
        Test whether a number is a possible subscript into a sequence, that is, a whole number greater than zero and less than 2^31
        the number as an int if it is a possible subscript, or -1 otherwise
      • abs

        public abstract NumericValue abs()
        Get the absolute value as defined by the XPath abs() function
        the absolute value
      • getXPathComparable

        public final AtomicMatchKey getXPathComparable​(boolean ordered,
                                                       StringCollator collator,
                                                       int implicitTimezone)
        Get a Comparable value that implements the XPath ordering comparison semantics for this value. Returns null if the value is not comparable according to XPath rules. The implementation for all kinds of NumericValue returns the value itself.
        Specified by:
        getXPathComparable in class AtomicValue
        ordered - true if an ordered comparison is required. In this case the result is null if the type is unordered; in other cases the returned value will be a Comparable.
        collator - the collation to be used when comparing strings
        implicitTimezone - the implicit timezone in the dynamic context, used when comparing dates/times with and without timezone
        a collation key that implements the comparison semantics
      • compareTo

        public int compareTo​(NumericValue other)
        Compare the value to another numeric value
        Specified by:
        compareTo in interface java.lang.Comparable<NumericValue>
        other - The other numeric value
        -1 if this one is the lower, 0 if they are numerically equal, +1 if this one is the higher, or if either value is NaN. Where NaN values are involved, they should be handled by the caller before invoking this method.
        java.lang.ClassCastException - if the other value is not a NumericValue (the parameter is declared as Object to satisfy the Comparable interface)
      • compareTo

        public abstract int compareTo​(long other)
        Compare the value to a long
        other - the value to be compared with
        -1 if this is less, 0 if this is equal, +1 if this is greater or if this is NaN
      • equals

        public final boolean equals​(java.lang.Object other)
        The equals() function compares numeric equality among integers, decimals, floats, doubles, and their subtypes
        Specified by:
        equals in class AtomicValue
        other - the value to be compared with this one
        true if the two values are numerically equal
      • hashCode

        public abstract int hashCode()
        hashCode() must be the same for two values that are equal. One way to ensure this is to convert the value to a double, and take the hashCode of the double. But this is expensive in the common case where we are comparing integers. So we adopt the rule: for values that are in the range of a Java Integer, we use the int value as the hashcode. For values outside that range, we convert to a double and take the hashCode of the double. This method needs to have a compatible implementation in each subclass.
        hashCode in class java.lang.Object
        the hash code of the numeric value
      • toString

        public java.lang.String toString()
        Produce a string representation of the value
        toString in class AtomicValue
        The result of casting the number to a string