Package jsonvalues
Class JsStr
java.lang.Object
jsonvalues.JsPrimitive
jsonvalues.JsStr
- All Implemented Interfaces:
Comparable<JsStr>
,JsValue
Represents an immutable JSON string.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final fun.optic.Prism<String,
byte[]> Prism for converting between Base64-encoded strings and byte arrays.Prism for converting between ISO-8601 formatted strings and Instant objects.Prism between the sum type JsValue and JsStr.final String
The string value. -
Method Summary
Modifier and TypeMethodDescriptionint
Compares twoJsStr
objects lexicographically.boolean
Indicates whether some other object is "equal to" this JSON string.int
hashCode()
Returns the hashcode of this JSON string.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.boolean
Returns true if this JsValue is a JsInstant or a JsString with a value that is a date formatted in ISO-8601.boolean
isStr()
Returns true if this JsValue is a JsStr.map
(UnaryOperator<String> fn) Maps this JsStr into another one.static JsStr
Static factory method to create a JsStr from a string.boolean
Tests this JsStr on a predicate.Returns this JsValue as a JsPrimitive.toString()
Returns the string representation of this JSON string which is its value quoted.Methods inherited from class jsonvalues.JsPrimitive
isJson, isPrimitive
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface jsonvalues.JsValue
ifNothing, ifNull, isArray, isArray, isBigDec, isBigDec, isBigInt, isBigInt, isBool, isDecimal, isDouble, isDouble, isFalse, isInstant, isInt, isInt, isIntegral, isJson, isLong, isLong, isNothing, isNotNothing, isNotNull, isNotNumber, isNull, isNumber, isObj, isObj, isSameType, isStr, isTrue, toJsArray, toJsBigDec, toJsBigInt, toJsBinary, toJsBool, toJsDouble, toJsInstant, toJsInt, toJsLong, toJsNumber, toJsObj, toJson, toJsStr
-
Field Details
-
prism
Prism between the sum type JsValue and JsStr. Allows conversion between JsValue and JsStr using a prism. -
base64Prism
Prism for converting between Base64-encoded strings and byte arrays. -
instantPrism
Prism for converting between ISO-8601 formatted strings and Instant objects. -
value
The string value.
-
-
Method Details
-
of
Static factory method to create a JsStr from a string.- Parameters:
str
- the string- Returns:
- a new JsStr
-
toJsPrimitive
Description copied from interface:JsValue
Returns this JsValue as a JsPrimitive.- Specified by:
toJsPrimitive
in interfaceJsValue
- Returns:
- This JsValue as a JsPrimitive.
-
isStr
public boolean isStr()Description copied from interface:JsValue
Returns true if this JsValue is a JsStr. -
compareTo
Compares twoJsStr
objects lexicographically.- Specified by:
compareTo
in interfaceComparable<JsStr>
- See Also:
-
test
Tests this JsStr on a predicate.- Parameters:
predicate
- the predicate- Returns:
- true if this string satisfies the predicate
-
hashCode
public int hashCode()Returns the hashcode of this JSON string. -
equals
Indicates whether some other object is "equal to" this JSON string.- Overrides:
equals
in classObject
- Parameters:
that
- the reference object with which to compare- Returns:
- true if
that
is a JsStr with the same value asthis
JsStr. Ifthat
is a JsInstant or JsBinary, equality is based on their conversion to strings: - JsInstant is considered equal if its string representation (ISO-8601 format) matches the value of this JsStr. - JsBinary is considered equal if its Base64-encoded string representation matches the value of this JsStr.
-
toString
Returns the string representation of this JSON string which is its value quoted. -
map
Maps this JsStr into another one.- Parameters:
fn
- the mapping function- Returns:
- a new JsStr
-
isBinary
public boolean isBinary()Description copied from interface:JsValue
Returns true if this JsValue is a JsBinary or a JsString with a value that is an array of bytes encoded in base64. -
isInstant
public boolean isInstant()Description copied from interface:JsValue
Returns true if this JsValue is a JsInstant or a JsString with a value that is a date formatted in ISO-8601.
-