Class CharsWrapper.Builder
- java.lang.Object
-
- java.io.Writer
-
- com.electronwill.nightconfig.core.io.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.
-
-
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.Builderappend(char c)CharsWrapper.Builderappend(char... chars)Appends a char array to this builder.CharsWrapper.Builderappend(char[] chars, int begin, int end)Appends a portion of a char array to this builder.CharsWrapper.Builderappend(CharsWrapper cw)Appends a CharsWrapper to this builder.CharsWrapper.Builderappend(java.lang.CharSequence csq)CharsWrapper.Builderappend(java.lang.CharSequence csq, int start, int end)CharsWrapper.Builderappend(java.lang.Object o)Appends the string representation of an object to this builder.CharsWrapper.Builderappend(java.lang.Object... objects)Appends multiple objects to this builder.CharsWrapper.Builderappend(java.lang.String str)Appends a String to this builder.CharsWrapper.Builderappend(java.lang.String str, int begin, int end)Appends a String to this builder.CharsWrapperbuild()Builds a CharsWrapper with the content of this builder.CharsWrapperbuild(int start)Builds a CharsWrapper with the content of this builder.CharsWrapperbuild(int start, int end)Builds a CharsWrapper with the content of this builder.voidclose()voidcompact()Compacts this builder, minimizing its size in memory.CharsWrappercopyAndBuild()Builds a CharsWrapper with a copy of the content of this builder.CharsWrappercopyAndBuild(int start)Builds a CharsWrapper with a copy of the content of this builder.CharsWrappercopyAndBuild(int start, int end)Builds a CharsWrapper with a copy of the content of this builder.voidflush()charget(int index)char[]getChars()Gets the underlying array of this builder.intlength()Gets the length (number of characters) of this builder.voidset(int index, char ch)Sets the value of a character.java.lang.StringtoString()java.lang.StringtoString(int start)java.lang.StringtoString(int start, int end)voidwrite(char c)Writes a character.voidwrite(char... cbuf)Writes an array of characters.voidwrite(char[] chars, int offset, int length)Writes a portion of an array of characters.voidwrite(int c)voidwrite(CharsWrapper cw)Writes all the characters in the given CharsWrapper.voidwrite(java.lang.String str)Writes all the characters in the given String.voidwrite(java.lang.String s, int offset, int length)Writes a portion of a String.
-
-
-
Method Detail
-
append
public CharsWrapper.Builder append(char c)
- Specified by:
appendin interfacejava.lang.Appendable- Overrides:
appendin classjava.io.Writer
-
append
public CharsWrapper.Builder append(java.lang.CharSequence csq)
- Specified by:
appendin interfacejava.lang.Appendable- Overrides:
appendin classjava.io.Writer
-
append
public CharsWrapper.Builder append(java.lang.CharSequence csq, int start, int end)
- Specified by:
appendin interfacejava.lang.Appendable- Overrides:
appendin classjava.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 nullbegin- the index to start atend- 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 nullbegin- the index to start atend- 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 toappend(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 callingappend(String.valueOf(o))in a loop.- Parameters:
objects- the objects to append, may be null- Returns:
- this builder
-
flush
public void flush()
- Specified by:
flushin interfacejava.io.Flushable- Specified by:
flushin classjava.io.Writer
-
close
public void close()
- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Specified by:
closein classjava.io.Writer
-
write
public void write(int c)
- Overrides:
writein classjava.io.Writer
-
write
public void write(char c)
Description copied from interface:CharacterOutputWrites a character.- Specified by:
writein interfaceCharacterOutput- Parameters:
c- the character to write
-
write
public void write(char... cbuf)
Description copied from interface:CharacterOutputWrites an array of characters.- Specified by:
writein interfaceCharacterOutput- Overrides:
writein classjava.io.Writer- Parameters:
cbuf- the characters to write
-
write
public void write(char[] chars, int offset, int length)Description copied from interface:CharacterOutputWrites a portion of an array of characters.- Specified by:
writein interfaceCharacterOutput- Specified by:
writein classjava.io.Writer- Parameters:
chars- the characters to writeoffset- the index to start atlength- the number of characters to write
-
write
public void write(java.lang.String str)
Description copied from interface:CharacterOutputWrites all the characters in the given String.- Specified by:
writein interfaceCharacterOutput- Overrides:
writein classjava.io.Writer- Parameters:
str- the string to write
-
write
public void write(java.lang.String s, int offset, int length)Description copied from interface:CharacterOutputWrites a portion of a String.- Specified by:
writein interfaceCharacterOutput- Overrides:
writein classjava.io.Writer- Parameters:
s- the string to writeoffset- the index to start atlength- the number of characters to write
-
write
public void write(CharsWrapper cw)
Description copied from interface:CharacterOutputWrites all the characters in the given CharsWrapper.- Specified by:
writein interfaceCharacterOutput- 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 useend- 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 useend- 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:
toStringin classjava.lang.Object
-
toString
public java.lang.String toString(int start)
-
toString
public java.lang.String toString(int start, int end)
-
-