public final class FormatUtil extends Object
Modifier and Type | Field and Description |
---|---|
private static NumberFormatException |
EMPTY_STRING
Preallocated exceptions.
|
private static NumberFormatException |
EXPONENT_OVERFLOW
Preallocated exceptions.
|
private static int |
INFINITY_LENGTH
Length of pattern
|
private static char[] |
INFINITY_PATTERN
Infinity pattern, with any capitalization
|
private static NumberFormatException |
INVALID_EXPONENT
Preallocated exceptions.
|
private static int |
MAX_INT_OVERFLOW
Maximum integer that we can process without overflowing.
|
private static long |
MAX_LONG_OVERFLOW
Maximum long that we can process without overflowing.
|
static String |
NEWLINE
The system newline setting.
|
static NumberFormat |
NF
Dynamic number formatter, but with language constraint.
|
static NumberFormat |
NF0
Number Formatter (0 digits) for output purposes.
|
static NumberFormat |
NF2
Number Formatter (2 digits) for output purposes.
|
static NumberFormat |
NF3
Number Formatter (3 digits) for output purposes.
|
static NumberFormat |
NF4
Number Formatter (4 digits) for output purposes.
|
static NumberFormat |
NF6
Number Formatter (6 digits) for output purposes.
|
static NumberFormat |
NF8
Number Formatter (8 digits) for output purposes.
|
static String |
NONBREAKING_SPACE
Non-breaking unicode space character.
|
private static NumberFormatException |
NOT_A_NUMBER
Preallocated exceptions.
|
private static NumberFormatException |
PRECISION_OVERFLOW
Preallocated exceptions.
|
private static char[] |
SPACEPADDING
Buffer for whitespace padding.
|
private static int[] |
TIME_UNIT_DIGITS
The number of digits used for formatting
|
private static 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 NumberFormatException |
TRAILING_CHARACTERS
Preallocated exceptions.
|
private static String |
WHITESPACE_BUFFER
Whitespace.
|
private static char[] |
ZEROPADDING
Buffer for zero padding.
|
Constructor and Description |
---|
FormatUtil() |
Modifier and Type | Method and Description |
---|---|
static StringBuilder |
appendSpace(StringBuilder buf,
int spaces)
Append whitespace to a buffer.
|
static StringBuilder |
appendZeros(StringBuilder buf,
int zeros)
Append zeros to a buffer.
|
static int |
findSplitpoint(String s,
int width)
Find the first space before position w or if there is none after w.
|
static String |
format(boolean b)
Formats the boolean b.
|
static String |
format(boolean[] b,
String sep)
Formats the boolean array b with ',' as separator.
|
static StringBuilder |
format(boolean b,
StringBuilder buf)
Format a boolean value as string "true" or "false".
|
static String |
format(byte[] a)
Formats the byte array a for printing purposes.
|
static String |
format(Collection<String> d,
String sep)
Formats the String collection with the specified separator.
|
static String |
format(double[] d)
Formats the double array d with ', ' as separator and 2 fraction digits.
|
static String |
format(double[][] d)
Formats the double array d with ',' as separator and 2 fraction digits.
|
static String |
format(double[][] d,
String sep1,
String sep2,
NumberFormat nf)
Formats the array of double arrays d with 'the specified separators and
fraction digits.
|
static String |
format(double[] d,
NumberFormat nf)
Formats the double array d with the specified number format.
|
static String |
format(double[] d,
String sep)
Formats the double array d with the specified separator.
|
static String |
format(double[] d,
String sep,
NumberFormat nf)
Formats the double array d with the specified number format.
|
static String |
format(float[] f)
Formats the float array f with ',' as separator and 2 fraction digits.
|
static String |
format(float[] d,
String sep,
NumberFormat nf)
Formats the double array d with the specified number format.
|
static String |
format(int[] a)
Formats the int array a for printing purposes.
|
static String |
format(int[] a,
String sep)
Formats the int array a for printing purposes.
|
static String |
format(int dim,
long[] bitSet)
Returns a string representation of the specified bit set.
|
static StringBuilder |
format(int i,
StringBuilder buf)
Format an integer value as decimal.
|
static String |
format(long[] a)
Formats the long array a for printing purposes.
|
static String |
format(long[] bitSet,
int dim,
String sep)
Returns a string representation of the specified bit set.
|
static StringBuilder |
format(long i,
StringBuilder buf)
Format a long value as decimal.
|
static String |
format(Matrix m)
returns String-representation of Matrix.
|
static String |
format(Matrix m,
int w,
int d)
Returns a string representation of this matrix.
|
static String |
format(Matrix m,
NumberFormat nf)
returns String-representation of Matrix.
|
static String |
format(Matrix m,
String pre)
Returns a string representation of this matrix.
|
static String |
format(Matrix m,
String pre,
NumberFormat nf)
Returns a string representation of this matrix.
|
static String |
format(String[] d,
String sep)
Formats the string array d with the specified separator.
|
static String |
format(Vector m)
Returns String-representation of Vector.
|
static String |
format(Vector v,
int w,
int d)
Returns a string representation of this matrix.
|
static String |
format(Vector m,
NumberFormat nf)
returns String-representation of Vector.
|
static String |
format(Vector v,
String pre)
Returns a string representation of this matrix.
|
static StringBuilder |
formatBit(boolean b,
StringBuilder buf)
Format a boolean value as string "1" or "0".
|
static String |
formatTimeDelta(long time,
CharSequence sep)
Formats a time delta in human readable format.
|
static StringBuilder |
formatTo(StringBuilder a,
double[] d,
String sep)
Formats the double array d with the specified number format.
|
static StringBuilder |
formatTo(StringBuilder a,
double[] d,
String sep,
NumberFormat nf)
Formats the double array d with the specified number format.
|
static int |
getConsoleWidth()
Get the width of the terminal window (on Unix xterms), with a default of 78
characters.
|
static NumberFormat |
makeNumberFormat(int digits)
Initialize a number format with ELKI standard options (US locale, no
grouping).
|
private static boolean |
matchInf(byte[] str,
byte firstchar,
int start,
int end)
Match "inf", "infinity" in a number of different capitalizations.
|
private static boolean |
matchInf(CharSequence str,
char firstchar,
int start,
int end)
Match "inf", "infinity" in a number of different capitalizations.
|
private static boolean |
matchNaN(byte[] str,
byte firstchar,
int start,
int end)
Match "NaN" in a number of different capitalizations.
|
private static boolean |
matchNaN(CharSequence str,
char firstchar,
int start,
int end)
Match "NaN" in a number of different capitalizations.
|
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 String |
pad(String o,
int len)
Pad a string to a given length by adding whitespace to the right.
|
static String |
padRightAligned(String o,
int len)
Pad a string to a given length by adding whitespace to the left.
|
static double |
parseDouble(byte[] str,
int start,
int end)
Parse a double from a character sequence.
|
static double |
parseDouble(CharSequence str)
Parse a double from a character sequence.
|
static double |
parseDouble(CharSequence str,
int start,
int end)
Parse a double from a character sequence.
|
static long |
parseLongBase10(CharSequence str,
int start,
int end)
Parse a long integer from a character sequence.
|
static List<String> |
splitAtLastBlank(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 String |
whitespace(int n)
Returns a string with the specified number of whitespace.
|
public static final NumberFormat NF
public static final NumberFormat NF0
public static final NumberFormat NF2
public static final NumberFormat NF3
public static final NumberFormat NF4
public static final NumberFormat NF6
public static final NumberFormat NF8
private static final String WHITESPACE_BUFFER
public static final String NEWLINE
public static final String NONBREAKING_SPACE
private static final long[] TIME_UNIT_SIZES
private static final String[] TIME_UNIT_NAMES
private static final int[] TIME_UNIT_DIGITS
private static final NumberFormatException EMPTY_STRING
private static final NumberFormatException EXPONENT_OVERFLOW
private static final NumberFormatException INVALID_EXPONENT
private static final NumberFormatException TRAILING_CHARACTERS
private static final NumberFormatException PRECISION_OVERFLOW
private static final NumberFormatException NOT_A_NUMBER
private static final long MAX_LONG_OVERFLOW
private static final int MAX_INT_OVERFLOW
private static final char[] INFINITY_PATTERN
private static final int INFINITY_LENGTH
private static final char[] ZEROPADDING
private static final char[] SPACEPADDING
public static NumberFormat makeNumberFormat(int digits)
digits
- Number of digits to usepublic static String format(double[] d, String sep)
d
- the double array to be formattedsep
- the separator between the single values of the double array,
e.g. ','public static String format(double[] d, NumberFormat nf)
d
- the double array to be formattednf
- the number format to be used for formattingpublic static String format(double[] d, String sep, NumberFormat nf)
d
- the double array to be formattedsep
- the separator between the single values of the double array,
e.g. ','nf
- the number format to be used for formattingpublic static StringBuilder formatTo(StringBuilder a, double[] d, String sep)
d
- the double array to be formattedsep
- the separator between the single values of the double array,
e.g. ','public static StringBuilder formatTo(StringBuilder a, double[] d, String sep, NumberFormat nf)
d
- the double array to be formattedsep
- the separator between the single values of the double array,
e.g. ','nf
- the number format to be used for formattingpublic static String format(double[] d)
d
- the double array to be formattedpublic static String format(double[][] d)
d
- the double array to be formattedpublic static String format(double[][] d, String sep1, String sep2, NumberFormat nf)
d
- the double array to be formattedsep1
- the first separator of the outer arraysep2
- the second separator of the inner arraynf
- the number format to usepublic static String format(float[] d, String sep, NumberFormat nf)
d
- the double array to be formattedsep
- the separator between the single values of the double array,
e.g. ','nf
- the number format to be used for formattingpublic static String format(float[] f)
f
- the float array to be formattedpublic static String format(int[] a, String sep)
a
- the int array to be formattedsep
- the separator between the single values of the float array, e.g.
','public static String format(int[] a)
a
- the int array to be formattedpublic static String format(long[] a)
a
- the long array to be formattedpublic static String format(byte[] a)
a
- the byte array to be formattedpublic static String format(boolean[] b, String sep)
b
- the boolean array to be formattedsep
- the separator between the single values of the double array,
e.g. ','public static String format(boolean b)
b
- the boolean to be formattedpublic static String format(long[] bitSet, int dim, String sep)
bitSet
- the bitSetdim
- the overall dimensionality of the bit setsep
- the separatorpublic static String format(int dim, long[] bitSet)
dim
- the overall dimensionality of the bit setbitSet
- the bitSetpublic static String format(Collection<String> d, String sep)
d
- the String collection to formatsep
- the separator between the single values of the double array,
e.g. ' 'public static String format(Matrix m, int w, int d)
w
- column widthd
- number of digits after the decimalpublic static String format(Vector v, int w, int d)
w
- column widthd
- number of digits after the decimalpublic static String format(Matrix m, String pre)
pre
is prefixed.pre
- the prefix of each linepublic static String format(Matrix m, NumberFormat nf)
nf
- NumberFormat to specify output precisionpublic static String format(Matrix m)
public static String format(Vector m, NumberFormat nf)
nf
- NumberFormat to specify output precisionpublic static String format(Vector m)
public static String format(Vector v, String pre)
pre
is prefixed.pre
- the prefix of each linepublic static String format(Matrix m, String pre, NumberFormat nf)
pre<\code> is prefixed.
nf
- number format for output accuracypre
- the prefix of each linepublic static int findSplitpoint(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 positive.public static List<String> splitAtLastBlank(String s, int width)
s
- the string to be splitwidth
- intpublic static String whitespace(int n)
n
- the number of whitespace characterspublic static String pad(String o, int len)
o
- original stringlen
- destination lengthpublic static String padRightAligned(String o, int len)
o
- original stringlen
- destination lengthpublic static int getConsoleWidth()
public static String formatTimeDelta(long time, CharSequence sep)
time
- time delta in mspublic static String format(String[] d, String sep)
d
- the string array to be formattedsep
- the separator between the single values of the double array,
e.g. ','public static double parseDouble(CharSequence str)
Double.parseDouble(java.lang.String)
, this will not
create an object and thus is expected to put less load on the garbage
collector. It will accept some more spellings of NaN and infinity, thus
removing the need for checking for these independently.str
- Stringpublic static double parseDouble(CharSequence str, int start, int end)
Double.parseDouble(java.lang.String)
, this will not
create an object and thus is expected to put less load on the garbage
collector. It will accept some more spellings of NaN and infinity, thus
removing the need for checking for these independently.str
- Stringstart
- Beginend
- Endpublic static double parseDouble(byte[] str, int start, int end)
Double.parseDouble(java.lang.String)
, this will not
create an object and thus is expected to put less load on the garbage
collector. It will accept some more spellings of NaN and infinity, thus
removing the need for checking for these independently.str
- Stringstart
- Beginend
- Endprivate static boolean matchNaN(CharSequence str, char firstchar, int start, int end)
str
- String to matchfirstchar
- First characterstart
- Interval beginend
- Interval endtrue
when NaN was recognized.private static boolean matchNaN(byte[] str, byte firstchar, int start, int end)
str
- String to matchfirstchar
- First characterstart
- Interval beginend
- Interval endtrue
when NaN was recognized.private static boolean matchInf(CharSequence str, char firstchar, int start, int end)
str
- String to matchfirstchar
- First characterstart
- Interval beginend
- Interval endtrue
when infinity was recognized.private static boolean matchInf(byte[] str, byte firstchar, int start, int end)
str
- String to matchfirstchar
- First characterstart
- Interval beginend
- Interval endtrue
when infinity was recognized.public static long parseLongBase10(CharSequence str, int start, int end)
str
- Stringstart
- Beginend
- Endpublic static StringBuilder format(boolean b, StringBuilder buf)
b
- Boolean to Formatbuf
- Buffer to append topublic static StringBuilder formatBit(boolean b, StringBuilder buf)
b
- Boolean to Formatbuf
- Buffer to append topublic static StringBuilder format(int i, StringBuilder buf)
i
- Integer value to format.buf
- Buffer to append topublic static StringBuilder format(long i, StringBuilder buf)
i
- Long value to format.buf
- Buffer to append topublic static StringBuilder appendZeros(StringBuilder buf, int zeros)
buf
- Buffer to append tozeros
- Number of zeros to append.public static StringBuilder appendSpace(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 valueCopyright © 2015 ELKI Development Team, Lehr- und Forschungseinheit für Datenbanksysteme, Ludwig-Maximilians-Universität München. License information.