com.sun.faban.common
Class TextTable

java.lang.Object
  extended by com.sun.faban.common.TextTable

public class TextTable
extends Object

The text table assists in formatting tabular data for text output. I takes care of column alignments. The output format is compatible with FenXi's Xan format.

Author:
Akara Sucharitakul

Constructor Summary
TextTable(int rows, int columns)
          Constructs a text table with predefined number of rows and columns.
 
Method Summary
 Appendable format(Appendable a)
          Formats the TextTable and outputs to an Appendable.
 StringBuffer format(StringBuffer b)
          StringBuffer version of format.
 StringBuilder format(StringBuilder b)
          StringBuilder version of format.
 CharSequence getField(int row, int column)
          Obtains the field so formatters can insert values directly.
 CharSequence getHeader(int column)
          Gets the header field's value.
 void setField(int row, int column, CharSequence field)
          Sets the data fields' value.
 void setHeader(int column, CharSequence header)
          Sets the header fields' value.
 String toString()
          Returns the formatted table in a string.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

TextTable

public TextTable(int rows,
                 int columns)
Constructs a text table with predefined number of rows and columns.

Parameters:
rows - The number of rows
columns - The number of columns
Method Detail

setHeader

public void setHeader(int column,
                      CharSequence header)
Sets the header fields' value.

Parameters:
column - The column to set the header
header - The header

getHeader

public CharSequence getHeader(int column)
Gets the header field's value.

Parameters:
column - The colund to get the header
Returns:
The current field value

setField

public void setField(int row,
                     int column,
                     CharSequence field)
Sets the data fields' value.

Parameters:
row - The row index of the data
column - The column index of the data
field - The data field

getField

public CharSequence getField(int row,
                             int column)
Obtains the field so formatters can insert values directly.

Parameters:
row - The row index
column - The column index
Returns:
The CharSequence representing this field.

format

public StringBuilder format(StringBuilder b)
StringBuilder version of format. Same as format(Appendable) but does not throw exceptions.

Parameters:
b - The StringBuilder to append to
Returns:
The same StringBuilder

format

public StringBuffer format(StringBuffer b)
StringBuffer version of format. Same as format(Appendable) but does not throw exceptions.

Parameters:
b - The StringBuffer to append to
Returns:
The same StringBuffer

format

public Appendable format(Appendable a)
                  throws IOException
Formats the TextTable and outputs to an Appendable.

Parameters:
a - The Appendable to output the text
Returns:
The same Appendable
Throws:
IOException - Problems writing to the Appendable

toString

public String toString()
Returns the formatted table in a string.

Overrides:
toString in class Object
Returns:
a formatted string representation of the table.