Package jsonvalues

Interface JsValue

All Known Subinterfaces:
Json<T>
All Known Implementing Classes:
JsArray, JsBigDec, JsBigInt, JsBinary, JsBool, JsDouble, JsInstant, JsInt, JsLong, JsNothing, JsNull, JsNumber, JsObj, JsPrimitive, JsStr

public sealed interface JsValue permits JsNothing, JsPrimitive, Json<T>
Represents a JSON element of any type. Every JSON type implements this interface. This interface implements two kinds of methods:

1. Classificatory methods, which start with the prefix isXXX. 2. Accessory methods to convert the JsValue to the real implementation, which starts with the prefix toJsXXX.

  • Method Summary

    Modifier and Type
    Method
    Description
    default JsValue
    Returns the specified default value if nothing or the same this object.
    default JsValue
    ifNull(JsValue value)
    Returns the specified default value if null or the same this object.
    default boolean
    Returns true if this JsValue is a JsArray.
    default boolean
    Returns true if this element is a JsArray and satisfies the given predicate.
    default boolean
    Returns true if this JsValue is a JsBigDec.
    default boolean
    Returns true if this element is a JsBigDec and satisfies the given predicate.
    default boolean
    Returns true if this JsValue is a JsBigInt.
    default boolean
    Returns true if this element is a JsBigInt and satisfies the given predicate.
    default boolean
    Returns true if this JsValue is a JsBinary or a JsString with a value that is an array of bytes encoded in base64.
    default boolean
    Returns true if this JsValue is a JsBool.
    default boolean
    Returns true if this element is a decimal number (JsDouble or JsBigDec).
    default boolean
    Returns true if this JsValue is a JsDouble.
    default boolean
    Returns true if this element is a JsDouble and satisfies the given predicate.
    default boolean
    Returns true if this JsValue is a JsBool and its value is false.
    default boolean
    Returns true if this JsValue is a JsInstant or a JsString with a value that is a date formatted in ISO-8601.
    default boolean
    Returns true if this element is a JsInstant and satisfies the given predicate.
    default boolean
    Returns true if this JsValue is a JsInt.
    default boolean
    isInt(IntPredicate predicate)
    Returns true if this element is a JsInt and satisfies the given predicate.
    default boolean
    Returns true if this element is an integral number (JsInt, JsLong, or JsBigInt).
    default boolean
    Returns true if this JsValue is a Json (JsObj or JsArray).
    default boolean
    isJson(Predicate<Json<?>> predicate)
    Returns true if this element is a Json and satisfies the given predicate.
    default boolean
    Returns this JsValue as a JsLong.
    default boolean
    isLong(LongPredicate predicate)
    Returns true if this element is a JsLong and satisfies the given predicate.
    default boolean
    Returns true if this element is JsNothing.
    default boolean
    Returns true if this element is not JsNothing.
    default boolean
    Return true if this element is not null.
    default boolean
    Returns true if this element is not a number.
    default boolean
    Returns true if this element is null.
    default boolean
    Returns true if this element is a number.
    default boolean
    Returns true if this JsValue is a JsObj.
    default boolean
    isObj(Predicate<JsObj> predicate)
    Returns true if this element is a JsObj and satisfies the given predicate.
    default boolean
    Returns true if this JsValue is not a Json (neither JsObj nor JsArray).
    default boolean
    Returns true if this JsValue is of the same type as the given JsValue.
    default boolean
    Returns true if this JsValue is a JsStr.
    default boolean
    isStr(Predicate<String> predicate)
    Returns true if this element is a JsStr and satisfies the given predicate.
    default boolean
    Returns true if this JsValue is a JsBool and its value is true.
    default JsArray
    Returns this JsValue as a JsArray.
    default JsBigDec
    Returns this JsValue as a JsBigDec.
    default JsBigInt
    Returns this JsValue as a JsBigInt.
    default JsBinary
    Returns this JsValue as a JsBinary.
    default JsBool
    Returns this JsValue as a JsBool.
    default JsDouble
    Returns this JsValue as a JsDouble.
    default JsInstant
    Returns this JsValue as a JsInstant.
    default JsInt
    Returns this JsValue as a JsInt.
    default JsLong
    Returns this JsValue as a JsLong.
    default JsNumber
    Returns this JsValue as a JsStr.
    default JsObj
    Returns this JsValue as a JsObj.
    default Json<?>
    Returns this JsValue as a Json.
    Returns this JsValue as a JsPrimitive.
    default JsStr
    Returns this JsValue as a JsStr.
  • Method Details

    • toJsBool

      default JsBool toJsBool()
      Returns this JsValue as a JsBool.
      Returns:
      This JsValue as a JsBool.
      Throws:
      UserError - if this JsValue is not a JsBool or cannot be converted to JsBool.
    • toJsPrimitive

      JsPrimitive toJsPrimitive()
      Returns this JsValue as a JsPrimitive.
      Returns:
      This JsValue as a JsPrimitive.
      Throws:
      UserError - if this JsValue is a Json container (object or array).
    • isBinary

      default boolean isBinary()
      Returns true if this JsValue is a JsBinary or a JsString with a value that is an array of bytes encoded in base64.
      Returns:
      True if this JsValue is a JsBinary or a JsString with a value that is an array of bytes encoded in base64.
    • isInstant

      default boolean isInstant()
      Returns true if this JsValue is a JsInstant or a JsString with a value that is a date formatted in ISO-8601.
      Returns:
      True if this JsValue is a JsInstant or a JsString with a value that is a date formatted in ISO-8601.
    • isInstant

      default boolean isInstant(Predicate<Instant> predicate)
      Returns true if this element is a JsInstant and satisfies the given predicate.
      Parameters:
      predicate - The given predicate.
      Returns:
      True if this JsValue is a JsInstant and satisfies the predicate.
    • isBool

      default boolean isBool()
      Returns true if this JsValue is a JsBool.
      Returns:
      True if this JsValue is a JsBool.
    • isSameType

      default boolean isSameType(JsValue that)
      Returns true if this JsValue is of the same type as the given JsValue.
      Parameters:
      that - The given JsValue.
      Returns:
      True if this JsValue and the given JsValue have the same type.
    • isTrue

      default boolean isTrue()
      Returns true if this JsValue is a JsBool and its value is true.
      Returns:
      True if this JsValue is a JsBool and its value is true.
    • isFalse

      default boolean isFalse()
      Returns true if this JsValue is a JsBool and its value is false.
      Returns:
      True if this JsValue is a JsBool and its value is false.
    • isInt

      default boolean isInt(IntPredicate predicate)
      Returns true if this element is a JsInt and satisfies the given predicate.
      Parameters:
      predicate - The given predicate.
      Returns:
      True if this JsValue is a JsInt and satisfies the predicate.
    • isInt

      default boolean isInt()
      Returns true if this JsValue is a JsInt.
      Returns:
      True if this JsValue is a JsInt.
    • toJsInt

      default JsInt toJsInt()
      Returns this JsValue as a JsInt.
      Returns:
      This JsValue as a JsInt.
      Throws:
      UserError - if this JsValue is not a JsInt or cannot be converted to JsInt.
    • toJsInstant

      default JsInstant toJsInstant()
      Returns this JsValue as a JsInstant.
      Returns:
      This JsValue as a JsInstant.
      Throws:
      UserError - if this JsValue is not a JsInstant or cannot be converted to JsInstant, e.g., if it's not a JsInstant or a JsString with a date formatted in ISO-8601.
    • toJsBinary

      default JsBinary toJsBinary()
      Returns this JsValue as a JsBinary.
      Returns:
      This JsValue as a JsBinary.
      Throws:
      UserError - if this JsValue is not a JsBinary or cannot be converted to JsBinary, e.g., if it's not a JsBinary or a JsString with a value encoded in base64.
    • isDouble

      default boolean isDouble(DoublePredicate predicate)
      Returns true if this element is a JsDouble and satisfies the given predicate.
      Parameters:
      predicate - The given predicate.
      Returns:
      True if this JsValue is a JsDouble and satisfies the predicate.
    • isDouble

      default boolean isDouble()
      Returns true if this JsValue is a JsDouble.
      Returns:
      True if this JsValue is a JsDouble.
    • toJsDouble

      default JsDouble toJsDouble()
      Returns this JsValue as a JsDouble.
      Returns:
      This JsValue as a JsDouble.
      Throws:
      UserError - if this JsValue is not a JsDouble or cannot be converted to JsDouble.
    • isBigDec

      default boolean isBigDec(Predicate<BigDecimal> predicate)
      Returns true if this element is a JsBigDec and satisfies the given predicate.
      Parameters:
      predicate - The given predicate.
      Returns:
      True if this JsValue is a JsBigDec and satisfies the predicate.
    • isBigDec

      default boolean isBigDec()
      Returns true if this JsValue is a JsBigDec.
      Returns:
      True if this JsValue is a JsBigDec.
    • toJsBigDec

      default JsBigDec toJsBigDec()
      Returns this JsValue as a JsBigDec.
      Returns:
      This JsValue as a JsBigDec.
      Throws:
      UserError - if this JsValue is not a JsBigDec or cannot be converted to JsBigDec.
    • isLong

      default boolean isLong(LongPredicate predicate)
      Returns true if this element is a JsLong and satisfies the given predicate.
      Parameters:
      predicate - The given predicate.
      Returns:
      True if this JsValue is a JsLong and satisfies the predicate.
    • isLong

      default boolean isLong()
      Returns this JsValue as a JsLong.
      Returns:
      This JsValue as a JsLong.
      Throws:
      UserError - if this JsValue is not a JsLong, JsInt, or cannot be converted to JsLong.
    • toJsLong

      default JsLong toJsLong()
      Returns this JsValue as a JsLong.
      Returns:
      This JsValue as a JsLong.
      Throws:
      UserError - if this JsValue is not a JsLong, JsInt, or cannot be converted to JsLong.
    • isPrimitive

      default boolean isPrimitive()
      Returns true if this JsValue is not a Json (neither JsObj nor JsArray).
      Returns:
      True if this JsValue is not a Json (neither JsObj nor JsArray).
    • isJson

      default boolean isJson()
      Returns true if this JsValue is a Json (JsObj or JsArray).
      Returns:
      True if this JsValue is a Json (JsObj or JsArray).
    • isObj

      default boolean isObj()
      Returns true if this JsValue is a JsObj.
      Returns:
      True if this JsValue is a JsObj.
    • isArray

      default boolean isArray()
      Returns true if this JsValue is a JsArray.
      Returns:
      True if this JsValue is a JsArray.
    • isJson

      default boolean isJson(Predicate<Json<?>> predicate)
      Returns true if this element is a Json and satisfies the given predicate.
      Parameters:
      predicate - The given predicate.
      Returns:
      True if this JsValue is a Json and satisfies the predicate.
    • toJson

      default Json<?> toJson()
      Returns this JsValue as a Json.
      Returns:
      This JsValue as a Json.
      Throws:
      UserError - if this JsValue is not a JsObj or JsArray or cannot be converted to Json.
    • toJsObj

      default JsObj toJsObj()
      Returns this JsValue as a JsObj.
      Returns:
      This JsValue as a JsObj.
      Throws:
      UserError - if this JsValue is not a JsObj or cannot be converted to JsObj.
    • toJsArray

      default JsArray toJsArray()
      Returns this JsValue as a JsArray.
      Returns:
      This JsValue as a JsArray.
      Throws:
      UserError - if this JsValue is not a JsArray or cannot be converted to JsArray.
    • isObj

      default boolean isObj(Predicate<JsObj> predicate)
      Returns true if this element is a JsObj and satisfies the given predicate.
      Parameters:
      predicate - The given predicate.
      Returns:
      True if this JsValue is a JsObj and satisfies the predicate.
    • isArray

      default boolean isArray(Predicate<JsArray> predicate)
      Returns true if this element is a JsArray and satisfies the given predicate.
      Parameters:
      predicate - The given predicate.
      Returns:
      True if this JsValue is a JsArray and satisfies the predicate.
    • toJsNumber

      default JsNumber toJsNumber()
      Returns this JsValue as a JsStr.
      Returns:
      This JsValue as a JsStr.
      Throws:
      UserError - if this JsValue is not a JsStr or cannot be converted to JsStr.
    • isBigInt

      default boolean isBigInt(Predicate<BigInteger> predicate)
      Returns true if this element is a JsBigInt and satisfies the given predicate.
      Parameters:
      predicate - The given predicate.
      Returns:
      True if this JsValue is a JsBigInt and satisfies the predicate.
    • isBigInt

      default boolean isBigInt()
      Returns true if this JsValue is a JsBigInt.
      Returns:
      True if this JsValue is a JsBigInt.
    • toJsBigInt

      default JsBigInt toJsBigInt()
      Returns this JsValue as a JsBigInt.
      Returns:
      This JsValue as a JsBigInt.
      Throws:
      UserError - if this JsValue is not a JsBigInt, JsLong, JsInt, or cannot be converted to JsBigInt.
    • isStr

      default boolean isStr(Predicate<String> predicate)
      Returns true if this element is a JsStr and satisfies the given predicate.
      Parameters:
      predicate - The given predicate.
      Returns:
      True if this JsValue is a JsStr and satisfies the predicate.
    • isStr

      default boolean isStr()
      Returns true if this JsValue is a JsStr.
      Returns:
      True if this JsValue is a JsStr.
    • toJsStr

      default JsStr toJsStr()
      Returns this JsValue as a JsStr.
      Returns:
      This JsValue as a JsStr.
      Throws:
      UserError - if this JsValue is not a JsStr or cannot be converted to JsStr.
    • isIntegral

      default boolean isIntegral()
      Returns true if this element is an integral number (JsInt, JsLong, or JsBigInt).
      Returns:
      True if this element is an integral number (JsInt, JsLong, or JsBigInt).
    • isDecimal

      default boolean isDecimal()
      Returns true if this element is a decimal number (JsDouble or JsBigDec).
      Returns:
      True if this element is a decimal number (JsDouble or JsBigDec).
    • isNotNull

      default boolean isNotNull()
      Return true if this element is not null.
      Returns:
      True if this element is not null.
    • isNull

      default boolean isNull()
      Returns true if this element is null.
      Returns:
      True if this element is null.
    • isNotNothing

      default boolean isNotNothing()
      Returns true if this element is not JsNothing.
      Returns:
      True if this element is not JsNothing.
    • isNothing

      default boolean isNothing()
      Returns true if this element is JsNothing.
      Returns:
      True if this element is JsNothing.
    • isNotNumber

      default boolean isNotNumber()
      Returns true if this element is not a number.
      Returns:
      True if this element is not a number.
    • isNumber

      default boolean isNumber()
      Returns true if this element is a number.
      Returns:
      True if this element is a number.
    • ifNull

      default JsValue ifNull(JsValue value)
      Returns the specified default value if null or the same this object.
      Parameters:
      value - The default value.
      Returns:
      A JSON value.
    • ifNothing

      default JsValue ifNothing(JsValue value)
      Returns the specified default value if nothing or the same this object.
      Parameters:
      value - The default value.
      Returns:
      A JSON value.