Package jsonvalues
Interface JsValue
-
- All Known Subinterfaces:
Json<T>
- All Known Implementing Classes:
JsArray
,JsBigDec
,JsBigInt
,JsBool
,JsDouble
,JsInt
,JsLong
,JsNothing
,JsNull
,JsNumber
,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 JsValue to the real implementation, which starts with the prefix asJsXXX
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description int
id()
default JsValue
ifNothing(JsValue value)
returns the specified default value if nothing or the same this objectdefault JsValue
ifNull(JsValue value)
returns the specified default value if null or the same this objectdefault boolean
isArray()
default boolean
isArray(Predicate<JsArray> predicate)
Returns true if this elem is a JsArray and satisfies the given predicatedefault boolean
isBigDec()
default boolean
isBigDec(Predicate<BigDecimal> predicate)
Returns true if this elem is a JsBigDec and satisfies the given predicatedefault boolean
isBigInt()
default boolean
isBigInt(Predicate<BigInteger> predicate)
Returns true if this elem is a JsBigInt and satisfies the given predicatedefault boolean
isBool()
default boolean
isDecimal()
default boolean
isDouble()
default boolean
isDouble(DoublePredicate predicate)
Returns true if this elem is a JsDouble and satisfies the given predicatedefault boolean
isFalse()
default boolean
isInstant()
default boolean
isInstant(Predicate<Instant> predicate)
Returns true if this elem is a JsStr that contains an Instant and satisfies the given predicatedefault boolean
isInt()
default boolean
isInt(IntPredicate predicate)
Returns true if this elem is a JsInt and satisfies the given predicatedefault boolean
isIntegral()
default boolean
isJson()
default boolean
isJson(Predicate<Json<?>> predicate)
Returns true if this elem is a Json and satisfies the given predicatedefault boolean
isLocalDate(DateTimeFormatter formatter)
return true if this JsValue is a JsStr that contains a local date that can be parsed with the given formatterdefault boolean
isLocalDate(DateTimeFormatter formatter, Predicate<LocalDate> predicate)
return true if this JsValue is a JsStr that contains a local date that can be parsed with the given formatter and satisfies the given predicatedefault boolean
isLocalDateTime(DateTimeFormatter formatter)
return true if this JsValue is a JsStr that contains a local date-time that can be parsed with the given formatterdefault boolean
isLocalDateTime(DateTimeFormatter formatter, Predicate<LocalDateTime> predicate)
return true if this JsValue is a JsStr that contains a local date-time that can be parsed with the given formatter and satisfies the given predicatedefault boolean
isLong()
default boolean
isLong(LongPredicate predicate)
Returns true if this elem is a JsLong and satisfies the given predicatedefault boolean
isNothing()
default boolean
isNotJson()
default boolean
isNotNothing()
default boolean
isNotNull()
default boolean
isNotNumber()
default boolean
isNull()
default boolean
isNumber()
default boolean
isObj()
default boolean
isObj(Predicate<JsObj> predicate)
Returns true if this elem is a JsObj and satisfies the given predicatedefault boolean
isSameType(JsValue that)
returns true if this elem and the given have the same typedefault boolean
isStr()
default boolean
isStr(Predicate<String> predicate)
Returns true if this elem is a JsStr and satisfies the given predicatedefault boolean
isTrue()
default JsArray
toJsArray()
default JsBigDec
toJsBigDec()
default JsBigInt
toJsBigInt()
default JsBool
toJsBool()
default JsDouble
toJsDouble()
default JsInt
toJsInt()
default JsLong
toJsLong()
default JsNumber
toJsNumber()
default JsObj
toJsObj()
default Json<?>
toJson()
default JsStr
toJsStr()
-
-
-
Method Detail
-
id
int id()
-
toJsBool
default JsBool toJsBool()
- Returns:
- this JsValue as a JsBool
- Throws:
UserError
- if this JsValue is not a JsBool
-
isBool
default boolean isBool()
- Returns:
- true if this JsValue 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 JsValue and the given have the same type
-
isTrue
default boolean isTrue()
- Returns:
- true if this JsValue is a JsBool and it's true
-
isFalse
default boolean isFalse()
- Returns:
- true if this JsValue is a JsBool and it's false
-
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 JsValue is a JsInt and satisfies the predicate
-
isInt
default boolean isInt()
- Returns:
- true if this JsValue is a JsInt
-
toJsInt
default JsInt toJsInt()
- Returns:
- this JsValue as a JsInt
- Throws:
UserError
- if this JsValue is not a JsInt
-
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 JsValue is a JsDouble and satisfies the predicate
-
isDouble
default boolean isDouble()
- Returns:
- true if this JsValue is a JsDouble
-
toJsDouble
default JsDouble toJsDouble()
- Returns:
- this JsValue as a JsDouble
- Throws:
UserError
- if this JsValue is not a JsDouble
-
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 JsValue is a JsBigDec and satisfies the predicate
-
isBigDec
default boolean isBigDec()
- Returns:
- true if this JsValue is a JsBigDec
-
toJsBigDec
default JsBigDec toJsBigDec()
- Returns:
- this JsValue as a JsBigDec
- Throws:
UserError
- if this JsValue is not a JsBigDec or a JsDouble
-
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 JsValue is a JsLong and satisfies the predicate
-
isLong
default boolean isLong()
- Returns:
- true if this JsValue is a JsLong
-
toJsLong
default JsLong toJsLong()
- Returns:
- this JsValue as a JsLong
- Throws:
UserError
- if this JsValue is not a JsLong or a JsInt
-
isNotJson
default boolean isNotJson()
- Returns:
- true if this JsValue is a not a Json (neither JsObj nor JsArray)
-
isJson
default boolean isJson()
- Returns:
- true if this JsValue is a Json (JsObj or JsArray)
-
isObj
default boolean isObj()
- Returns:
- true if this JsValue is a JsObj
-
isArray
default boolean isArray()
- Returns:
- true if this JsValue is a 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 JsValue is a Json and satisfies the predicate
-
toJson
default Json<?> toJson()
- Returns:
- this JsValue as a Json
- Throws:
UserError
- if this JsValue is not a JsObj or a JsArray
-
toJsObj
default JsObj toJsObj()
- Returns:
- this JsValue as a JsObj
- Throws:
UserError
- if this JsValue is not a JsObj
-
toJsArray
default JsArray toJsArray()
- Returns:
- this JsValue as a JsArray
- Throws:
UserError
- if this JsValue is not a JsArray
-
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 JsValue is a JsObj and satisfies the predicate
-
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 JsValue is a JsArray and satisfies the predicate
-
toJsNumber
default JsNumber toJsNumber()
- Returns:
- this JsValue as a JsStr
- Throws:
UserError
- if this JsValue is not a JsStr
-
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 JsValue is a JsBigInt and satisfies the predicate
-
isBigInt
default boolean isBigInt()
- Returns:
- true if this JsValue is a JsBigInt
-
toJsBigInt
default JsBigInt toJsBigInt()
- Returns:
- this JsValue as a JsBigInt
- Throws:
UserError
- if this JsValue is not a JsBigInt or JsLong or JsInt
-
isInstant
default boolean isInstant()
- Returns:
- true if this JsValue is a JsStr that contains an instant in the format
DateTimeFormatter.ISO_INSTANT
-
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 JsValue is a JsStr and satisfies the predicate
-
isStr
default boolean isStr()
- Returns:
- true if this JsValue is a JsStr
-
toJsStr
default JsStr toJsStr()
- Returns:
- this JsValue as a JsStr
- Throws:
UserError
- if this JsValue is not a JsStr
-
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 JsValue is a JsStr that contains an Instant and satisfies the predicate
-
isLocalDate
default boolean isLocalDate(DateTimeFormatter formatter)
return true if this JsValue 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 JsValue 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 JsValue 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 formatterpredicate
- the given predicate- Returns:
- true if this JsValue 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 JsValue 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 JsValue 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 JsValue 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 formatterpredicate
- the given predicate- Returns:
- true if this JsValue 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)
-
isNotNull
default boolean isNotNull()
- Returns:
- true if this element is not null
-
isNull
default boolean isNull()
- Returns:
- true if this element is null
-
isNotNothing
default boolean isNotNothing()
- Returns:
- true if this element is not JsNothing
-
isNothing
default boolean isNothing()
- Returns:
- true if this element is JsNothing
-
isNotNumber
default boolean isNotNumber()
- Returns:
- true if this element is not a number
-
isNumber
default boolean isNumber()
- 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
-
-