Interface INumericItem

All Superinterfaces:
IAnyAtomicItem, IAtomicValuedItem, ICollectionValue, IItem
All Known Subinterfaces:
IDecimalItem, IIntegerItem, INonNegativeIntegerItem, IPositiveIntegerItem

public interface INumericItem extends IAnyAtomicItem
Represents an atomic Metapath item containing a numeric data value, which can be either an integer or decimal. This interface provides operations for numeric type conversion, comparison, and mathematical operations commonly used in Metapath expressions.
See Also:
  • Method Details

    • type

      @NonNull static IAtomicOrUnionType<INumericItem> type()
      Get the type information for this item.
      Returns:
      the type information
    • cast

      @NonNull static INumericItem cast(@NonNull IAnyAtomicItem item)
      Cast the provided type to this item type.

      Per XPath 3.1, boolean values are cast as: true → 1, false → 0.

      Parameters:
      item - the item to cast
      Returns:
      the original item if it is already this type, otherwise a new item cast to this type
      Throws:
      InvalidValueForCastFunctionException - if the provided item cannot be cast to this type
    • asDecimal

      @NonNull BigDecimal asDecimal()
      Get this item's value as a decimal.
      Returns:
      the equivalent decimal value
    • asInteger

      @NonNull BigInteger asInteger()
      Get this item's value as an integer.
      Returns:
      the equivalent integer value
    • toIntValueExact

      int toIntValueExact()
      Convert this numeric item to a Java int, exactly. If the value is not in a valid int range, an exception is thrown.
      Returns:
      the int value
      Throws:
      CastFunctionException - if the value does not fit in an int
    • toEffectiveBoolean

      boolean toEffectiveBoolean()
      Get the effective boolean value of this item based on XPath 3.1.
      Returns:
      the effective boolean value
    • castAsType

      INumericItem castAsType(IAnyAtomicItem item)
      Description copied from interface: IAnyAtomicItem
      Cast the provided item to be the same type as this item.
      Specified by:
      castAsType in interface IAnyAtomicItem
      Parameters:
      item - the item to cast
      Returns:
      an atomic item of this type
    • abs

      @NonNull INumericItem abs()
      Get the absolute value of the item.
      Returns:
      this item negated if this item is negative, or the item otherwise
    • ceiling

      @NonNull IIntegerItem ceiling()
      Round the value to the whole number closest to positive infinity.
      Returns:
      the rounded value
    • floor

      @NonNull IIntegerItem floor()
      Round the value to the whole number closest to negative infinity.
      Returns:
      the rounded value
    • round

      @NonNull default INumericItem round()
      Round the item's value with zero precision.

      This is the same as calling round(IIntegerItem) with a precision of 0.

      Returns:
      the rounded value
    • round

      @NonNull default INumericItem round(@NonNull IIntegerItem precisionItem)
      Round the item's value with the specified precision.

      This is the same as calling round(IIntegerItem) with a precision of 0.

      Parameters:
      precisionItem - the precision indicating the number of digits to round to before (negative value} or after (positive value) the decimal point.
      Returns:
      the rounded value
    • add

      @NonNull default INumericItem add(@NonNull INumericItem addend)
      Create a new sum by adding this value to the provided addend value.
      Parameters:
      addend - the second value to sum
      Returns:
      a new value resulting from adding this value to the provided addend value
    • subtract

      @NonNull default INumericItem subtract(@NonNull INumericItem subtrahend)
      Determine the difference by subtracting the provided subtrahend value from this minuend value.
      Parameters:
      subtrahend - the value to subtract
      Returns:
      a new value resulting from subtracting the subtrahend from the minuend
    • multiply

      @NonNull default INumericItem multiply(@NonNull INumericItem multiplier)
      Multiply this multiplicand value by the provided multiplier value.
      Parameters:
      multiplier - the value to multiply by
      Returns:
      a new value resulting from multiplying the multiplicand by the multiplier
    • divide

      @NonNull default INumericItem divide(@NonNull INumericItem divisor)
      Divide this dividend value by the provided divisor value.
      Parameters:
      divisor - the value to divide by
      Returns:
      a new value resulting from dividing the dividend by the divisor
    • integerDivide

      @NonNull default IIntegerItem integerDivide(@NonNull INumericItem divisor)
      Divide this dividend value by the provided divisor value using integer division.
      Parameters:
      divisor - the value to divide by
      Returns:
      a new value resulting from dividing the dividend by the divisor
    • mod

      @NonNull default INumericItem mod(@NonNull INumericItem divisor)
      Compute the remainder when dividing this dividend value by the provided divisor value.
      Parameters:
      divisor - the value to divide by
      Returns:
      a new value containing the remainder resulting from dividing the dividend by the divisor
    • negate

      @NonNull INumericItem negate()
      Reverse the sign of this value.
      Returns:
      a new value with the sign reversed