Class NumberNode

java.lang.Object
software.amazon.smithy.model.node.Node
software.amazon.smithy.model.node.NumberNode
All Implemented Interfaces:
FromSourceLocation, ToNode

public final class NumberNode extends Node
Represents a number node. Number nodes contain a Number value.

Number nodes contain a value. You can inspect its type by calling isNaturalNumber() or isFloatingPointNumber(). Natural numbers are positive, or negative numbers without a decimal part.

  • Constructor Details

  • Method Details

    • getValue

      public Number getValue()
      Gets the number value.
      Returns:
      Returns a number.
    • isNaturalNumber

      public boolean isNaturalNumber()
      Returns true if the node contains a natural number.
      Returns:
      Returns true if the node contains a natural number.
    • isFloatingPointNumber

      public boolean isFloatingPointNumber()
      Returns true if the node contains a floating point number.
      Returns:
      Returns true if the node contains a floating point number.
    • getType

      public NodeType getType()
      Description copied from class: Node
      Gets the type of the node.
      Specified by:
      getType in class Node
      Returns:
      Returns the node type.
    • accept

      public <R> R accept(NodeVisitor<R> visitor)
      Description copied from class: Node
      Accepts a visitor with the node.
      Specified by:
      accept in class Node
      Type Parameters:
      R - visitor return type.
      Parameters:
      visitor - Visitor to dispatch to.
      Returns:
      Returns the accepted result.
    • expectNumberNode

      public NumberNode expectNumberNode(String errorMessage)
      Description copied from class: Node
      Casts the current node to a NumberNode, throwing ExpectationNotMetException when the node is the wrong type.
      Overrides:
      expectNumberNode in class Node
      Parameters:
      errorMessage - Error message to use if the node is of the wrong type.
      Returns:
      Returns a number node.
    • expectNumberNode

      public NumberNode expectNumberNode(Supplier<String> errorMessage)
      Description copied from class: Node
      Casts the current node to a NumberNode, throwing ExpectationNotMetException when the node is the wrong type.
      Overrides:
      expectNumberNode in class Node
      Parameters:
      errorMessage - Error message supplier.
      Returns:
      Returns a number node.
    • asNumberNode

      public Optional<NumberNode> asNumberNode()
      Description copied from class: Node
      Gets the node as an NumberNode if it is an number.
      Overrides:
      asNumberNode in class Node
      Returns:
      Returns the optional NumberNode.
    • isZero

      public boolean isZero()
      Returns true if the value of the number contained in the number node is zero, accounting for float, double, bigInteger, bigDecimal, and other numeric types (e.g., 0, 0.0, etc).

      Note that -0 and +0 are considered 0. However, NaN is not considered zero. When unknown number types are encountered, this method will return true if the toString of the given number returns "0", or "0.0". Other kinds of unknown number types will be treated like a double.

      Double and float comparisons to zero are exact and use no rounding. The majority of values seen by this method come from models that use "0" or "0.0". However, we can improve this in the future with some kind of epsilon if the need arises.

      Returns:
      Returns true if set to zero.
    • equals

      public boolean equals(Object other)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object