org.apache.xpath.objects

## Class XNumber

- java.lang.Object
- - org.apache.xpath.Expression
  - - org.apache.xpath.objects.XObject
    - - org.apache.xpath.objects.XNumber

- All Implemented Interfaces:
    java.io.Serializable, java.lang.Cloneable, javax.xml.transform.SourceLocator, ExpressionNode, XPathVisitable

      public class XNumber
      extends XObject

  This class represents an XPath number, and is capable of converting the number to other types, such as a string.
  See Also:
    Serialized Form
  Usage:

- - ### Field Summary

    - ### Fields inherited from class org.apache.xpath.objects.XObject

      `CLASS_BOOLEAN, CLASS_NODESET, CLASS_NULL, CLASS_NUMBER, CLASS_RTREEFRAG, CLASS_STRING, CLASS_UNKNOWN, CLASS_UNRESOLVEDVARIABLE`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `XNumber(double d)` Construct a XNodeSet object.
    `XNumber(java.lang.Number num)` Construct a XNodeSet object.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `boolean` | `bool()` Cast result object to a boolean.
    `void` | `callVisitors(ExpressionOwner owner, XPathVisitor visitor)` This will traverse the heararchy, calling the visitor for each member.
    `boolean` | `equals(XObject obj2)` Tell if two objects are functionally equal.
    `int` | `getType()` Tell that this is a CLASS_NUMBER.
    `java.lang.String` | `getTypeString()` Given a request type, return the equivalent string.
    `boolean` | `isStableNumber()` Tell if this expression returns a stable number that will not change during iterations within the expression.
    `double` | `num()` Cast result object to a number.
    `double` | `num(XPathContext xctxt)` Evaluate expression to a number.
    `java.lang.Object` | `object()` Return a java object that's closest to the representation that should be handed to an extension.
    `java.lang.String` | `str()` Cast result object to a string.

    - ### Methods inherited from class org.apache.xpath.objects.XObject

      `allowDetachToRelease, appendToFsb, boolWithSideEffects, castToType, create, create, deepEquals, destruct, detach, dispatchCharactersEvents, execute, fixupVariables, getFresh, greaterThan, greaterThanOrEqual, iter, lessThan, lessThanOrEqual, mutableNodeset, nodelist, nodeset, notEquals, numWithSideEffects, reset, rtf, rtf, rtree, rtree, toString, xstr`

    - ### Methods inherited from class org.apache.xpath.Expression

      `asIterator, asIteratorRaw, asNode, assertion, bool, canTraverseOutsideSubtree, error, execute, execute, execute, executeCharsToContentHandler, exprAddChild, exprGetChild, exprGetNumChildren, exprGetParent, exprSetParent, getColumnNumber, getExpressionOwner, getLineNumber, getPublicId, getSystemId, isNodesetExpr, warn, xstr`

    - ### Methods inherited from class java.lang.Object

      `equals, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- - ### Constructor Detail

    - #### XNumber

          public XNumber(double d)

      Construct a XNodeSet object.
      Parameters:
        `d` - Value of the object

    - #### XNumber

          public XNumber(java.lang.Number num)

      Construct a XNodeSet object.
      Parameters:
        `num` - Value of the object

  - ### Method Detail

    - #### getType

          public int getType()

      Tell that this is a CLASS_NUMBER.
      Overrides:
        `getType` in class `XObject`
      Returns:
        node type CLASS_NUMBER

    - #### getTypeString

          public java.lang.String getTypeString()

      Given a request type, return the equivalent string. For diagnostic purposes.
      Overrides:
        `getTypeString` in class `XObject`
      Returns:
        type string "#NUMBER"

    - #### num

          public double num()

      Cast result object to a number.
      Overrides:
        `num` in class `XObject`
      Returns:
        the value of the XNumber object

    - #### num

          public double num(XPathContext xctxt)
                     throws javax.xml.transform.TransformerException

      Evaluate expression to a number.
      Overrides:
        `num` in class `Expression`
      Parameters:
        `xctxt` - The XPath runtime context.
      Returns:
        0.0
      Throws:
        `javax.xml.transform.TransformerException`

    - #### bool

          public boolean bool()

      Cast result object to a boolean.
      Overrides:
        `bool` in class `XObject`
      Returns:
        false if the value is NaN or equal to 0.0

    - #### str

          public java.lang.String str()

      Cast result object to a string.
      Overrides:
        `str` in class `XObject`
      Returns:
        "NaN" if the number is NaN, Infinity or -Infinity if the number is infinite or the string value of the number.

    - #### object

          public java.lang.Object object()

      Return a java object that's closest to the representation that should be handed to an extension.
      Overrides:
        `object` in class `XObject`
      Returns:
        The value of this XNumber as a Double object

    - #### equals

          public boolean equals(XObject obj2)

      Tell if two objects are functionally equal.
      Overrides:
        `equals` in class `XObject`
      Parameters:
        `obj2` - Object to compare this to
      Returns:
        true if the two objects are equal
      Throws:
        `javax.xml.transform.TransformerException`

    - #### isStableNumber

          public boolean isStableNumber()

      Tell if this expression returns a stable number that will not change during iterations within the expression. This is used to determine if a proximity position predicate can indicate that no more searching has to occur.
      Overrides:
        `isStableNumber` in class `Expression`
      Returns:
        true if the expression represents a stable number.

    - #### callVisitors

          public void callVisitors(ExpressionOwner owner,
                                   XPathVisitor visitor)

      Description copied from interface: `XPathVisitable`
      This will traverse the heararchy, calling the visitor for each member. If the called visitor method returns false, the subtree should not be called.
      Specified by:
        `callVisitors` in interface `XPathVisitable`
      Overrides:
        `callVisitors` in class `XObject`
      Parameters:
        `owner` - The owner of the visitor, where that path may be rewritten if needed.
        `visitor` - The visitor whose appropriate method will be called.
      See Also:
        `XPathVisitable.callVisitors(ExpressionOwner, XPathVisitor)`

Copyright © 2023 Apache XML Project. All Rights Reserved.