Class CharsWrapper.Builder

  • All Implemented Interfaces:
    CharacterOutput, java.io.Closeable, java.io.Flushable, java.lang.Appendable, java.lang.AutoCloseable
    Enclosing class:
    CharsWrapper

    public static final class CharsWrapper.Builder
    extends java.io.Writer
    implements CharacterOutput
    Builder class for constructing CharsWrappers.
    • Field Summary

      • Fields inherited from class java.io.Writer

        lock
    • Constructor Summary

      Constructors 
      Constructor Description
      Builder​(int initialCapacity)
      Creates a new CharsWrapper's builder with the specified initial capacity.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      CharsWrapper.Builder append​(char c)  
      CharsWrapper.Builder append​(char... chars)
      Appends a char array to this builder.
      CharsWrapper.Builder append​(char[] chars, int begin, int end)
      Appends a portion of a char array to this builder.
      CharsWrapper.Builder append​(CharsWrapper cw)
      Appends a CharsWrapper to this builder.
      CharsWrapper.Builder append​(java.lang.CharSequence csq)  
      CharsWrapper.Builder append​(java.lang.CharSequence csq, int start, int end)  
      CharsWrapper.Builder append​(java.lang.Object o)
      Appends the string representation of an object to this builder.
      CharsWrapper.Builder append​(java.lang.Object... objects)
      Appends multiple objects to this builder.
      CharsWrapper.Builder append​(java.lang.String str)
      Appends a String to this builder.
      CharsWrapper.Builder append​(java.lang.String str, int begin, int end)
      Appends a String to this builder.
      CharsWrapper build()
      Builds a CharsWrapper with the content of this builder.
      CharsWrapper build​(int start)
      Builds a CharsWrapper with the content of this builder.
      CharsWrapper build​(int start, int end)
      Builds a CharsWrapper with the content of this builder.
      void close()  
      void compact()
      Compacts this builder, minimizing its size in memory.
      CharsWrapper copyAndBuild()
      Builds a CharsWrapper with a copy of the content of this builder.
      CharsWrapper copyAndBuild​(int start)
      Builds a CharsWrapper with a copy of the content of this builder.
      CharsWrapper copyAndBuild​(int start, int end)
      Builds a CharsWrapper with a copy of the content of this builder.
      void flush()  
      char get​(int index)  
      char[] getChars()
      Gets the underlying array of this builder.
      int length()
      Gets the length (number of characters) of this builder.
      void set​(int index, char ch)
      Sets the value of a character.
      java.lang.String toString()  
      java.lang.String toString​(int start)  
      java.lang.String toString​(int start, int end)  
      void write​(char c)
      Writes a character.
      void write​(char... cbuf)
      Writes an array of characters.
      void write​(char[] chars, int offset, int length)
      Writes a portion of an array of characters.
      void write​(int c)  
      void write​(CharsWrapper cw)
      Writes all the characters in the given CharsWrapper.
      void write​(java.lang.String str)
      Writes all the characters in the given String.
      void write​(java.lang.String s, int offset, int length)
      Writes a portion of a String.
      • Methods inherited from class java.io.Writer

        nullWriter
      • Methods inherited from class java.lang.Object

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

      • Builder

        public Builder​(int initialCapacity)
        Creates a new CharsWrapper's builder with the specified initial capacity. If the specified capacity is less than 2 then 2 will be used instead.
        Parameters:
        initialCapacity - the initial capacity
    • Method Detail

      • append

        public CharsWrapper.Builder append​(char c)
        Specified by:
        append in interface java.lang.Appendable
        Overrides:
        append in class java.io.Writer
      • append

        public CharsWrapper.Builder append​(java.lang.CharSequence csq)
        Specified by:
        append in interface java.lang.Appendable
        Overrides:
        append in class java.io.Writer
      • append

        public CharsWrapper.Builder append​(java.lang.CharSequence csq,
                                           int start,
                                           int end)
        Specified by:
        append in interface java.lang.Appendable
        Overrides:
        append in class java.io.Writer
      • append

        public CharsWrapper.Builder append​(char... chars)
        Appends a char array to this builder.
        Parameters:
        chars - the array to append, not null
        Returns:
        this builder
      • append

        public CharsWrapper.Builder append​(char[] chars,
                                           int begin,
                                           int end)
        Appends a portion of a char array to this builder.
        Parameters:
        chars - the array to append, not null
        begin - the index to start at
        end - the index to stop at (exclusive)
        Returns:
        this builder
      • append

        public CharsWrapper.Builder append​(java.lang.String str)
        Appends a String to this builder.
        Parameters:
        str - the String to append, not null
        Returns:
        this builder
      • append

        public CharsWrapper.Builder append​(java.lang.String str,
                                           int begin,
                                           int end)
        Appends a String to this builder.
        Parameters:
        str - the String to append, not null
        begin - the index to start at
        end - the index to stop at (exclusive)
        Returns:
        this builder
      • append

        public CharsWrapper.Builder append​(CharsWrapper cw)
        Appends a CharsWrapper to this builder.
        Parameters:
        cw - the wrapper to append, not null
        Returns:
        this builder
      • append

        public CharsWrapper.Builder append​(java.lang.Object o)
        Appends the string representation of an object to this builder. This is equivalent to append(String.valueOf(o)).
        Parameters:
        o - the object to append, may be null
        Returns:
        this builder
      • append

        public CharsWrapper.Builder append​(java.lang.Object... objects)
        Appends multiple objects to this builder. This is equivalent to calling append(String.valueOf(o)) in a loop.
        Parameters:
        objects - the objects to append, may be null
        Returns:
        this builder
      • flush

        public void flush()
        Specified by:
        flush in interface java.io.Flushable
        Specified by:
        flush in class java.io.Writer
      • close

        public void close()
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
        Specified by:
        close in class java.io.Writer
      • write

        public void write​(int c)
        Overrides:
        write in class java.io.Writer
      • write

        public void write​(char c)
        Description copied from interface: CharacterOutput
        Writes a character.
        Specified by:
        write in interface CharacterOutput
        Parameters:
        c - the character to write
      • write

        public void write​(char... cbuf)
        Description copied from interface: CharacterOutput
        Writes an array of characters.
        Specified by:
        write in interface CharacterOutput
        Overrides:
        write in class java.io.Writer
        Parameters:
        cbuf - the characters to write
      • write

        public void write​(char[] chars,
                          int offset,
                          int length)
        Description copied from interface: CharacterOutput
        Writes a portion of an array of characters.
        Specified by:
        write in interface CharacterOutput
        Specified by:
        write in class java.io.Writer
        Parameters:
        chars - the characters to write
        offset - the index to start at
        length - the number of characters to write
      • write

        public void write​(java.lang.String str)
        Description copied from interface: CharacterOutput
        Writes all the characters in the given String.
        Specified by:
        write in interface CharacterOutput
        Overrides:
        write in class java.io.Writer
        Parameters:
        str - the string to write
      • write

        public void write​(java.lang.String s,
                          int offset,
                          int length)
        Description copied from interface: CharacterOutput
        Writes a portion of a String.
        Specified by:
        write in interface CharacterOutput
        Overrides:
        write in class java.io.Writer
        Parameters:
        s - the string to write
        offset - the index to start at
        length - the number of characters to write
      • write

        public void write​(CharsWrapper cw)
        Description copied from interface: CharacterOutput
        Writes all the characters in the given CharsWrapper.
        Specified by:
        write in interface CharacterOutput
        Parameters:
        cw - the CharsWrapper to write
      • length

        public int length()
        Gets the length (number of characters) of this builder.
        Returns:
        the length of this builder
      • getChars

        public char[] getChars()
        Gets the underlying array of this builder. Please note that its size may not be equal to the length of the builder.
        Returns:
        the array containing the characters of this builder.
      • get

        public char get​(int index)
        Parameters:
        index - the character's index (the first character is at index 0)
        Returns:
        the character at the specified index
      • set

        public void set​(int index,
                        char ch)
        Sets the value of a character.
        Parameters:
        index - the character's index (the first character is at index 0)
        ch - the character value to set
      • compact

        public void compact()
        Compacts this builder, minimizing its size in memory.
      • build

        public CharsWrapper build()
        Builds a CharsWrapper with the content of this builder. The builder's content is directly used to create a new CharsWrapper.
        Returns:
        a new CharsWrapper with the content of this builder
      • build

        public CharsWrapper build​(int start)
        Builds a CharsWrapper with the content of this builder. The builder's content is directly used to create a new CharsWrapper.
        Parameters:
        start - index of the 1st character to use
        Returns:
        a new CharsWrapper with the content of this builder
      • build

        public CharsWrapper build​(int start,
                                  int end)
        Builds a CharsWrapper with the content of this builder. The builder's content is directly used to create a new CharsWrapper.
        Parameters:
        start - index of the 1st character to use
        end - index after the last character to use
        Returns:
        a new CharsWrapper with the content of this builder
      • copyAndBuild

        public CharsWrapper copyAndBuild()
        Builds a CharsWrapper with a copy of the content of this builder.
        Returns:
        a new CharsWrapper with a copy of the content of this builder
      • copyAndBuild

        public CharsWrapper copyAndBuild​(int start)
        Builds a CharsWrapper with a copy of the content of this builder.
        Parameters:
        start - index of the 1st character to use
        Returns:
        a new CharsWrapper with a copy of the content of this builder
      • copyAndBuild

        public CharsWrapper copyAndBuild​(int start,
                                         int end)
        Builds a CharsWrapper with a copy of the content of this builder.
        Parameters:
        start - index of the 1st character to use
        end - index after the last character to use
        Returns:
        a new CharsWrapper with a copy of the content of this builder
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • toString

        public java.lang.String toString​(int start)
      • toString

        public java.lang.String toString​(int start,
                                         int end)