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
Fields -
Method Summary
Modifier and TypeMethodDescriptionbyteasByte()Gets the number as byte.doubleasDouble()Gets the number as double.floatasFloat()Gets the number as float.intasInt()Gets the number as int.longasLong()Gets the number as long.shortasShort()Gets the number as short.static @NotNull NumberValuefromNumber(@Nullable Number value) CreatesNumberValuefrom the givenNumber.default booleanhasValue()Checks if thisNodeholds an object.Methods inherited from interface java.lang.Comparable
compareToMethods inherited from interface com.github.siroshun09.configapi.core.node.Node
accept, asOptional
-
Field Details
-
ZERO
ANumberValuethat represents zero.
-
-
Method Details
-
fromNumber
CreatesNumberValuefrom 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) AtomicIntegerAtomicLong
- Parameters:
value- the number value- Returns:
- a
NumberValuewith the givenNumber
- Classes that wraps primitive types (like
-
hasValue
default boolean hasValue()Description copied from interface:NodeChecks if thisNodeholds 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
-