Package org.evoludo.util
Class Formatter
Object
Formatter
Collection of convenience methods for formatting numbers, vectors and
matrices as Strings.
- Author:
- Christoph Hauert
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final String
Delimiter between matrix rows.private static final int
The maximum number of decimal digits to format.private static final DecimalFormat[]
Array of formatters with fixed number of digits ranging from 0 to 12.private static final DecimalFormat[]
Array of formatters with 0 to up to 12 non-zero decimal digits.private static final DecimalFormat[]
Array of percentage formatters with fixed number of digits ranging from 0 to 12.private static final DecimalFormat[]
Array of scientific formatters with fixed number of digits ranging from 0 to up to 12 non-zero decimal digits.private static final double[][]
The thresholds for 'pretty' formatting of exponents for each number of digits.static final String
Delimiter between vector elements. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivate
Ensure non-instantiability with private default constructor -
Method Summary
Modifier and TypeMethodDescriptionstatic String
format
(double[][] aMatrix, int digits) Format array/matrix of doublesaMatrix
as String.static String
format
(double[] aVector, int digits) Format array/vector of doublesaVector
as String.static String
format
(double aDouble, int digits) Format doubleaDouble
as String with at mostdigits
decimal places (trailing zeroes are suppressed).static String
format
(float[][] aMatrix, int digits) Format array/matrix of floatsaMatrix
as String.static String
format
(float[] aVector, int digits) Format array/vector of floatsaVector
as String.static String
format
(int anInteger) Format integeranInteger
as Stringstatic String
format
(int[] aVector) Format integer array/vectoraVector
as String.static String
format
(int[][] aMatrix) Format array/matrix of integersaMatrix
as String.static <T> String
format
(T[] aVector) static <T> String
Format the vectoraVector
of typeT
as a String with elements separated bydelimiter
string.static String
formatFix
(double[][] aMatrix, int digits) Format array/matrix of doublesaMatrix
as String.static String
formatFix
(double[] aVector, int digits) Format array/vector of doublesaVector
as String.static String
formatFix
(double aDouble, int digits) Format doubleaDouble
as String withdigits
decimal places (trailing zeroes are included).static String
formatPercent
(double aDouble, int digits) Format doubleaDouble
as percent String withdigits
decimal places (trailing zeroes are included).static String
formatSci
(double[][] aMatrix, int digits) Format array/matrix of doublesaMatrix
as String.static String
formatSci
(double[] aVector, int digits) Format array/vector of doublesaVector
as String.static String
formatSci
(double aDouble, int digits) Format doubleaDouble
as String with up todigits
decimal places (trailing zeroes are suppressed) forcing scientific formatting including exponent (separated by 'E').static String
pretty
(double[][] aMatrix, int digits) Same asformatSci(double[], int)
but formatting of exponents 'prettyfied' using HTML.static String
pretty
(double[] aVector, int digits) Same asformatSci(double[], int)
but formatting of exponents 'prettyfied' using HTML.static String
pretty
(double aDouble, int digits) Same asformatSci(double, int)
but formatting of exponent 'prettyfied' using HTML.private static String
prettyFormat
(double aDouble, int digits) Helper method to format a doubleaDouble
as HTML string withdigits
decimal places (trailing zeroes are included).
-
Field Details
-
MAX_DIGITS
private static final int MAX_DIGITSThe maximum number of decimal digits to format.- See Also:
-
MATRIX_DELIMITER
Delimiter between matrix rows. Note: keep in sync withCLOParser.MATRIX_DELIMITER
- See Also:
-
VECTOR_DELIMITER
Delimiter between vector elements. Note: keep in sync withCLOParser.VECTOR_DELIMITER
- See Also:
-
myFormatters
Array of formatters with 0 to up to 12 non-zero decimal digits. -
myFixFormatters
Array of formatters with fixed number of digits ranging from 0 to 12. -
mySciFormatters
Array of scientific formatters with fixed number of digits ranging from 0 to up to 12 non-zero decimal digits. -
myPercentFormatters
Array of percentage formatters with fixed number of digits ranging from 0 to 12. -
prettyThresholds
private static final double[][] prettyThresholdsThe thresholds for 'pretty' formatting of exponents for each number of digits. For absolute values between the upper and lower bound fixed formatting is used, otherwise scientific formatting is applied.
-
-
Constructor Details
-
Formatter
private Formatter()Ensure non-instantiability with private default constructor
-
-
Method Details
-
format
- Type Parameters:
T
- the type of the vector- Parameters:
aVector
- the vector to format- Returns:
- the formatted String vector
-
format
Format the vectoraVector
of typeT
as a String with elements separated bydelimiter
string.- Type Parameters:
T
- the type of the vector- Parameters:
aVector
- the string vector to formatdelimiter
- the delimiter for separating the entries inaVector
- Returns:
- the formatted String vector
-
format
Format integeranInteger
as String- Parameters:
anInteger
- number to format- Returns:
- formatted
int
as String
-
format
Format integer array/vectoraVector
as String. Elements are separated by '", "'.- Parameters:
aVector
- array to format- Returns:
- formatted
int[]
as String
-
format
Format array/matrix of integersaMatrix
as String. Column elements are separated by '", "' and rows of elements by '"; "'.- Parameters:
aMatrix
- array to format- Returns:
- formatted
int[][]
as String
-
format
Format doubleaDouble
as String with at mostdigits
decimal places (trailing zeroes are suppressed).- Parameters:
aDouble
- number to formatdigits
- number of decimal places- Returns:
- formatted
double
as String
-
format
Format array/vector of doublesaVector
as String. Elements are separated by '", "' and formatted with at mostdigits
decimal places (trailing zeroes are suppressed).- Parameters:
aVector
- array to formatdigits
- number of decimal places- Returns:
- formatted
double[]
as String
-
format
Format array/matrix of doublesaMatrix
as String. Column elements are separated by '", "' and rows of elements by '"; "'. Each element is formatted with at mostdigits
decimal places (trailing zeroes are suppressed).- Parameters:
aMatrix
- array to formatdigits
- number of decimal places- Returns:
- formatted
double[][]
as String
-
format
Format array/vector of floatsaVector
as String. Elements are separated by '", "' and formatted with at mostdigits
decimal places (trailing zeroes are suppressed).- Parameters:
aVector
- array to formatdigits
- number of decimal places- Returns:
- formatted
float[]
as String
-
format
Format array/matrix of floatsaMatrix
as String. Column elements are separated by '", "' and rows of elements by '"; "'. Each element is formatted with at mostdigits
decimal places (trailing zeroes are suppressed).- Parameters:
aMatrix
- array to formatdigits
- number of decimal places- Returns:
- formatted
float[][]
as String
-
formatFix
Format doubleaDouble
as String withdigits
decimal places (trailing zeroes are included).- Parameters:
aDouble
- number to formatdigits
- number of decimal places- Returns:
- formatted
double
as String
-
formatFix
Format array/vector of doublesaVector
as String. Elements are separated by '", "' and formatted withdigits
decimal places (trailing zeroes are included).- Parameters:
aVector
- array to formatdigits
- number of decimal places- Returns:
- formatted
double[]
as String
-
formatFix
Format array/matrix of doublesaMatrix
as String. Column elements are separated by '", "' and rows of elements by '"; "'. Each element is formatted withdigits
decimal places (trailing zeroes are included).- Parameters:
aMatrix
- array to formatdigits
- number of decimal places- Returns:
- formatted
double[][]
as String
-
formatSci
Format doubleaDouble
as String with up todigits
decimal places (trailing zeroes are suppressed) forcing scientific formatting including exponent (separated by 'E').- Parameters:
aDouble
- number to formatdigits
- number of decimal places- Returns:
- formatted
double
as String
-
formatSci
Format array/vector of doublesaVector
as String. Elements are separated by '", "' and formatted with up todigits
decimal places (trailing zeroes are suppressed) forcing scientific formatting including exponent (separated by 'E').- Parameters:
aVector
- array to formatdigits
- number of decimal places- Returns:
- formatted
double[]
as String
-
formatSci
Format array/matrix of doublesaMatrix
as String. Column elements are separated by '", "' and rows of elements by '"; "'. Each element is formatted with up todigits
decimal places (trailing zeroes are suppressed) forcing scientific formatting including exponent (separated by 'E').- Parameters:
aMatrix
- array to formatdigits
- number of decimal places- Returns:
- formatted
double[][]
as String
-
prettyFormat
Helper method to format a doubleaDouble
as HTML string withdigits
decimal places (trailing zeroes are included).- Parameters:
aDouble
- the number to formatdigits
- the number of decimal places- Returns:
- the formatted
double
as HTML string
-
pretty
Same asformatSci(double, int)
but formatting of exponent 'prettyfied' using HTML.- Parameters:
aDouble
- number to formatdigits
- number of decimal places- Returns:
- formatted
double
as HTML string
-
pretty
Same asformatSci(double[], int)
but formatting of exponents 'prettyfied' using HTML.- Parameters:
aVector
- number to formatdigits
- number of decimal places- Returns:
- formatted
double[]
as HTML string
-
pretty
Same asformatSci(double[], int)
but formatting of exponents 'prettyfied' using HTML.- Parameters:
aMatrix
- number to formatdigits
- number of decimal places- Returns:
- formatted
double[][]
as HTML string
-
formatPercent
Format doubleaDouble
as percent String withdigits
decimal places (trailing zeroes are included).- Parameters:
aDouble
- number to formatdigits
- number of decimal places- Returns:
- formatted
double
as String
-