Package jsonvalues
Class JsLong
- java.lang.Object
-
- jsonvalues.JsLong
-
- All Implemented Interfaces:
Comparable<JsLong>
,JsElem
,JsNumber
public final class JsLong extends Object implements JsNumber, Comparable<JsLong>
Represents an immutable json number of type long.
-
-
Field Summary
Fields Modifier and Type Field Description long
x
The long primitive.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description int
compareTo(JsLong o)
Compares twoJsLong
objects numerically.boolean
equals(@Nullable Object that)
Indicates whether some other object is "equal to" this json long.boolean
equals(JsBigDec jsBigDec)
returns true if this long and the specified bigdecimal represent the same numberboolean
equals(JsBigInt jsBigInt)
returns true if this long and the specified biginteger represent the same numberboolean
equals(JsDouble jsDouble)
returns true if this long and the specified double represent the same numberboolean
equals(JsInt jsInt)
returns true if this long and the specified integer represent the same numberint
hashCode()
Returns the hashcode of this json long.OptionalInt
intValueExact()
Returns the value of this long; or an empty optional if the value overflows anint
.boolean
isArray()
boolean
isBigDec()
boolean
isBigInt()
boolean
isBool()
boolean
isDouble()
boolean
isFalse()
boolean
isInt()
boolean
isLong()
boolean
isNothing()
boolean
isNull()
boolean
isNumber()
boolean
isObj()
boolean
isStr()
boolean
isTrue()
JsLong
map(LongUnaryOperator fn)
Maps this json long into another one.JsLong
minus(JsLong that)
subtract this long from the specified onestatic JsLong
of(long n)
Static factory method to create a JsLong from a long primitive type.JsLong
plus(JsLong that)
adds up this long to the specified oneboolean
test(LongPredicate predicate)
Tests the value of this json long on a predicate.JsLong
times(JsLong that)
multiplies this long by the specified oneString
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, isBigDec, isBigInt, isDecimal, isDouble, isInstant, isInstant, isInt, isIntegral, isJson, isJson, isLocalDate, isLocalDate, isLocalDateTime, isLocalDateTime, isLong, isNotJson, isNotNothing, isNotNull, isNotNumber, isObj, isSameType, isStr
-
-
-
-
Method Detail
-
compareTo
public int compareTo(JsLong o)
Compares twoJsLong
objects numerically.- Specified by:
compareTo
in interfaceComparable<JsLong>
- See Also:
Long.compareTo(Long)
-
equals
public boolean equals(@Nullable Object that)
Indicates whether some other object is "equal to" this json long. Numbers of different types are equals if the have the same value:JsLong.parse(1).equals(JsLong.parse(1)) JsLong.parse(1).equals(JsInt.parse(1)) JsLong.parse(1).equals(JsBigInt.parse(BigInteger.ONE)) JsLong.parse(1).equals(JsBigDec.parse(BigDecimal.valueOf(1.0))) JsLong.parse(1).equals(JsDouble.parse(1.0))
-
hashCode
public int hashCode()
Returns the hashcode of this json long.
-
map
public JsLong map(LongUnaryOperator fn)
Maps this json long into another one.- Parameters:
fn
- the mapping function- Returns:
- a new JsLong
-
plus
public JsLong plus(JsLong that)
adds up this long to the specified one- Parameters:
that
- the specified long- Returns:
- the sum of both longs
-
minus
public JsLong minus(JsLong that)
subtract this long from the specified one- Parameters:
that
- the specified long- Returns:
- this long minus the specified one
-
times
public JsLong times(JsLong that)
multiplies this long by the specified one- Parameters:
that
- the specified long- Returns:
- this long times the specified one
-
test
public boolean test(LongPredicate predicate)
Tests the value of this json long on a predicate.- Parameters:
predicate
- the predicate- Returns:
- true if this long satisfies the predicate
-
toString
public String toString()
- Overrides:
toString
in classObject
- Returns:
- a string representation of the long value.
- See Also:
Long.toString
-
of
public static JsLong of(long n)
Static factory method to create a JsLong from a long primitive type.- Parameters:
n
- the long primitive type- Returns:
- a new JsLong
-
intValueExact
public OptionalInt intValueExact()
Returns the value of this long; or an empty optional if the value overflows anint
.- Returns:
- this long as an int wrapped in an OptionalInt
-
equals
public boolean equals(JsBigDec jsBigDec)
returns true if this long and the specified bigdecimal represent the same number- Parameters:
jsBigDec
- the specified JsBigDec- Returns:
- true if both JsElem are the same value
-
equals
public boolean equals(JsBigInt jsBigInt)
returns true if this long 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 long 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(JsDouble jsDouble)
returns true if this long and the specified double represent the same number- Parameters:
jsDouble
- the specified JsDouble- Returns:
- true if both JsElem are the same value
-
isObj
public boolean isObj()
-
isArray
public boolean isArray()
-
isNothing
public boolean isNothing()
-
isNull
public boolean isNull()
-
isNumber
public boolean isNumber()
-
isBool
public boolean isBool()
-
isTrue
public boolean isTrue()
-
isFalse
public boolean isFalse()
-
isInt
public boolean isInt()
-
isDouble
public boolean isDouble()
-
isBigDec
public boolean isBigDec()
-
isLong
public boolean isLong()
-
isStr
public boolean isStr()
-
-