public abstract class NamedValuesFormatter extends Object
NamedValues is a class for holding lists of String values where each list is associated with a name. NamedValuesFormatter can print the name/values in a NamedValues as a table or as a list of rows.
See NamedValuesColumnFormatter for help with formatting a NamedValues as a table (each name and all its values in one column). See NamedValuesRowFormatter for help printing as a list of row oriented data (each name and all its values on one row).
For example, to create a table style output formatter, assign it data, and print the data:NamedValuesFormatter formatter = NamedValuesFormatter.create( NamedValuesFormatter.STYLE_COLUMNS ); formatter.setWhetherDisplayLabels( true ); formatter.assignNamedValues( namedValues ); // A named values system created elsewhere formatter.display( System.out );
NamedValuesColumnFormatter
,
NamedValuesRowFormatter
Modifier and Type | Field and Description |
---|---|
protected String[][] |
cells |
protected String[] |
labels |
protected int |
numCols |
protected int |
numRows |
static int |
STYLE_COLUMNS
To create a NamedValuesFormatter that prints NamedValues as a table, 1 name and its values in a column.
|
static int |
STYLE_ROWS
To create a NamedValuesFormatter that prints NamedValues as 1 name and its values on 1 row.
|
Constructor and Description |
---|
NamedValuesFormatter() |
Modifier and Type | Method and Description |
---|---|
void |
assignNamedValues(NamedValues namedValues)
Tells the NamedValuesFormatter which NamedValues system it should format.
|
protected static String |
centerText(String text,
String space)
Returns the given "text" overlaid in the center of the space string.
|
static NamedValuesFormatter |
create(int style)
Creates an NamedValuesFormatter that will print a NamedValues
object in either columns or rows orientation, depending on the argument.
|
void |
display(PrintStream out)
Prints the formatted NamedValues as a table or list of rows, according to the style
used to create the formatter.
|
abstract String |
getCell(int row,
int col)
Thinking of the namedValues system as a matrix of strings, return a given cell's string data
|
protected int |
getColumnWidth(int col)
Finds the widest cell of the given column and returns its width.
|
abstract String |
getFormattedCell(int row,
int col,
String space)
Thinking of the namedValues system as a matrix of strings, return a given cell's string data
formatted in a string according to whether the system as a whole would be printed in column
or row formatting.
|
boolean |
getWhetherDisplayLabels()
Returns boolean indicating if the printed output
will include headings.
|
abstract boolean |
isLabelCell(int row,
int col)
Thinking of the namedValues system as a matrix of strings, return whether
the given cell is a label cell or not.
|
protected static String |
leftJustifyText(String text,
String space)
Returns the given "text" overlaid and to the left of the space string.
|
protected static String |
rightJustifyText(String text,
String space)
Returns the given "text" overlaid and to the right of the space string.
|
void |
setWhetherDisplayLabels(boolean yesno)
Sets whether or not headings will be printed with the data.
|
protected abstract void |
updateDimensions()
Thinking of the namedValues system as a matrix of strings, reset the internal row and column
count based on things like whether labels would be printed (if not, that's one less row).
|
public static final int STYLE_ROWS
public static final int STYLE_COLUMNS
protected String[] labels
protected String[][] cells
protected int numRows
protected int numCols
public static NamedValuesFormatter create(int style)
style
- If style is given and is valued NamedValuesFormatter.STYLE_ROWS (1) then
a row formatter is created, otherwise a column formatter is created.STYLE_ROWS
,
STYLE_COLUMNS
public void assignNamedValues(NamedValues namedValues)
namedValues
- The system of named values that should be formatted by this NamedValuesFormatter.protected int getColumnWidth(int col)
col
- public void display(PrintStream out)
out
- The stream to which to print the output.public boolean getWhetherDisplayLabels()
setWhetherDisplaylabels
public void setWhetherDisplayLabels(boolean yesno)
yesno
- If false the formatter will not print the labels. If true, or
this method is not used, the headings will be printed.protected static String centerText(String text, String space)
text
- The string of data. This would be one cell's value data.space
- A string into which to put the text. Usually space would be a String of spaces.protected static String leftJustifyText(String text, String space)
text
- The string of data. This would be one cell's value data.space
- A string into which to put the text. Usually space would be a String of spaces.protected static String rightJustifyText(String text, String space)
text
- The string of data. This would be one cell's value data.space
- A string into which to put the text. Usually space would be a String of spaces.public abstract boolean isLabelCell(int row, int col)
row
- col
- public abstract String getCell(int row, int col)
row
- Specifies the index of the vector of values that were added to the NamedValues system,
starting from 0 being the first name and value vector added.col
- Specifies the index of a column, where 0 indicates the name, and >0 indicates one of
the values associated with that name.public abstract String getFormattedCell(int row, int col, String space)
row
- Specifies the index of the vector of values that were added to the NamedValues system,
starting from 0 being the first name and value vector added.col
- Specifies the index of a column, where 0 indicates the name, and >0 indicates one of
the values associated with that name.protected abstract void updateDimensions()
Copyright © 2014. All Rights Reserved.