Package jsonvalues

Interface JsValue

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

    public interface JsValue
    Represents a json element of any type. Every json type implements this interface. This interface implements two kind of methods:
    • Classificatory methods, which starts with the prefix isXXX
    • Accessory methods to convert the JsElem to the real implementation, which starts with the prefix asJsXXX
    • Method Detail

      • id

        int id()
      • toJsBool

        default JsBool toJsBool()
        Returns:
        this JsElem as a JsBool
        Throws:
        UserError - if this JsElem is not a JsBool
      • isBool

        default boolean isBool()
        Returns:
        true if this JsElem is a JsBool
      • isSameType

        default boolean isSameType​(JsValue that)
        returns true if this elem and the given have the same type
        Parameters:
        that - the given elem
        Returns:
        true if this JsElem and the given have the same type
      • isTrue

        default boolean isTrue()
        Returns:
        true if this JsElem is a JsBool and it's true
      • isFalse

        default boolean isFalse()
        Returns:
        true if this JsElem is a JsBool and it's false
      • toJsInt

        default JsInt toJsInt()
        Returns:
        this JsElem as a JsInt
        Throws:
        UserError - if this JsElem is not a JsInt
      • isInt

        default boolean isInt()
        Returns:
        true if this JsElem is a JsInt
      • isInt

        default boolean isInt​(IntPredicate predicate)
        Returns true if this elem is a JsInt and satisfies the given predicate
        Parameters:
        predicate - the given predicate
        Returns:
        true if this JsElem is a JsInt and satisfies the predicate
      • toJsDouble

        default JsDouble toJsDouble()
        Returns:
        this JsElem as a JsDouble
        Throws:
        UserError - if this JsElem is not a JsDouble
      • isDouble

        default boolean isDouble()
        Returns:
        true if this JsElem is a JsDouble
      • isDouble

        default boolean isDouble​(DoublePredicate predicate)
        Returns true if this elem is a JsDouble and satisfies the given predicate
        Parameters:
        predicate - the given predicate
        Returns:
        true if this JsElem is a JsDouble and satisfies the predicate
      • toJsBigDec

        default JsBigDec toJsBigDec()
        Returns:
        this JsElem as a JsBigDec
        Throws:
        UserError - if this JsElem is not a JsBigDec or a JsDouble
      • isBigDec

        default boolean isBigDec()
        Returns:
        true if this JsElem is a JsBigDec
      • isBigDec

        default boolean isBigDec​(Predicate<BigDecimal> predicate)
        Returns true if this elem is a JsBigDec and satisfies the given predicate
        Parameters:
        predicate - the given predicate
        Returns:
        true if this JsElem is a JsBigDec and satisfies the predicate
      • toJsLong

        default JsLong toJsLong()
        Returns:
        this JsElem as a JsLong
        Throws:
        UserError - if this JsElem is not a JsLong or a JsInt
      • isLong

        default boolean isLong()
        Returns:
        true if this JsElem is a JsLong
      • isLong

        default boolean isLong​(LongPredicate predicate)
        Returns true if this elem is a JsLong and satisfies the given predicate
        Parameters:
        predicate - the given predicate
        Returns:
        true if this JsElem is a JsLong and satisfies the predicate
      • toJson

        default Json<?> toJson()
        Returns:
        this JsElem as a Json
        Throws:
        UserError - if this JsElem is not a JsObj or a JsArray
      • isJson

        default boolean isJson()
        Returns:
        true if this JsElem is a Json (JsObj or JsArray)
      • isNotJson

        default boolean isNotJson()
        Returns:
        true if this JsElem is a not a Json (neither JsObj nor JsArray)
      • isJson

        default boolean isJson​(Predicate<Json<?>> predicate)
        Returns true if this elem is a Json and satisfies the given predicate
        Parameters:
        predicate - the given predicate
        Returns:
        true if this JsElem is a Json and satisfies the predicate
      • toJsObj

        default JsObj toJsObj()
        Returns:
        this JsElem as a JsObj
        Throws:
        UserError - if this JsElem is not a JsObj
      • isObj

        default boolean isObj()
        Returns:
        true if this JsElem is a JsObj
      • isObj

        default boolean isObj​(Predicate<JsObj> predicate)
        Returns true if this elem is a JsObj and satisfies the given predicate
        Parameters:
        predicate - the given predicate
        Returns:
        true if this JsElem is a JsObj and satisfies the predicate
      • toJsArray

        default JsArray toJsArray()
        Returns:
        this JsElem as a JsArray
        Throws:
        UserError - if this JsElem is not a JsArray
      • isArray

        default boolean isArray()
        Returns:
        true if this JsElem is a JsArray
      • isArray

        default boolean isArray​(Predicate<JsArray> predicate)
        Returns true if this elem is a JsArray and satisfies the given predicate
        Parameters:
        predicate - the given predicate
        Returns:
        true if this JsElem is a JsArray and satisfies the predicate
      • toJsStr

        default JsStr toJsStr()
        Returns:
        this JsElem as a JsStr
        Throws:
        UserError - if this JsElem is not a JsStr
      • isStr

        default boolean isStr()
        Returns:
        true if this JsElem is a JsStr
      • isStr

        default boolean isStr​(Predicate<String> predicate)
        Returns true if this elem is a JsStr and satisfies the given predicate
        Parameters:
        predicate - the given predicate
        Returns:
        true if this JsElem is a JsStr and satisfies the predicate
      • toJsBigInt

        default JsBigInt toJsBigInt()
        Returns:
        this JsElem as a JsBigInt
        Throws:
        UserError - if this JsElem is not a JsBigInt or JsLong or JsInt
      • isBigInt

        default boolean isBigInt()
        Returns:
        true if this JsElem is a JsBigInt
      • isBigInt

        default boolean isBigInt​(Predicate<BigInteger> predicate)
        Returns true if this elem is a JsBigInt and satisfies the given predicate
        Parameters:
        predicate - the given predicate
        Returns:
        true if this JsElem is a JsBigInt and satisfies the predicate
      • isInstant

        default boolean isInstant()
        Returns:
        true if this JsElem is a JsStr that contains an instant in the format DateTimeFormatter.ISO_INSTANT
      • isInstant

        default boolean isInstant​(Predicate<Instant> predicate)
        Returns true if this elem is a JsStr that contains an Instant and satisfies the given predicate
        Parameters:
        predicate - the given predicate
        Returns:
        true if this JsElem is a JsStr that contains an Instant and satisfies the predicate
      • isLocalDate

        default boolean isLocalDate​(DateTimeFormatter formatter)
        return true if this JsElem is a JsStr that contains a local date that can be parsed with the given formatter
        Parameters:
        formatter - the given formatter
        Returns:
        true if this JsElem is a JsStr that contains a local date that can be parsed with the given formatter
      • isLocalDate

        default boolean isLocalDate​(DateTimeFormatter formatter,
                                    Predicate<LocalDate> predicate)
        return true if this JsElem is a JsStr that contains a local date that can be parsed with the given formatter and satisfies the given predicate
        Parameters:
        formatter - the given formatter
        predicate - the given predicate
        Returns:
        true if this JsElem is a JsStr that contains a local date that can be parsed with the formatter and satisfies the predicate
      • isLocalDateTime

        default boolean isLocalDateTime​(DateTimeFormatter formatter)
        return true if this JsElem is a JsStr that contains a local date-time that can be parsed with the given formatter
        Parameters:
        formatter - the given formatter
        Returns:
        true if this JsElem is a JsStr that contains a local date-time that can be parsed with the given formatter
      • isLocalDateTime

        default boolean isLocalDateTime​(DateTimeFormatter formatter,
                                        Predicate<LocalDateTime> predicate)
        return true if this JsElem is a JsStr that contains a local date-time that can be parsed with the given formatter and satisfies the given predicate
        Parameters:
        formatter - the given formatter
        predicate - the given predicate
        Returns:
        true if this JsElem is a JsStr that contains a local date-time that can be parsed with the formatter and satisfies the predicate
      • isIntegral

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

        default boolean isDecimal()
        Returns:
        true if this element is an decimal number (JsDouble or JsBigDec)
      • isNull

        default boolean isNull()
        Returns:
        true if this element is null
      • isNothing

        default boolean isNothing()
        Returns:
        true if this element is JsNothing
      • isNotNull

        default boolean isNotNull()
        Returns:
        true if this element is not null
      • isNotNothing

        default boolean isNotNothing()
        Returns:
        true if this element is not JsNothing
      • isNumber

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

        default boolean isNotNumber()
        Returns:
        true if this element is not a number