Interface JsonNumber
A JSON number in a representation that the model chooses.
JsonModel.numberValue(Object) returns a JsonNumber. For the common representations, use
the factories of this interface:
JsonNumber small = JsonNumber.of(42);
JsonNumber exact = JsonNumber.of(new BigDecimal("0.1"));
Maybe<JsonNumber> binary = JsonNumber.of(1.5); // NaN and the infinities are not JSON numbers
A model can also implement this interface for its own representation, for example a number
that it reads from bytes only when the evaluator compares it. The only obligation is
exactValue().
A JsonNumber has no order of its own. The model compares numbers with
JsonModel.compareNumbers(JsonNumber, JsonNumber), because only the model knows its
representations and can compare them without conversion.
-
Method Summary
Modifier and TypeMethodDescriptionReturns the exact value of the number.static Maybe<JsonNumber> of(double value) Returns a number with adoublevalue.static JsonNumberof(int value) Returns a number with anintvalue.static JsonNumberof(long value) Returns a number with alongvalue.static JsonNumberof(JsonDecimal value) Returns a number with aJsonDecimalvalue.static JsonNumberof(BigDecimal value) Returns a number with aBigDecimalvalue.static JsonNumberof(BigInteger value) Returns a number with aBigIntegervalue.
-
Method Details
-
exactValue
JsonDecimal exactValue()Returns the exact value of the number.
Each JSON number has an exact value, also with a very large exponent.
- Returns:
- the exact value
-
of
Returns a number with anintvalue.- Parameters:
value- the value- Returns:
- the number
-
of
Returns a number with alongvalue.- Parameters:
value- the value- Returns:
- the number
-
of
Returns a number with aBigIntegervalue.- Parameters:
value- the value- Returns:
- the number
-
of
Returns a number with aBigDecimalvalue.- Parameters:
value- the value- Returns:
- the number
-
of
Returns a number with aJsonDecimalvalue.- Parameters:
value- the value- Returns:
- the number
-
of
Returns a number with a
doublevalue.The exact value is the shortest decimal that gives the
double(BigDecimal.valueOf(double)), so the JSON text1.1, read as adouble, equals the literal1.1.- Parameters:
value- the value- Returns:
- the number, or
Maybe.Noneif the value is NaN or infinite, because these values are not JSON numbers
-