Package jsonvalues
Class JsBigDec
- java.lang.Object
-
- jsonvalues.JsBigDec
-
- All Implemented Interfaces:
Comparable<JsBigDec>
,JsElem
,JsNumber
public final class JsBigDec extends Object implements JsNumber, Comparable<JsBigDec>
Represents an immutable json number of type BigDecimal.
-
-
Field Summary
Fields Modifier and Type Field Description BigDecimal
x
The big decimal value
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Optional<BigInteger>
bigIntegerExact()
Returns the value of this bigdecimal; or an empty optional if the value overflows anbiginteger
.int
compareTo(JsBigDec o)
Compares twoJsBigDec
objects numericallyOptionalDouble
doubleValueExact()
Returns the value of this bigdecimal; or an empty optional if the value overflows andouble
.boolean
equals(@Nullable Object that)
Indicates whether some other object is "equal to" this json big decimal.boolean
equals(JsBigInt jsBigInt)
returns true if this bigdecimal and the specified biginteger represent the same numberboolean
equals(JsDouble jsDouble)
returns true if this bigdecimal and the specified double represent the same numberboolean
equals(JsInt jsInt)
returns true if this bigdecimal and the specified integer represent the same numberboolean
equals(JsLong jsLong)
returns true if this bigdecimal and the specified long represent the same numberint
hashCode()
Returns the hashcode of this json big decimalOptionalInt
intValueExact()
Returns the value of this bigdecimal; or an empty optional if the value overflows anint
.OptionalLong
longValueExact()
Returns the value of this bigdecimal; or an empty optional if the value overflows anlong
.JsBigDec
map(UnaryOperator<BigDecimal> fn)
Maps this JsBigDec into another onestatic JsBigDec
of(BigDecimal n)
Static factory method to create a JsBigDec from a BigDecimal object.boolean
test(Predicate<BigDecimal> predicate)
Tests the value of this json bigdec on a predicateString
toString()
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface jsonvalues.JsElem
asJsArray, asJsBigDec, asJsBigInt, asJsBool, asJsDouble, asJsInt, asJsLong, asJsObj, asJson, asJsStr, isArray, isArray, isBigDec, isBigDec, isBigInt, isBigInt, isBool, isDecimal, isDouble, isDouble, isFalse, isInstant, isInstant, isInt, isInt, isIntegral, isJson, isJson, isLocalDate, isLocalDate, isLocalDateTime, isLocalDateTime, isLong, isLong, isNothing, isNotJson, isNotNothing, isNotNull, isNotNumber, isNull, isNumber, isObj, isObj, isStr, isStr, isTrue
-
-
-
-
Field Detail
-
x
public final BigDecimal x
The big decimal value
-
-
Method Detail
-
compareTo
public int compareTo(JsBigDec o)
Compares twoJsBigDec
objects numerically- Specified by:
compareTo
in interfaceComparable<JsBigDec>
- See Also:
compareTo(JsBigDec)
-
equals
public boolean equals(@Nullable Object that)
Indicates whether some other object is "equal to" this json big decimal. Numbers of different types are equals if the have the same value:JsBigDec.of(BigDecimal.valueOf(1.0)).equals(JsDouble.of(1.00)) JsBigDec.of(BigDecimal.valueOf(1.0)).equals(JsInt.of(1)) JsBigDec.of(BigDecimal.valueOf(1.0)).equals(JsBigInt.of(BigInteger.ONE)) JsBigDec.of(BigDecimal.valueOf(1.0)).equals(JsBigDec.of(BigDecimal.valueOf(1.00))) JsBigDec.of(BigDecimal.valueOf(1.0)).equals(JsLong.of(1))
-
hashCode
public int hashCode()
Returns the hashcode of this json big decimal
-
map
public JsBigDec map(UnaryOperator<BigDecimal> fn)
Maps this JsBigDec into another one- Parameters:
fn
- the mapping function- Returns:
- a new JsBigDec
-
test
public boolean test(Predicate<BigDecimal> predicate)
Tests the value of this json bigdec on a predicate- Parameters:
predicate
- the predicate- Returns:
- true if this big decimal satisfies the predicate
-
of
public static JsBigDec of(BigDecimal n)
Static factory method to create a JsBigDec from a BigDecimal object.- Parameters:
n
- the big decimal- Returns:
- a new JsBigDec
-
toString
public String toString()
- Overrides:
toString
in classObject
- Returns:
- a string representation of the bigdec value
- See Also:
BigDecimal.toString
-
bigIntegerExact
public Optional<BigInteger> bigIntegerExact()
Returns the value of this bigdecimal; or an empty optional if the value overflows anbiginteger
.- Returns:
- this bigdecimal as an biginteger wrapped in an OptionalInt
-
intValueExact
public OptionalInt intValueExact()
Returns the value of this bigdecimal; or an empty optional if the value overflows anint
.- Returns:
- this bigdecimal as an int wrapped in an OptionalInt
-
longValueExact
public OptionalLong longValueExact()
Returns the value of this bigdecimal; or an empty optional if the value overflows anlong
.- Returns:
- this bigdecimal as an long wrapped in an OptionalLong
-
doubleValueExact
public OptionalDouble doubleValueExact()
Returns the value of this bigdecimal; or an empty optional if the value overflows andouble
.- Returns:
- this bigdecimal as an double wrapped in an OptionalDouble
- See Also:
BigDecimal.doubleValue()
-
equals
public boolean equals(JsBigInt jsBigInt)
returns true if this bigdecimal and the specified biginteger represent the same number- Parameters:
jsBigInt
- the specified JsBigInt- Returns:
- true if both JsElem are the same value
-
equals
public boolean equals(JsInt jsInt)
returns true if this bigdecimal and the specified integer represent the same number- Parameters:
jsInt
- the specified JsInt- Returns:
- true if both JsElem are the same value
-
equals
public boolean equals(JsLong jsLong)
returns true if this bigdecimal and the specified long represent the same number- Parameters:
jsLong
- the specified JsLong- Returns:
- true if both JsElem are the same value
-
equals
public boolean equals(JsDouble jsDouble)
returns true if this bigdecimal and the specified double represent the same number- Parameters:
jsDouble
- the specified JsDouble- Returns:
- true if both JsElem are the same value
-
-