|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.afcs.warts.util.TablePrinter
The TablePrinter class prints a 2-D array of strings in
a plain-text table with each column aligned to the left or right. The column
names, widths, and alignments are specified at initialization, and then one
of the prettyPrint()
methods is called to format a specific
dataset, returning the result as a string.
LICENSE: This code is released to the public domain and may be used for any purpose whatsoever without permission or acknowledgment.
Constructor Summary | |
TablePrinter(java.lang.String[] columnNames,
int[] columnWidths)
Initialises a new instance with the specified column names and widths. |
|
TablePrinter(java.lang.String[] columnNames,
int[] columnWidths,
boolean[] columnLeftAligned)
Initialises a new instance with the specified column names, widths, and alignments. |
Method Summary | |
java.lang.String |
prettyPrint(java.util.List data)
Returns a string containing the specified dataset, which must be a list of java.util.List instances, in a plain text table, formatted
according to the parameters specified at initialization. |
java.lang.String |
prettyPrint(java.lang.String[][] data)
Returns a string containing the specified dataset, formatted according to the parameters specified at initialization. |
java.lang.String |
toString()
Returns a text description of the current instance that can be used for debugging purposes. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
public TablePrinter(java.lang.String[] columnNames, int[] columnWidths)
columnNames
- The names of each column.columnWidths
- The widths of each column.public TablePrinter(java.lang.String[] columnNames, int[] columnWidths, boolean[] columnLeftAligned)
columnNames
- The names of each column.columnWidths
- The widths of each column.columnLeftAligned
- Whether of not each column should be
left-aligned. If null, all columns are left-aligned.
java.lang.NullPointerException
- If columnNames or columnWidths is null.
java.lang.IllegalArgumentException
- If columnNames, columnWidths, or
columnLeftAligned (if specified) are different
lengths.Method Detail |
public java.lang.String prettyPrint(java.util.List data)
java.util.List
instances, in a plain text table, formatted
according to the parameters specified at initialization.
data
- The data to format. Each element in the list should be
a java.util.List
. Empty strings will be
included in the output for rows where the number column
specified is less than the number of columns in the
table.
java.lang.NullPointerException
- If data is null.public java.lang.String prettyPrint(java.lang.String[][] data)
data
- The data to format. Empty strings will be included in
the output for rows where the number column specified is
less than the number of columns in the table.
java.lang.NullPointerException
- If data is null.public java.lang.String toString()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |