Class NumberNode
- All Implemented Interfaces:
FromSourceLocation
,ToNode
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.
-
Nested Class Summary
Nested classes/interfaces inherited from class software.amazon.smithy.model.node.Node
Node.NonNumericFloat
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescription<R> R
accept
(NodeVisitor<R> visitor) Accepts a visitor with the node.Gets the number value as a BigDecimal if possible.Gets the node as an NumberNode if it is an number.boolean
expectNumberNode
(String errorMessage) Casts the current node to aNumberNode
, throwingExpectationNotMetException
when the node is the wrong type.expectNumberNode
(Supplier<String> errorMessage) Casts the current node to aNumberNode
, throwingExpectationNotMetException
when the node is the wrong type.getType()
Gets the type of the node.getValue()
Gets the number value.int
hashCode()
boolean
Returns true if the node contains a floating point number.boolean
Returns true if the number is infinite.boolean
isNaN()
Returns true if the number is a floating point NaN.boolean
Deprecated.boolean
Check the value is negative, including negative infinity.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).toString()
Methods inherited from class software.amazon.smithy.model.node.Node
arrayNode, arrayNode, asArrayNode, asBooleanNode, asNullNode, asObjectNode, assertEquals, asStringNode, diff, expectArrayNode, expectArrayNode, expectArrayNode, expectBooleanNode, expectBooleanNode, expectBooleanNode, expectNullNode, expectNullNode, expectNullNode, expectNumberNode, expectObjectNode, expectObjectNode, expectObjectNode, expectStringNode, expectStringNode, expectStringNode, from, from, from, from, fromNodes, fromNodes, fromStrings, fromStrings, getSourceLocation, isArrayNode, isBooleanNode, isNullNode, isNumberNode, isObjectNode, isStringNode, loadArrayOfString, nullNode, objectNode, objectNode, objectNodeBuilder, parse, parse, parse, parse, parseJsonWithComments, parseJsonWithComments, prettyPrintJson, prettyPrintJson, printJson, toNode, withDeepSortedKeys, withDeepSortedKeys
-
Constructor Details
-
NumberNode
-
-
Method Details
-
getValue
Gets the number value.- Returns:
- Returns a number.
-
asBigDecimal
Gets the number value as a BigDecimal if possible.NaN and infinite numbers will return an empty Optional.
- Returns:
- Returns the BigDecimal value of the wrapped number.
-
isNaturalNumber
Deprecated. -
isNegative
public boolean isNegative()Check the value is negative, including negative infinity.Any number >= 0, +Infinity, and NaN return false.
- Returns:
- Return true if negative.
-
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.
-
isNaN
public boolean isNaN()Returns true if the number is a floating point NaN.- Returns:
- Return true if NaN.
-
isInfinite
public boolean isInfinite()Returns true if the number is infinite.- Returns:
- Return true if infinite.
-
getType
Description copied from class:Node
Gets the type of the node. -
accept
Description copied from class:Node
Accepts a visitor with the node. -
expectNumberNode
Description copied from class:Node
Casts the current node to aNumberNode
, throwingExpectationNotMetException
when the node is the wrong type.- Overrides:
expectNumberNode
in classNode
- Parameters:
errorMessage
- Error message to use if the node is of the wrong type.- Returns:
- Returns a number node.
-
expectNumberNode
Description copied from class:Node
Casts the current node to aNumberNode
, throwingExpectationNotMetException
when the node is the wrong type.- Overrides:
expectNumberNode
in classNode
- Parameters:
errorMessage
- Error message supplier.- Returns:
- Returns a number node.
-
asNumberNode
Description copied from class:Node
Gets the node as an NumberNode if it is an number.- Overrides:
asNumberNode
in classNode
- 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
-
hashCode
public int hashCode() -
toString
-