Package jsonvalues

Class JsStr

All Implemented Interfaces:
Comparable<JsStr>, JsValue

public final class JsStr extends JsPrimitive implements Comparable<JsStr>
Represents an immutable JSON string.
  • Field Details

    • prism

      public static final fun.optic.Prism<JsValue,String> prism
      Prism between the sum type JsValue and JsStr. Allows conversion between JsValue and JsStr using a prism.
    • base64Prism

      public static final fun.optic.Prism<String,byte[]> base64Prism
      Prism for converting between Base64-encoded strings and byte arrays.
    • instantPrism

      public static final fun.optic.Prism<String,Instant> instantPrism
      Prism for converting between ISO-8601 formatted strings and Instant objects.
    • value

      public final String value
      The string value.
  • Method Details

    • of

      public static JsStr of(String str)
      Static factory method to create a JsStr from a string.
      Parameters:
      str - the string
      Returns:
      a new JsStr
    • toJsPrimitive

      public JsPrimitive toJsPrimitive()
      Description copied from interface: JsValue
      Returns this JsValue as a JsPrimitive.
      Specified by:
      toJsPrimitive in interface JsValue
      Returns:
      This JsValue as a JsPrimitive.
    • isStr

      public boolean isStr()
      Description copied from interface: JsValue
      Returns true if this JsValue is a JsStr.
      Specified by:
      isStr in interface JsValue
      Returns:
      True if this JsValue is a JsStr.
    • compareTo

      public int compareTo(JsStr o)
      Compares two JsStr objects lexicographically.
      Specified by:
      compareTo in interface Comparable<JsStr>
      See Also:
    • test

      public boolean test(Predicate<String> predicate)
      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.
      Overrides:
      hashCode in class Object
      Returns:
      the hashcode of this JsStr
    • equals

      public boolean equals(Object that)
      Indicates whether some other object is "equal to" this JSON string.
      Overrides:
      equals in class Object
      Parameters:
      that - the reference object with which to compare
      Returns:
      true if that is a JsStr with the same value as this JsStr. If that 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

      public String toString()
      Returns the string representation of this JSON string which is its value quoted.
      Overrides:
      toString in class Object
      Returns:
      the value quoted
    • map

      public JsStr map(UnaryOperator<String> fn)
      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.
      Specified by:
      isBinary in 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.
      Specified by:
      isInstant in interface JsValue
      Returns:
      True if this JsValue is a JsInstant or a JsString with a value that is a date formatted in ISO-8601.