public abstract class AbstractFormatter extends PersistentObject
A column can be broader than specified by the parameter minColumnWidth (because a cell may not fit into that width) but a column is never smaller than minColumnWidth. Normally one does not need to specify minColumnWidth. Cells in a row are separated by a separator string, similar separators can be set for rows and slices. For more info, see the concrete subclasses.
Modifier and Type | Field and Description |
---|---|
protected java.lang.String |
alignment
The default format string for formatting a single cell value; currently "%G".
|
static java.lang.String |
CENTER
The alignment string aligning the cells of a column to its center.
|
protected java.lang.String |
columnSeparator
The default string separating any two columns from another; currently " ".
|
static java.lang.String |
DECIMAL
The alignment string aligning the cells of a column to the decimal point.
|
static java.lang.String |
DEFAULT_COLUMN_SEPARATOR
The default string separating any two columns from another; currently " ".
|
static int |
DEFAULT_MIN_COLUMN_WIDTH
The default minimum number of characters a column may have; currently 1.
|
static java.lang.String |
DEFAULT_ROW_SEPARATOR
The default string separating any two rows from another; currently "\n".
|
static java.lang.String |
DEFAULT_SLICE_SEPARATOR
The default string separating any two slices from another; currently "\n\n".
|
protected static FormerFactory |
factory |
protected java.lang.String |
format
The default format string for formatting a single cell value; currently "%G".
|
static java.lang.String |
LEFT
The alignment string aligning the cells of a column to the left.
|
protected int |
minColumnWidth
The default minimum number of characters a column may have; currently 1.
|
protected boolean |
printShape
Tells whether String representations are to be preceded with summary of the shape; currently true.
|
static java.lang.String |
RIGHT
The alignment string aligning the cells of a column to the right.
|
protected java.lang.String |
rowSeparator
The default string separating any two rows from another; currently "\n".
|
protected java.lang.String |
sliceSeparator
The default string separating any two slices from another; currently "\n\n".
|
serialVersionUID
Modifier | Constructor and Description |
---|---|
protected |
AbstractFormatter()
Makes this class non instantiable, but still let's others inherit from it.
|
Modifier and Type | Method and Description |
---|---|
protected void |
align(java.lang.String[][] strings)
Modifies the strings in a column of the string matrix to be aligned (left,centered,right,decimal).
|
protected int |
alignmentCode(java.lang.String alignment)
Converts a row into a string.
|
protected void |
alignRow(java.lang.String[] row,
int[] maxColWidth,
int[] maxColLead)
Modifies the strings the string matrix to be aligned (left,centered,right,decimal).
|
protected java.lang.String |
blanks(int length)
Returns a String with length blanks.
|
static void |
demo1()
Demonstrates how to use this class.
|
static void |
demo2()
Demonstrates how to use this class.
|
static void |
demo3(int size,
java.lang.Object value)
Demonstrates how to use this class.
|
protected abstract java.lang.String |
form(AbstractMatrix1D matrix,
int index,
Former formatter)
Converts a given cell to a String; no alignment considered.
|
protected abstract java.lang.String[][] |
format(AbstractMatrix2D matrix)
Returns a string representations of all cells; no alignment considered.
|
protected java.lang.String[] |
formatRow(AbstractMatrix1D vector)
Returns a string representations of all cells; no alignment considered.
|
protected int |
lead(java.lang.String s)
Returns the number of characters or the number of characters before the decimal point.
|
protected java.lang.String |
repeat(char character,
int length)
Returns a String with the given character repeated length times.
|
void |
setAlignment(java.lang.String alignment)
Sets the column alignment (left,center,right,decimal).
|
void |
setColumnSeparator(java.lang.String columnSeparator)
Sets the string separating any two columns from another.
|
void |
setFormat(java.lang.String format)
Sets the way a single cell value is to be formatted.
|
void |
setMinColumnWidth(int minColumnWidth)
Sets the minimum number of characters a column may have.
|
void |
setPrintShape(boolean printShape)
Specifies whether a string representation of a matrix is to be preceded with a summary of its shape.
|
void |
setRowSeparator(java.lang.String rowSeparator)
Sets the string separating any two rows from another.
|
void |
setSliceSeparator(java.lang.String sliceSeparator)
Sets the string separating any two slices from another.
|
protected static void |
setupBlanksCache()
Cache for faster string processing.
|
static java.lang.String |
shape(AbstractMatrix1D matrix)
Returns a short string representation describing the shape of the matrix.
|
static java.lang.String |
shape(AbstractMatrix2D matrix)
Returns a short string representation describing the shape of the matrix.
|
static java.lang.String |
shape(AbstractMatrix3D matrix)
Returns a short string representation describing the shape of the matrix.
|
protected java.lang.String |
toString(AbstractMatrix2D matrix)
Returns a string representation of the given matrix.
|
protected java.lang.String |
toString(java.lang.String[][] strings)
Returns a single string representation of the given string matrix.
|
clone
public static final java.lang.String LEFT
public static final java.lang.String CENTER
public static final java.lang.String RIGHT
public static final java.lang.String DECIMAL
public static final int DEFAULT_MIN_COLUMN_WIDTH
public static final java.lang.String DEFAULT_COLUMN_SEPARATOR
public static final java.lang.String DEFAULT_ROW_SEPARATOR
public static final java.lang.String DEFAULT_SLICE_SEPARATOR
protected java.lang.String alignment
protected java.lang.String format
protected int minColumnWidth
protected java.lang.String columnSeparator
protected java.lang.String rowSeparator
protected java.lang.String sliceSeparator
protected boolean printShape
protected static final FormerFactory factory
protected AbstractFormatter()
protected void align(java.lang.String[][] strings)
protected int alignmentCode(java.lang.String alignment)
protected void alignRow(java.lang.String[] row, int[] maxColWidth, int[] maxColLead)
protected java.lang.String blanks(int length)
public static void demo1()
public static void demo2()
public static void demo3(int size, java.lang.Object value)
protected abstract java.lang.String form(AbstractMatrix1D matrix, int index, Former formatter)
protected abstract java.lang.String[][] format(AbstractMatrix2D matrix)
protected java.lang.String[] formatRow(AbstractMatrix1D vector)
protected int lead(java.lang.String s)
protected java.lang.String repeat(char character, int length)
public void setAlignment(java.lang.String alignment)
alignment
- the new alignment to be used; must be one of {LEFT,CENTER,RIGHT,DECIMAL}.public void setColumnSeparator(java.lang.String columnSeparator)
columnSeparator
- the new columnSeparator to be used.public void setFormat(java.lang.String format)
format
- the new format to be used.public void setMinColumnWidth(int minColumnWidth)
minColumnWidth
- the new minColumnWidth to be used.public void setPrintShape(boolean printShape)
printShape
- true shape summary is printed, otherwise not printed.public void setRowSeparator(java.lang.String rowSeparator)
rowSeparator
- the new rowSeparator to be used.public void setSliceSeparator(java.lang.String sliceSeparator)
sliceSeparator
- the new sliceSeparator to be used.protected static void setupBlanksCache()
public static java.lang.String shape(AbstractMatrix1D matrix)
public static java.lang.String shape(AbstractMatrix2D matrix)
public static java.lang.String shape(AbstractMatrix3D matrix)
protected java.lang.String toString(java.lang.String[][] strings)
strings
- the matrix to be converted to a single string.protected java.lang.String toString(AbstractMatrix2D matrix)
matrix
- the matrix to convert.Jump to the Colt Homepage