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 StringDelimiter between matrix rows.private static final intThe 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 StringDelimiter between vector elements. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivateEnsure non-instantiability with private default constructor -
Method Summary
Modifier and TypeMethodDescriptionstatic Stringformat(double[][] aMatrix, int digits) Format array/matrix of doublesaMatrixas String.static Stringformat(double[] aVector, int digits) Format array/vector of doublesaVectoras String.static Stringformat(double aDouble, int digits) Format doubleaDoubleas String with at mostdigitsdecimal places (trailing zeroes are suppressed).static Stringformat(float[][] aMatrix, int digits) Format array/matrix of floatsaMatrixas String.static Stringformat(float[] aVector, int digits) Format array/vector of floatsaVectoras String.static Stringformat(int anInteger) Format integeranIntegeras Stringstatic Stringformat(int[] aVector) Format integer array/vectoraVectoras String.static Stringformat(int[][] aMatrix) Format array/matrix of integersaMatrixas String.static Stringformat(int digits, double... aDouble) Format an arbitrary number of doubles as String formatted as an array of with at mostdigitsdecimal places (trailing zeroes are suppressed).static <T> Stringformat(T[] aVector) static <T> StringFormat the vectoraVectorof typeTas a String with elements separated bydelimiterstring.static StringformatFix(double[][] aMatrix, int digits) Format array/matrix of doublesaMatrixas String.static StringformatFix(double[] aVector, int digits) Format array/vector of doublesaVectoras String.static StringformatFix(double aDouble, int digits) Format doubleaDoubleas String withdigitsdecimal places (trailing zeroes are included).static StringformatPercent(double aDouble, int digits) Format doubleaDoubleas percent String withdigitsdecimal places (trailing zeroes are included).static StringformatSci(double[][] aMatrix, int digits) Format array/matrix of doublesaMatrixas String.static StringformatSci(double[] aVector, int digits) Format array/vector of doublesaVectoras String.static StringformatSci(double aDouble, int digits) Format doubleaDoubleas String with up todigitsdecimal places (trailing zeroes are suppressed) forcing scientific formatting including exponent (separated by 'E').static Stringpretty(double[][] aMatrix, int digits) Same asformatSci(double[], int)but formatting of exponents 'prettyfied' using HTML.static Stringpretty(double[] aVector, int digits) Same asformatSci(double[], int)but formatting of exponents 'prettyfied' using HTML.static Stringpretty(double aDouble, int digits) Same asformatSci(double, int)but formatting of exponent 'prettyfied' using HTML.private static StringprettyFormat(double aDouble, int digits) Helper method to format a doubleaDoubleas HTML string withdigitsdecimal 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 vectoraVectorof typeTas a String with elements separated bydelimiterstring.- 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 integeranIntegeras String- Parameters:
anInteger- number to format- Returns:
- formatted
intas String
-
format
Format integer array/vectoraVectoras String. Elements are separated by '", "'.- Parameters:
aVector- array to format- Returns:
- formatted
int[]as String
-
format
Format array/matrix of integersaMatrixas String. Column elements are separated by '", "' and rows of elements by '"; "'.- Parameters:
aMatrix- array to format- Returns:
- formatted
int[][]as String
-
format
Format doubleaDoubleas String with at mostdigitsdecimal places (trailing zeroes are suppressed).- Parameters:
aDouble- number to formatdigits- number of decimal places- Returns:
- formatted
doubleas String
-
format
Format an arbitrary number of doubles as String formatted as an array of with at mostdigitsdecimal places (trailing zeroes are suppressed).- Parameters:
digits- the number of decimal placesaDouble- the variable number of doubles to format- Returns:
- formatted
doubleas String - See Also:
-
format
Format array/vector of doublesaVectoras String. Elements are separated by '", "' and formatted with at mostdigitsdecimal places (trailing zeroes are suppressed).- Parameters:
aVector- array to formatdigits- number of decimal places- Returns:
- formatted
double[]as String
-
format
Format array/matrix of doublesaMatrixas String. Column elements are separated by '", "' and rows of elements by '"; "'. Each element is formatted with at mostdigitsdecimal places (trailing zeroes are suppressed).- Parameters:
aMatrix- array to formatdigits- number of decimal places- Returns:
- formatted
double[][]as String
-
format
Format array/vector of floatsaVectoras String. Elements are separated by '", "' and formatted with at mostdigitsdecimal places (trailing zeroes are suppressed).- Parameters:
aVector- array to formatdigits- number of decimal places- Returns:
- formatted
float[]as String
-
format
Format array/matrix of floatsaMatrixas String. Column elements are separated by '", "' and rows of elements by '"; "'. Each element is formatted with at mostdigitsdecimal places (trailing zeroes are suppressed).- Parameters:
aMatrix- array to formatdigits- number of decimal places- Returns:
- formatted
float[][]as String
-
formatFix
Format doubleaDoubleas String withdigitsdecimal places (trailing zeroes are included).- Parameters:
aDouble- number to formatdigits- number of decimal places- Returns:
- formatted
doubleas String
-
formatFix
Format array/vector of doublesaVectoras String. Elements are separated by '", "' and formatted withdigitsdecimal places (trailing zeroes are included).- Parameters:
aVector- array to formatdigits- number of decimal places- Returns:
- formatted
double[]as String
-
formatFix
Format array/matrix of doublesaMatrixas String. Column elements are separated by '", "' and rows of elements by '"; "'. Each element is formatted withdigitsdecimal places (trailing zeroes are included).- Parameters:
aMatrix- array to formatdigits- number of decimal places- Returns:
- formatted
double[][]as String
-
formatSci
Format doubleaDoubleas String with up todigitsdecimal places (trailing zeroes are suppressed) forcing scientific formatting including exponent (separated by 'E').- Parameters:
aDouble- number to formatdigits- number of decimal places- Returns:
- formatted
doubleas String
-
formatSci
Format array/vector of doublesaVectoras String. Elements are separated by '", "' and formatted with up todigitsdecimal 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 doublesaMatrixas String. Column elements are separated by '", "' and rows of elements by '"; "'. Each element is formatted with up todigitsdecimal 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 doubleaDoubleas HTML string withdigitsdecimal places (trailing zeroes are included).- Parameters:
aDouble- the number to formatdigits- the number of decimal places- Returns:
- the formatted
doubleas 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
doubleas 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 doubleaDoubleas percent String withdigitsdecimal places (trailing zeroes are included).- Parameters:
aDouble- number to formatdigits- number of decimal places- Returns:
- formatted
doubleas String
-