Class Spacer


  • public class Spacer
    extends java.lang.Object
    Efficiently writes strings of spaces.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private int n  
    • Constructor Summary

      Constructors 
      Constructor Description
      Spacer()
      Creates a Spacer with zero spaces.
      Spacer​(int n)
      Creates a Spacer with a given number of spaces.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      Spacer add​(int n)
      Increases the current number of spaces by n.
      int get()
      Returns the current number of spaces.
      java.lang.String padRight​(java.lang.String string)
      Returns a string that is padded on the right with spaces to the current length.
      Spacer set​(int n)
      Sets the current number of spaces.
      java.lang.StringBuilder spaces​(java.lang.StringBuilder buf)
      Appends current number of spaces to a StringBuilder.
      Spacer subtract​(int n)
      Reduces the current number of spaces by n.
      java.lang.String toString()
      Returns a string of the current number of spaces.
      • Methods inherited from class java.lang.Object

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

      • n

        private int n
    • Constructor Detail

      • Spacer

        public Spacer()
        Creates a Spacer with zero spaces.
      • Spacer

        public Spacer​(int n)
        Creates a Spacer with a given number of spaces.
    • Method Detail

      • set

        public Spacer set​(int n)
        Sets the current number of spaces.
      • get

        public int get()
        Returns the current number of spaces.
      • add

        public Spacer add​(int n)
        Increases the current number of spaces by n.
      • subtract

        public Spacer subtract​(int n)
        Reduces the current number of spaces by n.
      • toString

        public java.lang.String toString()
        Returns a string of the current number of spaces.
        Overrides:
        toString in class java.lang.Object
      • spaces

        public java.lang.StringBuilder spaces​(java.lang.StringBuilder buf)
        Appends current number of spaces to a StringBuilder.
      • padRight

        public java.lang.String padRight​(java.lang.String string)
        Returns a string that is padded on the right with spaces to the current length.