org.rythmengine.utils
Class TextBuilder

java.lang.Object
  extended by org.rythmengine.utils.TextBuilder
All Implemented Interfaces:
Cloneable
Direct Known Subclasses:
CodeBuilder, TemplateBuilder, Token

public class TextBuilder
extends Object
implements Cloneable

This class defines a chained text/string builder

Author:
luog

Nested Class Summary
protected static class TextBuilder.StrBuf
          A data structure used to store both character based content and it's binary byte array.
 
Field Summary
protected  StringBuilder __buffer
          The internal buffer
protected  TextBuilder __caller
          The caller text builder.
 
Constructor Summary
TextBuilder()
          Construct a root text builder
TextBuilder(TextBuilder caller)
          Construct a chained text builder with a caller() instance
 
Method Summary
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
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

__buffer

protected StringBuilder __buffer
The internal buffer


__caller

protected TextBuilder __caller
The caller text builder. It is always an ITemplate instance

Constructor Detail

TextBuilder

public TextBuilder()
Construct a root text builder


TextBuilder

public TextBuilder(TextBuilder caller)
Construct a chained text builder with a caller() instance

Parameters:
caller -
Method Detail

buffer

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

Returns:
a StringBuilder

caller

protected ITemplate caller()
Return the caller in ITemplate type

Returns:
a ITemplate

__getBuffer

public StringBuilder __getBuffer()
Alias of buffer()

Returns:
buffer as StringBuilder

__setBuffer

public void __setBuffer(StringBuilder buffer)
Set the internal buffer to this instance or if the caller() exists, to the caller instance

Parameters:
buffer -

setSelfOut

public void setSelfOut(StringBuilder buffer)
Set the internal buffer to this instance

Parameters:
buffer -

getSelfOut

public StringBuilder getSelfOut()
Get the buffer out from this instance

Returns:
a StringBuilder

__append

protected void __append(TextBuilder.StrBuf wrapper)
Append a TextBuilder.StrBuf content into the buffer

Parameters:
wrapper -

p

public TextBuilder p(TextBuilder.StrBuf wrapper)
Print a TextBuilder.StrBuf to internal buffer or output (os or writer) null object will not be printed

Parameters:
wrapper -
Returns:
this builder

__append

protected void __append(Object o)
Append a object to internal buffer or output (os or writer).

Parameters:
o -

p

public final TextBuilder p(Object o)
Print a Object to internal buffer or output (os or writer) null object will not be printed

Parameters:
o -
Returns:
this builder

__append

protected void __append(char c)
Append a char to internal buffer

Parameters:
c -

p

public final TextBuilder p(char c)
Print a char to internal buffer or output (os or writer)

Parameters:
c -
Returns:
this builder

__append

protected void __append(byte b)
Append a byte to internal buffer

Parameters:
b -

p

public final TextBuilder p(byte b)
Print a byte to internal buffer or output (os or writer)

Parameters:
b -
Returns:
this builder

__append

protected void __append(int i)
Append an integer to internal buffer

Parameters:
i -

p

public final TextBuilder p(int i)
Print an integer to internal buffer or output (os or writer)

Parameters:
i -
Returns:
this builder

__append

protected void __append(long l)
Append a long to internal buffer

Parameters:
l -

p

public final TextBuilder p(long l)
Print a long to internal buffer or output (os or writer)

Parameters:
l -
Returns:
this builder

__append

protected void __append(float f)
Append a float to internal buffer

Parameters:
f -

p

public final TextBuilder p(float f)
Print a float to internal buffer or output (os or writer)

Parameters:
f -
Returns:
this builder

__append

protected void __append(double d)
Append a double to internal buffer

Parameters:
d -

p

public final TextBuilder p(double d)
Print a double to internal buffer or output (os or writer)

Parameters:
d -
Returns:
this builder

__append

protected void __append(boolean b)
Append a boolean to internal buffer

Parameters:
b -

p

public final TextBuilder p(boolean b)
Print a boolean to internal buffer or output (os or writer)

Parameters:
b -
Returns:
this builder

pn

public final TextBuilder pn(Object o)
Print an object followed by an new line break

Parameters:
o -
Returns:
this builder

pn

public final TextBuilder pn()
Print an new line break

Returns:
this builder

np

public final TextBuilder np(Object o)
Print an new line break followed by an object

Parameters:
o -
Returns:
this builder

pt

public TextBuilder pt(Object o)
Print an object followed by a tab \t

Parameters:
o -
Returns:
this builder

ptn

public TextBuilder ptn(Object o)
Print an object followed by a tab \t and an new line break

Parameters:
o -
Returns:
this builder

p2t

public TextBuilder p2t(Object o)
Print an object followed by two tabs \t

Parameters:
o -
Returns:
this builder

p2tn

public TextBuilder p2tn(Object o)
Print an object followed by 2 tabs \t and an line break

Parameters:
o -
Returns:
this builder

p3t

public TextBuilder p3t(Object o)
Print an object followed by 3 tabs \t

Parameters:
o -
Returns:
this builder

p3tn

public TextBuilder p3tn(Object o)
Print an object followed by 3 tabs \t and an line break

Parameters:
o -
Returns:
this builder

p4t

public TextBuilder p4t(Object o)
Print an object followed by 4 tabs \t

Parameters:
o -
Returns:
this builder

p4tn

public TextBuilder p4tn(Object o)
Print an object followed by 4 tabs \t and an line break

Parameters:
o -
Returns:
this builder

build

public TextBuilder build()
Sub class could implement this method to append the generated source code to the buffer

Returns:
this builder

toString

public String toString()
Return the internal buffer or caller's internal buffer if it is null

Overrides:
toString in class Object
Returns:
the content

clone

public TextBuilder clone(TextBuilder caller)
return a clone of this TextBuilder instance

Parameters:
caller -
Returns:
the clone


Copyright © 2013. All Rights Reserved.