Class Spaces


  • public class Spaces
    extends java.lang.Object
    Utilities for creating strings of spaces.
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      private static class  Spaces.SpaceList
      List whose ith entry is a string consisting of i spaces.
      private static class  Spaces.SpaceString
      A string of spaces.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.CharSequence MAX
      The longest possible string of spaces.
      private static java.util.List<java.lang.String> SPACE_LIST
      It doesn't look like this list is ever updated.
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private Spaces()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.io.PrintWriter append​(java.io.PrintWriter pw, int n)
      Appends n spaces to a PrintWriter.
      static java.io.StringWriter append​(java.io.StringWriter pw, int n)
      Appends n spaces to a StringWriter.
      static java.lang.Appendable append​(java.lang.Appendable buf, int n)
      Appends n spaces to an Appendable.
      static java.lang.StringBuffer append​(java.lang.StringBuffer buf, int n)
      Appends n spaces to a StringBuffer.
      static java.lang.StringBuilder append​(java.lang.StringBuilder buf, int n)
      Appends n spaces to a StringBuilder.
      static java.lang.String of​(int n)
      Returns a string of n spaces.
      static java.lang.String padLeft​(java.lang.String string, int n)
      Returns a string that is padded on the left with spaces to the given length.
      static java.lang.String padRight​(java.lang.String string, int n)
      Returns a string that is padded on the right with spaces to the given length.
      static java.lang.CharSequence sequence​(int n)
      Creates a sequence of n spaces.
      • Methods inherited from class java.lang.Object

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

      • SPACE_LIST

        private static final java.util.List<java.lang.String> SPACE_LIST
        It doesn't look like this list is ever updated. But it is - when a call to to Spaces.SpaceList.get(int) causes an IndexOutOfBoundsException.
      • MAX

        public static final java.lang.CharSequence MAX
        The longest possible string of spaces. Fine as long as you don't try to print it.

        Use with StringBuilder.append(CharSequence, int, int) to append spaces without doing memory allocation.

    • Constructor Detail

      • Spaces

        private Spaces()
    • Method Detail

      • sequence

        public static java.lang.CharSequence sequence​(int n)
        Creates a sequence of n spaces.
      • of

        public static java.lang.String of​(int n)
        Returns a string of n spaces.
      • append

        public static java.lang.Appendable append​(java.lang.Appendable buf,
                                                  int n)
                                           throws java.io.IOException
        Appends n spaces to an Appendable.
        Throws:
        java.io.IOException
      • append

        public static java.io.PrintWriter append​(java.io.PrintWriter pw,
                                                 int n)
        Appends n spaces to a PrintWriter.
      • append

        public static java.io.StringWriter append​(java.io.StringWriter pw,
                                                  int n)
        Appends n spaces to a StringWriter.
      • append

        public static java.lang.StringBuilder append​(java.lang.StringBuilder buf,
                                                     int n)
        Appends n spaces to a StringBuilder.
      • append

        public static java.lang.StringBuffer append​(java.lang.StringBuffer buf,
                                                    int n)
        Appends n spaces to a StringBuffer.
      • padRight

        public static java.lang.String padRight​(java.lang.String string,
                                                int n)
        Returns a string that is padded on the right with spaces to the given length.
      • padLeft

        public static java.lang.String padLeft​(java.lang.String string,
                                               int n)
        Returns a string that is padded on the left with spaces to the given length.