Class IndentWriter

java.lang.Object
dev.roanh.gmark.util.IndentWriter

public class IndentWriter extends Object
Writes that prefixes all lines with a configurable number of spaces and can be converted to a string once all content has been written.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private static final char[]
    Buffer of white space characters for copying.
    private final StringBuilder
    The context of this writer (all written lines).
    private int
    The current indent (in spaces).
    private boolean
    True if the next write call is the start of a new line and should thus be prefixed with spaces.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructs a new indent writer with an indent of 0.
    IndentWriter(int indent)
    Constructs a new indent writer with the given indent.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Decreases the current indent by the given number of spaces.
    int
    Gets the current writer indent.
    void
    Increases the current indent by the given number of spaces.
    void
    print(int i)
    Adds the given integer to this writer.
    void
    Adds the given string to this writer.
    void
    Writes a line break.
    void
    println(int indentDecrease, String str)
    Decreases the current indent by the given amount and then adds the given string to this writer and adds a line break.
    void
    Adds the given string to this writer and adds a line break.
    void
    println(String str, int indentIncrease)
    Adds the given string to this writer and adds a line break.
    void
    setIndent(int n)
    Sets the indent to the given number of spaces.
     

    Methods inherited from class java.lang.Object

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

    • BUFFER

      private static final char[] BUFFER
      Buffer of white space characters for copying.
    • content

      private final StringBuilder content
      The context of this writer (all written lines).
    • indent

      private int indent
      The current indent (in spaces).
    • newLine

      private boolean newLine
      True if the next write call is the start of a new line and should thus be prefixed with spaces.
  • Constructor Details

    • IndentWriter

      public IndentWriter()
      Constructs a new indent writer with an indent of 0.
      See Also:
    • IndentWriter

      public IndentWriter(int indent)
      Constructs a new indent writer with the given indent.
      Parameters:
      indent - The writer indent.
  • Method Details

    • getIndent

      public int getIndent()
      Gets the current writer indent.
      Returns:
      The indent (in spaces).
    • print

      public void print(String str)
      Adds the given string to this writer.
      Parameters:
      str - The string to print.
    • println

      public void println(String str)
      Adds the given string to this writer and adds a line break.
      Parameters:
      str - The string to print.
    • println

      public void println()
      Writes a line break.
    • println

      public void println(String str, int indentIncrease)
      Adds the given string to this writer and adds a line break. After that increases the current indent by the given amount.
      Parameters:
      str - The string to print.
      indentIncrease - The amount to increase the indent by.
    • println

      public void println(int indentDecrease, String str)
      Decreases the current indent by the given amount and then adds the given string to this writer and adds a line break.
      Parameters:
      str - The string to print.
      indentDecrease - The amount to decrease the indent by.
    • increaseIndent

      public void increaseIndent(int n)
      Increases the current indent by the given number of spaces.
      Parameters:
      n - The number of spaces to increase the indent by.
    • decreaseIndent

      public void decreaseIndent(int n)
      Decreases the current indent by the given number of spaces.
      Parameters:
      n - The number of spaces to decrease the indent by.
    • setIndent

      public void setIndent(int n)
      Sets the indent to the given number of spaces.
      Parameters:
      n - The new indent.
    • print

      public void print(int i)
      Adds the given integer to this writer.
      Parameters:
      i - The integer to print.
    • toString

      public String toString()
      Overrides:
      toString in class Object