Class JsonText

java.lang.Object
uk.blankaspect.common.json.JsonText

public class JsonText extends Object
This class implements a buffer for JSON text. Text is added to the buffer with the methods of this class.

The JSON text consists of a sequence of lines. A line consists of a sequence of spans; each span is associated with a token. The lines and spans may be extracted from the buffer.

  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    class 
    This class encapsulates a line of text, which consists of a sequence of spans.
    static final record 
    This record encapsulates a subsequence of the text of a JsonText.Line that is associated with a JSON token.
    static enum 
    This is an enumeration of the tokens that may be associated with elements of JSON text.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a new instance of JSON text.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    append(char ch, JsonText.Token token)
    Appends the specified character to this JSON text, and adds a new span for the character that associates it with the specified token.
    void
    Appends the specified text to this JSON text, and adds a new span for the text that associates it with the specified token.
    If this JSON text is not empty, a line-feed character (U+000A) is appended to it and a new span for it is added to the current line.
    void
    Appends a single space character (U+0020) to this JSON text, and adds a new span for the space.
    void
    appendSpaces(int numSpaces)
    Appends the specified number of space characters (U+0020) to this JSON text, and adds a new span for the spaces.
    Returns the buffer that contains the JSON text.
    Returns the last line of this JSON text within the buffer.
    int
    Returns the length of the last line of this JSON text.
    Returns a list of the lines of this JSON text within the buffer.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • JsonText

      public JsonText()
      Creates a new instance of JSON text.
  • Method Details

    • toString

      public String toString()
      Overrides:
      toString in class Object
    • buffer

      public StringBuilder buffer()
      Returns the buffer that contains the JSON text.
      Returns:
      the buffer that contains the JSON text.
    • lines

      public List<JsonText.Line> lines()
      Returns a list of the lines of this JSON text within the buffer.
      Returns:
      a list of the lines of this JSON text within the buffer.
    • lastLine

      public JsonText.Line lastLine()
      Returns the last line of this JSON text within the buffer.
      Returns:
      the last line of this JSON text within the buffer, or null if there are no lines.
    • lastLineLength

      public int lastLineLength()
      Returns the length of the last line of this JSON text.
      Returns:
      the length of the last line of JSON text, or 0 if there are no lines.
    • append

      public void append(char ch, JsonText.Token token)
      Appends the specified character to this JSON text, and adds a new span for the character that associates it with the specified token.
      Parameters:
      ch - the character that will be appended to this JSON text.
      token - the token with which ch will be associated in the span that is created for it.
    • append

      public void append(CharSequence text, JsonText.Token token)
      Appends the specified text to this JSON text, and adds a new span for the text that associates it with the specified token.
      Parameters:
      text - the text that will be appended to this JSON text.
      token - the token with which text will be associated in the span that is created for it.
    • appendSpace

      public void appendSpace()
      Appends a single space character (U+0020) to this JSON text, and adds a new span for the space.
    • appendSpaces

      public void appendSpaces(int numSpaces)
      Appends the specified number of space characters (U+0020) to this JSON text, and adds a new span for the spaces.
      Parameters:
      numSpaces - the number of space characters that will be appended to this JSON text.
    • appendNewLine

      public JsonText.Line appendNewLine()
      If this JSON text is not empty, a line-feed character (U+000A) is appended to it and a new span for it is added to the current line. A new line is created and added to the list of lines, and the new line is returned.
      Returns:
      a new line that was added to the list of lines.