public final class FormatUtil
extends java.lang.Object
FIXME: Handle formatting of infinity and NaN better.
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
NEWLINE
The system newline setting.
|
static java.text.NumberFormat |
NF
Dynamic number formatter, but with language constraint.
|
static java.text.NumberFormat |
NF0
Number Formatter (0 digits) for output purposes.
|
static java.text.NumberFormat |
NF16
Number Formatter (16 digits) for output purposes.
|
static java.text.NumberFormat |
NF2
Number Formatter (2 digits) for output purposes.
|
static java.text.NumberFormat |
NF3
Number Formatter (3 digits) for output purposes.
|
static java.text.NumberFormat |
NF4
Number Formatter (4 digits) for output purposes.
|
static java.text.NumberFormat |
NF6
Number Formatter (6 digits) for output purposes.
|
static java.text.NumberFormat |
NF8
Number Formatter (8 digits) for output purposes.
|
static char |
NONBREAKING_SPACE
Non-breaking unicode space character.
|
private static char[] |
SPACEPADDING
Buffer for whitespace padding.
|
private static int[] |
TIME_UNIT_DIGITS
The number of digits used for formatting
|
private static java.lang.String[] |
TIME_UNIT_NAMES
The strings used in serialization
|
private static long[] |
TIME_UNIT_SIZES
The time unit sizes: ms, s, m, h, d; all in ms.
|
private static java.lang.String |
WHITESPACE_BUFFER
Whitespace.
|
private static int |
WHITESPACE_BUFFER_LENGTH
Length of the whitespace buffer.
|
private static int |
width
Terminal width cache.
|
private static char[] |
ZEROPADDING
Buffer for zero padding.
|
Modifier | Constructor and Description |
---|---|
private |
FormatUtil()
Private constructor.
|
Modifier and Type | Method and Description |
---|---|
static java.lang.StringBuilder |
appendSpace(java.lang.StringBuilder buf,
int spaces)
Append whitespace to a buffer.
|
static java.lang.StringBuilder |
appendZeros(java.lang.StringBuilder buf,
int zeros)
Append zeros to a buffer.
|
static boolean |
endsWith(java.lang.CharSequence buf,
java.lang.CharSequence end)
Similar to
String.endsWith(String) but for buffers. |
static int |
findSplitpoint(java.lang.String s,
int width)
Find the first space before position w or if there is none after w.
|
static java.lang.String |
format(boolean b)
Formats the boolean b.
|
static java.lang.String |
format(boolean[] b,
java.lang.String sep)
Formats the boolean array b with ',' as separator.
|
static java.lang.String |
format(byte[] a)
Formats the byte array a for printing purposes.
|
static java.lang.String |
format(java.util.Collection<java.lang.String> d,
java.lang.String sep)
Formats the String collection with the specified separator.
|
static java.lang.String |
format(double[] d)
Formats the double array d with ', ' as separator and default precision.
|
static java.lang.String |
format(double[][] d)
Formats the double array d with ',' as separator and 2 fraction digits.
|
static java.lang.String |
format(double[][] m,
int w,
int d,
java.lang.String pre,
java.lang.String pos,
java.lang.String csep)
Returns a string representation of this matrix.
|
static java.lang.String |
format(double[][] m,
java.text.NumberFormat nf)
returns String-representation of Matrix.
|
static java.lang.String |
format(double[][] m,
java.lang.String pre)
Returns a string representation of this matrix.
|
static java.lang.String |
format(double[][] d,
java.lang.String pre,
java.lang.String pos,
java.lang.String csep,
java.text.NumberFormat nf)
Formats the array of double arrays d with 'the specified separators and
fraction digits.
|
static java.lang.String |
format(double[] v,
int w,
int d)
Returns a string representation of this vector.
|
static java.lang.String |
format(double[] d,
java.text.NumberFormat nf)
Formats the double array d with the specified number format.
|
static java.lang.String |
format(double[] d,
java.lang.String sep)
Formats the double array d with the specified separator.
|
static java.lang.String |
format(double[] d,
java.lang.String sep,
java.text.NumberFormat nf)
Formats the double array d with the specified number format.
|
static java.lang.String |
format(float[] f)
Formats the float array f with ',' as separator and default precision.
|
static java.lang.String |
format(float[] d,
java.lang.String sep)
Formats the float array d with the specified number format.
|
static java.lang.String |
format(float[] d,
java.lang.String sep,
java.text.NumberFormat nf)
Formats the float array d with the specified number format.
|
static java.lang.String |
format(int[] a)
Formats the int array a for printing purposes.
|
static java.lang.String |
format(int[] a,
java.lang.String sep)
Formats the int array a for printing purposes.
|
static java.lang.String |
format(long[] a)
Formats the long array a for printing purposes.
|
static java.lang.String |
format(java.lang.String[] d,
java.lang.String sep)
Formats the string array d with the specified separator.
|
static java.lang.StringBuilder |
formatBit(java.lang.StringBuilder buf,
boolean b)
Format a boolean value as string "1" or "0".
|
static java.lang.String |
formatTimeDelta(long time,
java.lang.CharSequence sep)
Formats a time delta in human readable format.
|
static java.lang.StringBuilder |
formatTo(java.lang.StringBuilder buf,
boolean b)
Format a boolean value as string "true" or "false".
|
static java.lang.StringBuilder |
formatTo(java.lang.StringBuilder buf,
boolean[] d,
java.lang.String sep)
Formats the boolean array d.
|
static java.lang.StringBuilder |
formatTo(java.lang.StringBuilder buf,
byte[] d,
java.lang.String sep)
Formats the byte array d.
|
static java.lang.StringBuilder |
formatTo(java.lang.StringBuilder buf,
double[][] d,
java.lang.String pre,
java.lang.String pos,
java.lang.String csep,
java.text.NumberFormat nf)
Formats the array of double arrays d with the specified separators and
fraction digits.
|
static java.lang.StringBuilder |
formatTo(java.lang.StringBuilder buf,
double[] d,
java.lang.String sep)
Formats the double array d with the default number format.
|
static java.lang.StringBuilder |
formatTo(java.lang.StringBuilder buf,
double[] d,
java.lang.String sep,
java.text.NumberFormat nf)
Formats the double array d with the specified number format.
|
static java.lang.StringBuilder |
formatTo(java.lang.StringBuilder buf,
float[] d,
java.lang.String sep)
Formats the float array d with the default number format.
|
static java.lang.StringBuilder |
formatTo(java.lang.StringBuilder buf,
float[] d,
java.lang.String sep,
java.text.NumberFormat nf)
Formats the float array d with the specified number format.
|
static java.lang.StringBuilder |
formatTo(java.lang.StringBuilder buf,
int[] d,
java.lang.String sep)
Formats the int array d.
|
static java.lang.StringBuilder |
formatTo(java.lang.StringBuilder buf,
long[] d,
java.lang.String sep)
Formats the long array d.
|
static java.lang.StringBuilder |
formatTo(java.lang.StringBuilder buf,
short[] d,
java.lang.String sep)
Formats the short array d.
|
static int |
getConsoleWidth()
Get the width of the terminal window (on Unix xterms), with a default of 78
characters.
|
static java.text.NumberFormat |
makeNumberFormat(int digits)
Initialize a number format with ELKI standard options (US locale, no
grouping).
|
private static int |
nextPosition(int a,
int b)
Helper that is similar to
Math.min(a,b) , except that negative
values are considered "invalid". |
static java.lang.String |
pad(java.lang.String o,
int len)
Pad a string to a given length by adding whitespace to the right.
|
static java.lang.String |
padRightAligned(java.lang.String o,
int len)
Pad a string to a given length by adding whitespace to the left.
|
static java.util.List<java.lang.String> |
splitAtLastBlank(java.lang.String s,
int width)
Splits the specified string at the last blank before width.
|
static int |
stringSize(int x)
Compute the number of characters needed to represent the integer x.
|
static int |
stringSize(long x)
Compute the number of characters needed to represent the integer x.
|
static java.lang.String |
whitespace(int n)
Returns a string with the specified number of whitespace.
|
static java.lang.StringBuilder |
whitespace(java.lang.StringBuilder buf,
int n)
Returns a string with the specified number of whitespace.
|
public static final java.text.NumberFormat NF
public static final java.text.NumberFormat NF0
public static final java.text.NumberFormat NF2
public static final java.text.NumberFormat NF3
public static final java.text.NumberFormat NF4
public static final java.text.NumberFormat NF6
public static final java.text.NumberFormat NF8
public static final java.text.NumberFormat NF16
private static final java.lang.String WHITESPACE_BUFFER
private static final int WHITESPACE_BUFFER_LENGTH
public static final java.lang.String NEWLINE
public static final char NONBREAKING_SPACE
private static final long[] TIME_UNIT_SIZES
private static final java.lang.String[] TIME_UNIT_NAMES
private static final int[] TIME_UNIT_DIGITS
private static int width
private static final char[] ZEROPADDING
private static final char[] SPACEPADDING
public static java.text.NumberFormat makeNumberFormat(int digits)
digits
- Number of digits to usepublic static java.lang.String format(double[] d)
d
- the double array to be formattedpublic static java.lang.String format(double[] d, java.lang.String sep)
d
- the double array to be formattedsep
- separator between the single values of the array, e.g. ','public static java.lang.String format(double[] d, java.text.NumberFormat nf)
d
- the double array to be formattednf
- the number format to be used for formattingpublic static java.lang.String format(double[] d, java.lang.String sep, java.text.NumberFormat nf)
d
- the double array to be formattedsep
- separator between the single values of the array, e.g. ','nf
- the number format to be used for formattingpublic static java.lang.String format(double[] v, int w, int d)
w
- column widthd
- number of digits after the decimalpublic static java.lang.StringBuilder formatTo(java.lang.StringBuilder buf, double[] d, java.lang.String sep)
buf
- String builder to append tod
- the double array to be formattedsep
- separator between the single values of the array, e.g. ','public static java.lang.StringBuilder formatTo(java.lang.StringBuilder buf, double[] d, java.lang.String sep, java.text.NumberFormat nf)
buf
- String builder to append tod
- the double array to be formattedsep
- separator between the single values of the array, e.g. ','nf
- the number format to be used for formattingpublic static java.lang.StringBuilder formatTo(java.lang.StringBuilder buf, float[] d, java.lang.String sep)
buf
- String builder to append tod
- the float array to be formattedsep
- separator between the single values of the array, e.g. ','public static java.lang.StringBuilder formatTo(java.lang.StringBuilder buf, float[] d, java.lang.String sep, java.text.NumberFormat nf)
buf
- String builder to append tod
- the float array to be formattedsep
- separator between the single values of the array, e.g. ','nf
- the number format to be used for formattingpublic static java.lang.StringBuilder formatTo(java.lang.StringBuilder buf, int[] d, java.lang.String sep)
buf
- String builder to append tod
- the int array to be formattedsep
- separator between the single values of the array, e.g. ','public static java.lang.StringBuilder formatTo(java.lang.StringBuilder buf, long[] d, java.lang.String sep)
buf
- String builder to append tod
- the long array to be formattedsep
- separator between the single values of the long array, e.g. ','public static java.lang.StringBuilder formatTo(java.lang.StringBuilder buf, short[] d, java.lang.String sep)
buf
- String builder to append tod
- the int array to be formattedsep
- separator between the single values of the array, e.g. ','public static java.lang.StringBuilder formatTo(java.lang.StringBuilder buf, byte[] d, java.lang.String sep)
buf
- String builder to append tod
- the byte array to be formattedsep
- separator between the single values of the array, e.g. ','public static java.lang.StringBuilder formatTo(java.lang.StringBuilder buf, boolean[] d, java.lang.String sep)
buf
- String builder to append tod
- the boolean array to be formattedsep
- separator between the single values of the array, e.g. ','public static java.lang.StringBuilder formatTo(java.lang.StringBuilder buf, boolean b)
buf
- Buffer to append tob
- Boolean to Formatpublic static java.lang.StringBuilder formatBit(java.lang.StringBuilder buf, boolean b)
buf
- Buffer to append tob
- Boolean to Formatpublic static java.lang.String format(float[] d, java.lang.String sep, java.text.NumberFormat nf)
d
- the float array to be formattedsep
- separator between the single values of the array, e.g. ','nf
- the number format to be used for formattingpublic static java.lang.String format(float[] d, java.lang.String sep)
d
- the float array to be formattedsep
- separator between the single values of the array, e.g. ','public static java.lang.String format(float[] f)
f
- the float array to be formattedpublic static java.lang.String format(int[] a, java.lang.String sep)
a
- the int array to be formattedsep
- the separator between the single values of the array, e.g. ','public static java.lang.String format(int[] a)
a
- the int array to be formattedpublic static java.lang.String format(long[] a)
a
- the long array to be formattedpublic static java.lang.String format(byte[] a)
a
- the byte array to be formattedpublic static java.lang.String format(boolean[] b, java.lang.String sep)
b
- the boolean array to be formattedsep
- separator between the single values of the array, e.g. ','public static java.lang.String format(boolean b)
b
- the boolean to be formattedpublic static java.lang.StringBuilder formatTo(java.lang.StringBuilder buf, double[][] d, java.lang.String pre, java.lang.String pos, java.lang.String csep, java.text.NumberFormat nf)
buf
- Output bufferd
- the double array to be formattedpre
- Row prefix (e.g. " [")pos
- Row postfix (e.g. "]\n")csep
- Separator for columns (e.g. ", ")nf
- the number format to usepublic static java.lang.String format(double[][] d)
d
- the double array to be formattedpublic static java.lang.String format(double[][] d, java.lang.String pre, java.lang.String pos, java.lang.String csep, java.text.NumberFormat nf)
d
- the double matrix to be formattedpre
- Row prefix (e.g. " [")pos
- Row postfix (e.g. "]\n")csep
- Separator for columns (e.g. ", ")nf
- the number format to usepublic static java.lang.String format(double[][] m, int w, int d, java.lang.String pre, java.lang.String pos, java.lang.String csep)
w
- column widthd
- number of digits after the decimalpre
- Row prefix (e.g. " [")pos
- Row postfix (e.g. "]\n")csep
- Column separator (e.g. ", ")public static java.lang.String format(double[][] m, java.lang.String pre)
pre
is prefixed.pre
- the prefix of each linepublic static java.lang.String format(double[][] m, java.text.NumberFormat nf)
nf
- NumberFormat to specify output precisionpublic static java.lang.String format(java.util.Collection<java.lang.String> d, java.lang.String sep)
d
- the String collection to formatsep
- separator between the single values of the array, e.g. ' 'public static java.lang.String format(java.lang.String[] d, java.lang.String sep)
d
- the string array to be formattedsep
- separator between the single values of the array, e.g. ','public static int findSplitpoint(java.lang.String s, int width)
s
- Stringwidth
- Width-1
if no whitespace was
found.private static int nextPosition(int a, int b)
Math.min(a,b)
, except that negative
values are considered "invalid".a
- String positionb
- String positionMath.min(a,b)
if a >= 0
and b >= 0
,
otherwise whichever is not negative.public static java.util.List<java.lang.String> splitAtLastBlank(java.lang.String s, int width)
s
- the string to be splitwidth
- intpublic static java.lang.String whitespace(int n)
n
- the number of whitespace characterspublic static java.lang.StringBuilder whitespace(java.lang.StringBuilder buf, int n)
n
- the number of whitespace characterspublic static java.lang.String pad(java.lang.String o, int len)
o
- original stringlen
- destination lengthpublic static java.lang.String padRightAligned(java.lang.String o, int len)
o
- original stringlen
- destination lengthpublic static int getConsoleWidth()
public static java.lang.String formatTimeDelta(long time, java.lang.CharSequence sep)
time
- time delta in mspublic static java.lang.StringBuilder appendZeros(java.lang.StringBuilder buf, int zeros)
buf
- Buffer to append tozeros
- Number of zeros to append.public static java.lang.StringBuilder appendSpace(java.lang.StringBuilder buf, int spaces)
buf
- Buffer to append tospaces
- Number of spaces to append.public static int stringSize(int x)
Long.stringSize(long)
, but public and without loop.x
- Integer valuepublic static int stringSize(long x)
Long.stringSize(long)
, but public and without loop.x
- Integer valuepublic static boolean endsWith(java.lang.CharSequence buf, java.lang.CharSequence end)
String.endsWith(String)
but for buffers.buf
- Bufferend
- Endtrue
if the buffer ends with the given sequenceCopyright © 2019 ELKI Development Team. License information.