public class StringTablePrinter extends Object
Modifier and Type | Class and Description |
---|---|
static class |
StringTablePrinter.StringAlign
Text alignment enumerate.
|
Modifier and Type | Field and Description |
---|---|
static String |
DEFAULT_BOLD_LINE_SEPARATOR
The default String representing the bold line separator.
|
static String |
DEFAULT_LEFT_VERTICAL_SEPARATOR
The default String representing the vertical separator of the left column.
|
static String |
DEFAULT_RIGHT_VERTICAL_SEPARATOR
The default String representing the vertical separator of the right column.
|
static String |
DEFAULT_STANDARD_LINE_SEPARATOR
The default String representing the standard line separator.
|
static String |
DEFAULT_VERTICAL_SEPARATOR
The default String representing the vertical separator of the middle columns.
|
Constructor and Description |
---|
StringTablePrinter(String[] header)
Constructor to initialize the header.
|
StringTablePrinter(String title,
String[] header)
Constructor to initialize the header and add a centered title to the table.
|
Modifier and Type | Method and Description |
---|---|
void |
addBoldLineSeparator()
Add a line full of bold separators.
|
void |
addLine(double[] values,
String fmt)
Add the values as a line to the table.
|
void |
addLine(String[] line)
Add a line to the table.
|
void |
addLine(String leftColumn,
double[] values,
String fmt)
Add the values as a line to the table.
The first column is described by a String. |
void |
addStandardLineSeparator()
Add a line full of standard separators.
|
void |
clear()
Clear the title and the table (the header remains).
|
String |
getBoldLineSeparator()
Getter for the String representing the bold line separator.
|
int |
getNbColumns()
Getter for the number of columns in the table.
|
String |
getStandardLineSeparator()
Getter for the String representing the standard line separator.
|
StringTablePrinter.StringAlign |
getStringAlign()
Getter for the text alignment mode.
|
String |
getVerticalLeftSeparator()
Getter for the String representing the vertical separator of the left column.
|
String |
getVerticalRightSeparator()
Getter for the String representing the vertical separator of the right column.
|
String |
getVerticalSeparator()
Getter for the String representing the vertical separator of the middle columns.
|
static String |
printDouble(double value,
String fmt)
Print a double as a String in the provided format.
|
void |
setBoldLineSeparator(String boldLineSeparator)
Setter for the String representing the bold line separator.
|
void |
setStandardLineSeparator(String standardLineSeparator)
Setter for the String representing the standard line separator.
|
void |
setStringAlign(StringTablePrinter.StringAlign stringAlign)
Setter for the text alignment mode (
RIGHT by default). |
void |
setTitle(String title)
Optionally, add a centered title (will be displayed before the header).
|
void |
setVerticalLeftSeparator(String verticalLeftSeparator)
Setter for the String representing the vertical separator of the left column.
|
void |
setVerticalRightSeparator(String verticalRightSeparator)
Setter for the String representing the vertical separator of the right column.
|
void |
setVerticalSeparator(String verticalSeparator)
Setter for the String representing the vertical separator of the middle columns.
|
void |
switchLastLineBold()
Change the last table line into a line full of bold separators.
|
String |
toString()
Return a string representation of the formatted table.
|
String |
toString(int indentation)
Return a string representation of the formatted table.
|
public static final String DEFAULT_BOLD_LINE_SEPARATOR
public static final String DEFAULT_STANDARD_LINE_SEPARATOR
public static final String DEFAULT_VERTICAL_SEPARATOR
public static final String DEFAULT_LEFT_VERTICAL_SEPARATOR
public static final String DEFAULT_RIGHT_VERTICAL_SEPARATOR
public StringTablePrinter(String[] header)
Note: the header dimension constrains the table dimension. The values added later must be compatible with this dimension.
header
- The header describing each column informationpublic StringTablePrinter(String title, String[] header)
Note: the header dimension constrains the table dimension. The values added later must be compatible with this dimension.
title
- Centered table title (null
if not initialized)header
- The header describing each column informationNullArgumentException
- if header
is null
IllegalArgumentException
- the header doesn't describe at least one column (size can't be 0)public void addLine(String[] line)
Note: the given array must have the same size as the header used in the constructor (see getNbColumns()
).
line
- The array describing each column value of the new lineIllegalArgumentException
- if the provided array does not have the same dimension than the headerpublic void addLine(double[] values, String fmt)
values
- The array describing each column value of the new linefmt
- The format used to convert the double values into StringIllegalArgumentException
- if the provided array does not have the same dimension than the headerpublic void addLine(String leftColumn, double[] values, String fmt)
leftColumn
- The first column of the line represented by a Stringvalues
- The other columns of the line represented by double values (must have the same dimension as the header
minus one, as the left column is not described by this array)fmt
- The format used to convert the double values into StringIllegalArgumentException
- if the provided array dimension is not compatible with the header
(values.length + 1 =! getNbColumns()
)public void setTitle(String title)
Note: the title's length must be shorter than the total table width minus the left and right columns separator lengths.
title
- Centered table (null
to disable)public void addBoldLineSeparator()
public void switchLastLineBold()
This method can be useful when the table is built with several standard lines separator depending on conditions and we still want to use a bold line at the end of the table.
public void addStandardLineSeparator()
public void clear()
public String toString()
public String toString(int indentation)
indentation
- Indent the array of N spacesNotPositiveException
- if indentation < 0
public StringTablePrinter.StringAlign getStringAlign()
public void setStringAlign(StringTablePrinter.StringAlign stringAlign)
RIGHT
by default).stringAlign
- Text alignment mode to setpublic String getBoldLineSeparator()
public void setBoldLineSeparator(String boldLineSeparator)
boldLineSeparator
- String representing the bold line separator to setpublic String getStandardLineSeparator()
public void setStandardLineSeparator(String standardLineSeparator)
standardLineSeparator
- String representing the standard line separator to setpublic String getVerticalSeparator()
public void setVerticalSeparator(String verticalSeparator)
verticalSeparator
- String representing the vertical separator of the middle columns to setpublic String getVerticalLeftSeparator()
public void setVerticalLeftSeparator(String verticalLeftSeparator)
verticalLeftSeparator
- String representing the vertical separator of the left column to setpublic String getVerticalRightSeparator()
public void setVerticalRightSeparator(String verticalRightSeparator)
verticalRightSeparator
- String representing the vertical separator of the right column to setpublic int getNbColumns()
Copyright © 2023 CNES. All rights reserved.