Interface JsonString
A JSON string in a representation that the model chooses.
JsonModel.stringValue(Object) returns a JsonString. The evaluator reads a string only
from start to end, one Unicode scalar value at a time: to compare strings, to count them for
length(), and to match regexps. So a model over UTF-8 bytes can give its strings without a
copy.
For a Java String, use of(String). It does not copy the string:
JsonString name = JsonString.of("Wilhelm");
-
Method Summary
Modifier and TypeMethodDescriptionstatic intcompare(JsonString a, JsonString b) Compares two strings by their Unicode scalar values (RFC 9535, Section 2.3.5.2.2).static StringcopyOf(JsonString string) Returns the value of a string as a JavaString.static booleanequal(JsonString a, JsonString b) Returns true if two strings have the same scalar values.static inthash(JsonString string) Returns a hash code of the scalar values of a string.static intlength(JsonString string) Returns the number of Unicode scalar values in a string, aslength()requires (RFC 9535, Section 2.4.4).static JsonStringReturns a string with the value of a JavaString, without a copy.Returns the Unicode scalar values of the string, in order.
-
Method Details
-
scalarValues
PrimitiveIterator.OfInt scalarValues()Returns the Unicode scalar values of the string, in order.
Each call returns a new iterator that starts at the first scalar value.
- Returns:
- the scalar values
-
of
Returns a string with the value of a JavaString, without a copy.- Parameters:
value- the value- Returns:
- the string
-
copyOf
Returns the value of a string as a Java
String.For a string from
of(String), this returns the sameString. For other strings, it makes a copy.- Parameters:
string- a string- Returns:
- the value as a
String
-
compare
Compares two strings by their Unicode scalar values (RFC 9535, Section 2.3.5.2.2).
This is not the order of
String.compareTo(String), which compares UTF-16 code units.- Parameters:
a- a stringb- another string- Returns:
- a negative value, zero, or a positive value if
ais less than, equal to, or greater thanb
-
equal
Returns true if two strings have the same scalar values.- Parameters:
a- a stringb- another string- Returns:
- true if the strings are equal
-
hash
Returns a hash code of the scalar values of a string.
The result is the same as
String.hashCode()ofcopyOf(JsonString), but it makes no copy. So equal strings in different representations have the same hash code.- Parameters:
string- a string- Returns:
- the hash code
-
length
Returns the number of Unicode scalar values in a string, aslength()requires (RFC 9535, Section 2.4.4).- Parameters:
string- a string- Returns:
- the number of scalar values
-