Package cern.colt.matrix.impl
Class AbstractFormatter
java.lang.Object
cern.colt.PersistentObject
cern.colt.matrix.impl.AbstractFormatter
- All Implemented Interfaces:
Serializable
,Cloneable
Abstract base class for flexible, well human readable matrix print formatting.
Value type independent.
A single cell is formatted via a format string.
Columns can be aligned left, centered, right and by decimal point.
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.
- Version:
- 1.0, 09/24/99
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected String
The default format string for formatting a single cell value; currently "%G".private static String[]
static final String
The alignment string aligning the cells of a column to its center.protected String
The default string separating any two columns from another; currently " ".static final String
The alignment string aligning the cells of a column to the decimal point.static final String
The default string separating any two columns from another; currently " ".static final int
The default minimum number of characters a column may have; currently 1.static final String
The default string separating any two rows from another; currently "\n".static final String
The default string separating any two slices from another; currently "\n\n".protected static final FormerFactory
protected String
The default format string for formatting a single cell value; currently "%G".static final String
The alignment string aligning the cells of a column to the left.protected int
The default minimum number of characters a column may have; currently 1.protected boolean
Tells whether String representations are to be preceded with summary of the shape; currently true.static final String
The alignment string aligning the cells of a column to the right.protected String
The default string separating any two rows from another; currently "\n".protected String
The default string separating any two slices from another; currently "\n\n".Fields inherited from class cern.colt.PersistentObject
serialVersionUID
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
Makes this class non instantiable, but still let's others inherit from it. -
Method Summary
Modifier and TypeMethodDescriptionprotected void
Modifies the strings in a column of the string matrix to be aligned (left,centered,right,decimal).protected int
alignmentCode
(String alignment) Converts a row into a string.protected void
Modifies the strings the string matrix to be aligned (left,centered,right,decimal).protected 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
Demonstrates how to use this class.protected abstract String
form
(AbstractMatrix1D matrix, int index, Former formatter) Converts a given cell to a String; no alignment considered.protected abstract String[][]
format
(AbstractMatrix2D matrix) Returns a string representations of all cells; no alignment considered.protected String[]
formatRow
(AbstractMatrix1D vector) Returns a string representations of all cells; no alignment considered.protected int
Returns the number of characters or the number of characters before the decimal point.protected String
repeat
(char character, int length) Returns a String with the given character repeated length times.void
setAlignment
(String alignment) Sets the column alignment (left,center,right,decimal).void
setColumnSeparator
(String columnSeparator) Sets the string separating any two columns from another.void
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
(String rowSeparator) Sets the string separating any two rows from another.void
setSliceSeparator
(String sliceSeparator) Sets the string separating any two slices from another.protected static void
Cache for faster string processing.static String
shape
(AbstractMatrix1D matrix) Returns a short string representation describing the shape of the matrix.static String
shape
(AbstractMatrix2D matrix) Returns a short string representation describing the shape of the matrix.static String
shape
(AbstractMatrix3D matrix) Returns a short string representation describing the shape of the matrix.protected String
toString
(AbstractMatrix2D matrix) Returns a string representation of the given matrix.protected String
Returns a single string representation of the given string matrix.Methods inherited from class cern.colt.PersistentObject
clone
-
Field Details
-
LEFT
The alignment string aligning the cells of a column to the left.- See Also:
-
CENTER
The alignment string aligning the cells of a column to its center.- See Also:
-
RIGHT
The alignment string aligning the cells of a column to the right.- See Also:
-
DECIMAL
The alignment string aligning the cells of a column to the decimal point.- See Also:
-
DEFAULT_MIN_COLUMN_WIDTH
public static final int DEFAULT_MIN_COLUMN_WIDTHThe default minimum number of characters a column may have; currently 1.- See Also:
-
DEFAULT_COLUMN_SEPARATOR
The default string separating any two columns from another; currently " ".- See Also:
-
DEFAULT_ROW_SEPARATOR
The default string separating any two rows from another; currently "\n".- See Also:
-
DEFAULT_SLICE_SEPARATOR
The default string separating any two slices from another; currently "\n\n".- See Also:
-
alignment
The default format string for formatting a single cell value; currently "%G". -
format
The default format string for formatting a single cell value; currently "%G". -
minColumnWidth
protected int minColumnWidthThe default minimum number of characters a column may have; currently 1. -
columnSeparator
The default string separating any two columns from another; currently " ". -
rowSeparator
The default string separating any two rows from another; currently "\n". -
sliceSeparator
The default string separating any two slices from another; currently "\n\n". -
printShape
protected boolean printShapeTells whether String representations are to be preceded with summary of the shape; currently true. -
blanksCache
-
factory
-
-
Constructor Details
-
AbstractFormatter
protected AbstractFormatter()Makes this class non instantiable, but still let's others inherit from it.
-
-
Method Details
-
align
Modifies the strings in a column of the string matrix to be aligned (left,centered,right,decimal). -
alignmentCode
Converts a row into a string. -
alignRow
Modifies the strings the string matrix to be aligned (left,centered,right,decimal). -
blanks
Returns a String with length blanks. -
demo1
public static void demo1()Demonstrates how to use this class. -
demo2
public static void demo2()Demonstrates how to use this class. -
demo3
Demonstrates how to use this class. -
form
Converts a given cell to a String; no alignment considered. -
format
Returns a string representations of all cells; no alignment considered. -
formatRow
Returns a string representations of all cells; no alignment considered. -
lead
Returns the number of characters or the number of characters before the decimal point. -
repeat
Returns a String with the given character repeated length times. -
setAlignment
Sets the column alignment (left,center,right,decimal).- Parameters:
alignment
- the new alignment to be used; must be one of {LEFT,CENTER,RIGHT,DECIMAL}.
-
setColumnSeparator
Sets the string separating any two columns from another.- Parameters:
columnSeparator
- the new columnSeparator to be used.
-
setFormat
Sets the way a single cell value is to be formatted.- Parameters:
format
- the new format to be used.
-
setMinColumnWidth
public void setMinColumnWidth(int minColumnWidth) Sets the minimum number of characters a column may have.- Parameters:
minColumnWidth
- the new minColumnWidth to be used.
-
setPrintShape
public void setPrintShape(boolean printShape) Specifies whether a string representation of a matrix is to be preceded with a summary of its shape.- Parameters:
printShape
- true shape summary is printed, otherwise not printed.
-
setRowSeparator
Sets the string separating any two rows from another.- Parameters:
rowSeparator
- the new rowSeparator to be used.
-
setSliceSeparator
Sets the string separating any two slices from another.- Parameters:
sliceSeparator
- the new sliceSeparator to be used.
-
setupBlanksCache
protected static void setupBlanksCache()Cache for faster string processing. -
shape
Returns a short string representation describing the shape of the matrix. -
shape
Returns a short string representation describing the shape of the matrix. -
shape
Returns a short string representation describing the shape of the matrix. -
toString
Returns a single string representation of the given string matrix.- Parameters:
strings
- the matrix to be converted to a single string.
-
toString
Returns a string representation of the given matrix.- Parameters:
matrix
- the matrix to convert.
-