Interface NumberValue
- All Superinterfaces:
Comparable<NumberValue>
,Node<Number>
,ValueNode<Number>
- All Known Implementing Classes:
ByteValue
,DoubleValue
,FloatValue
,IntValue
,LongValue
,ShortValue
public sealed interface NumberValue
extends ValueNode<Number>, Comparable<NumberValue>
permits IntValue, LongValue, FloatValue, DoubleValue, ByteValue, ShortValue
An interface to represent that
Node
holds number.-
Field Summary
-
Method Summary
Modifier and TypeMethodDescriptionbyte
asByte()
Gets the number as byte.double
asDouble()
Gets the number as double.float
asFloat()
Gets the number as float.int
asInt()
Gets the number as int.long
asLong()
Gets the number as long.short
asShort()
Gets the number as short.static @NotNull NumberValue
fromNumber
(@Nullable Number value) CreatesNumberValue
from the givenNumber
.default boolean
hasValue()
Checks if thisNode
holds an object.Methods inherited from interface java.lang.Comparable
compareTo
Methods inherited from interface com.github.siroshun09.configapi.core.node.Node
accept, asOptional
-
Field Details
-
ZERO
ANumberValue
that represents zero.
-
-
Method Details
-
fromNumber
CreatesNumberValue
from the givenNumber
.If the given number is zero, this method returns
ZERO
. For other values, the appropriate value record (IntValue, DoubleValue, etc.) is used.Supported Number types are as follows:
- Classes that wraps primitive types (like
Integer
,Double
) AtomicInteger
AtomicLong
- Parameters:
value
- the number value- Returns:
- a
NumberValue
with the givenNumber
- Classes that wraps primitive types (like
-
hasValue
default boolean hasValue()Description copied from interface:Node
Checks if thisNode
holds an object.The default implementation of this method checks if the returning value from
Node.value()
is notnull
. -
asInt
int asInt()Gets the number as int.- Returns:
- the int value
-
asLong
long asLong()Gets the number as long.- Returns:
- the long value
-
asFloat
float asFloat()Gets the number as float.- Returns:
- the float value
-
asDouble
double asDouble()Gets the number as double.- Returns:
- the double value
-
asByte
byte asByte()Gets the number as byte.- Returns:
- the byte value
-
asShort
short asShort()Gets the number as short.- Returns:
- the short value
-