public class TextBuilder extends Object implements Cloneable
This class defines a chained text/string builder
| Modifier and Type | Class and Description |
|---|---|
protected static class |
TextBuilder.StrBuf
A data structure used to store both character based content and it’s binary byte array.
|
| Modifier and Type | Field and Description |
|---|---|
protected StringBuilder |
__buffer
The internal buffer
|
protected TextBuilder |
__caller
The caller text builder.
|
| Constructor and Description |
|---|
TextBuilder()
Construct a root text builder
|
TextBuilder(TextBuilder caller)
Construct a chained text builder with a
caller() instance |
| Modifier and Type | Method and Description |
|---|---|
protected void |
__append(boolean b)
Append a boolean to internal buffer
|
protected void |
__append(byte b)
Append a byte to internal buffer
|
protected void |
__append(char c)
Append a char to internal buffer
|
protected void |
__append(double d)
Append a double to internal buffer
|
protected void |
__append(float f)
Append a float to internal buffer
|
protected void |
__append(int i)
Append an integer to internal buffer
|
protected void |
__append(long l)
Append a long to internal buffer
|
protected void |
__append(Object o)
Append a object to internal buffer or output (os or writer).
|
protected void |
__append(TextBuilder.StrBuf wrapper)
Append a
TextBuilder.StrBuf content into the buffer |
StringBuilder |
__getBuffer()
Alias of
buffer() |
void |
__setBuffer(StringBuilder buffer)
Set the internal buffer to this instance or if the
caller() exists, to the caller instance |
StringBuilder |
buffer()
Return the internal buffer of the text builder.
|
TextBuilder |
build()
Sub class could implement this method to append the generated source code to the buffer
|
protected ITemplate |
caller()
Return the caller in
ITemplate type |
TextBuilder |
clone(TextBuilder caller)
return a clone of this TextBuilder instance
|
StringBuilder |
getSelfOut()
Get the buffer out from this instance
|
TextBuilder |
np(Object o)
Print an new line break followed by an object
|
TextBuilder |
p(boolean b)
Print a boolean to internal buffer or output (os or writer)
|
TextBuilder |
p(byte b)
Print a byte to internal buffer or output (os or writer)
|
TextBuilder |
p(char c)
Print a char to internal buffer or output (os or writer)
|
TextBuilder |
p(double d)
Print a double to internal buffer or output (os or writer)
|
TextBuilder |
p(float f)
Print a float to internal buffer or output (os or writer)
|
TextBuilder |
p(int i)
Print an integer to internal buffer or output (os or writer)
|
TextBuilder |
p(long l)
Print a long to internal buffer or output (os or writer)
|
TextBuilder |
p(Object o)
Print a
Object to internal buffer or output (os or writer) null object will not be printed |
TextBuilder |
p(TextBuilder.StrBuf wrapper)
Print a
TextBuilder.StrBuf to internal buffer or output (os or writer) null object will not be printed |
TextBuilder |
p2t(Object o)
Print an object followed by two tabs
\t |
TextBuilder |
p2tn(Object o)
Print an object followed by 2 tabs
\t and an line break |
TextBuilder |
p3t(Object o)
Print an object followed by 3 tabs
\t |
TextBuilder |
p3tn(Object o)
Print an object followed by 3 tabs
\t and an line break |
TextBuilder |
p4t(Object o)
Print an object followed by 4 tabs
\t |
TextBuilder |
p4tn(Object o)
Print an object followed by 4 tabs
\t and an line break |
TextBuilder |
pn()
Print an new line break
|
TextBuilder |
pn(Object o)
Print an object followed by an new line break
|
TextBuilder |
pt(Object o)
Print an object followed by a tab
\t |
TextBuilder |
ptn(Object o)
Print an object followed by a tab
\t and an new line break |
void |
setSelfOut(StringBuilder buffer)
Set the internal buffer to this instance
|
String |
toString()
Return the internal buffer or caller’s internal buffer if it is null
|
protected StringBuilder __buffer
The internal buffer
protected TextBuilder __caller
The caller text builder. It is always an ITemplate instance
public TextBuilder()
Construct a root text builder
public TextBuilder(TextBuilder caller)
Construct a chained text builder with a caller() instance
caller - public StringBuilder buffer()
Return the internal buffer of the text builder. If the buffer of this instance is null then return the caller() instance’s buffer
StringBuilderpublic StringBuilder __getBuffer()
Alias of buffer()
StringBuilderpublic void __setBuffer(StringBuilder buffer)
Set the internal buffer to this instance or if the caller() exists, to the caller instance
buffer - public void setSelfOut(StringBuilder buffer)
Set the internal buffer to this instance
buffer - public StringBuilder getSelfOut()
Get the buffer out from this instance
StringBuilderprotected void __append(TextBuilder.StrBuf wrapper)
Append a TextBuilder.StrBuf content into the buffer
wrapper - public TextBuilder p(TextBuilder.StrBuf wrapper)
Print a TextBuilder.StrBuf to internal buffer or output (os or writer) null object will not be printed
wrapper - protected void __append(Object o)
Append a object to internal buffer or output (os or writer).
o - public final TextBuilder p(Object o)
Print a Object to internal buffer or output (os or writer) null object will not be printed
o - protected void __append(char c)
Append a char to internal buffer
c - public final TextBuilder p(char c)
Print a char to internal buffer or output (os or writer)
c - protected void __append(byte b)
Append a byte to internal buffer
b - public final TextBuilder p(byte b)
Print a byte to internal buffer or output (os or writer)
b - protected void __append(int i)
Append an integer to internal buffer
i - public final TextBuilder p(int i)
Print an integer to internal buffer or output (os or writer)
i - protected void __append(long l)
Append a long to internal buffer
l - public final TextBuilder p(long l)
Print a long to internal buffer or output (os or writer)
l - protected void __append(float f)
Append a float to internal buffer
f - public final TextBuilder p(float f)
Print a float to internal buffer or output (os or writer)
f - protected void __append(double d)
Append a double to internal buffer
d - public final TextBuilder p(double d)
Print a double to internal buffer or output (os or writer)
d - protected void __append(boolean b)
Append a boolean to internal buffer
b - public final TextBuilder p(boolean b)
Print a boolean to internal buffer or output (os or writer)
b - public final TextBuilder pn(Object o)
Print an object followed by an new line break
o - public final TextBuilder pn()
Print an new line break
public final TextBuilder np(Object o)
Print an new line break followed by an object
o - public TextBuilder pt(Object o)
Print an object followed by a tab \t
o - public TextBuilder ptn(Object o)
Print an object followed by a tab \t and an new line break
o - public TextBuilder p2t(Object o)
Print an object followed by two tabs \t
o - public TextBuilder p2tn(Object o)
Print an object followed by 2 tabs \t and an line break
o - public TextBuilder p3t(Object o)
Print an object followed by 3 tabs \t
o - public TextBuilder p3tn(Object o)
Print an object followed by 3 tabs \t and an line break
o - public TextBuilder p4t(Object o)
Print an object followed by 4 tabs \t
o - public TextBuilder p4tn(Object o)
Print an object followed by 4 tabs \t and an line break
o - public TextBuilder build()
Sub class could implement this method to append the generated source code to the buffer
public String toString()
Return the internal buffer or caller’s internal buffer if it is null
public TextBuilder clone(TextBuilder caller)
return a clone of this TextBuilder instance
caller - Copyright © 2017–2021 OSGL (Open Source General Library). All rights reserved.