Module math

Class FormatUtil

java.lang.Object
de.lmu.ifi.dbs.elki.utilities.FormatUtil

public final class FormatUtil extends Object
Utility methods for output formatting of various number objects
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
    The system newline setting.
    static final NumberFormat
    Dynamic number formatter, but with language constraint.
    static final NumberFormat
    Number Formatter (0 digits) for output purposes.
    static final NumberFormat
    Number Formatter (2 digits) for output purposes.
    static final NumberFormat
    Number Formatter (4 digits) for output purposes.
    static final NumberFormat
    Number Formatter (6 digits) for output purposes.
    static final NumberFormat
    Number Formatter (8 digits) for output purposes.
    static final String
    Non-breaking unicode space character.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    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 String
    format(byte[] a)
    Formats the byte array a for printing purposes.
    static String
    format(double d)
    Formats the double d with 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)
    Formats the double array d with ',' as separator and 2 fraction digits.
    static String
    format(double[][] d, String sep1, String sep2, int digits)
    Formats the array of double arrays d with 'the specified separators and fraction digits.
    static String
    format(double[] d, int digits)
    Formats the double array d with ', ' as separator and with the specified fraction digits.
    static String
    format(double[] d, String sep)
    Formats the double array d with the specified separator.
    static String
    format(double[] d, String sep, int digits)
    Formats the double array d with the specified separator and the specified fraction digits.
    static String
    format(double[] d, String sep, NumberFormat nf)
    Formats the double array d with the specified number format.
    static String
    format(double[] d, NumberFormat nf)
    Formats the double array d with the specified number format.
    static String
    format(double d, int digits)
    Formats the double d with the specified fraction digits.
    static String
    format(double d, NumberFormat nf)
    Formats the double 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[] f, String sep, int digits)
    Formats the float array f with the specified separator and the specified fraction digits.
    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, BitSet bitSet)
    Returns a string representation of the specified bit set.
    static String
    format(long[] a)
    Formats the long array a for printing purposes.
    static String
    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, String pre)
    Returns a string representation of this matrix.
    static String
    Returns a string representation of this matrix.
    static String
    returns String-representation of Matrix.
    static String
    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 v, String pre)
    Returns a string representation of this matrix.
    static String
    returns String-representation of Vector.
    static String
    Formats the Double array f with ',' as separator and 2 fraction digits.
    static String
    format(Double[] f, String sep, int digits)
    Formats the Double array f with the specified separator and the specified fraction digits.
    static String
    format(Double[] f, String sep, NumberFormat nf)
    Formats the Double array f with the specified separator and the specified fraction digits.
    static String
    Formats the Double array f with ',' as separator and 2 fraction digits.
    static String
    Formats the Integer array a for printing purposes.
    static String
    format(Integer[] a, String sep)
    Formats the Integer array a for printing purposes.
    static String
    format(String[] d, String sep)
    Formats the string array d with the specified separator.
    static String
    format(BitSet bitSet, int dim, String sep)
    Returns a string representation of the specified bit set.
    static String
    Formats the String collection with the specified separator.
    static String
    formatTimeDelta(long time, CharSequence sep)
    Formats a time delta in human readable format.
    static int
    Get the width of the terminal window (on Unix xterms), with a default of 78 characters.
    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 List<String>
    splitAtLastBlank(String s, int width)
    Splits the specified string at the last blank before width.
    static String
    whitespace(int n)
    Returns a string with the specified number of whitespace.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • NF

      public static final NumberFormat NF
      Dynamic number formatter, but with language constraint.
    • NF0

      public static final NumberFormat NF0
      Number Formatter (0 digits) for output purposes.
    • NF2

      public static final NumberFormat NF2
      Number Formatter (2 digits) for output purposes.
    • NF4

      public static final NumberFormat NF4
      Number Formatter (4 digits) for output purposes.
    • NF6

      public static final NumberFormat NF6
      Number Formatter (6 digits) for output purposes.
    • NF8

      public static final NumberFormat NF8
      Number Formatter (8 digits) for output purposes.
    • NEWLINE

      public static final String NEWLINE
      The system newline setting.
    • NONBREAKING_SPACE

      public static final String NONBREAKING_SPACE
      Non-breaking unicode space character.
      See Also:
  • Constructor Details

    • FormatUtil

      public FormatUtil()
  • Method Details

    • format

      public static String format(double d, int digits)
      Formats the double d with the specified fraction digits.
      Parameters:
      d - the double array to be formatted
      digits - the number of fraction digits
      Returns:
      a String representing the double d
    • format

      public static String format(double d, NumberFormat nf)
      Formats the double d with the specified number format.
      Parameters:
      d - the double array to be formatted
      nf - the number format to be used for formatting
      Returns:
      a String representing the double d
    • format

      public static String format(double d)
      Formats the double d with 2 fraction digits.
      Parameters:
      d - the double to be formatted
      Returns:
      a String representing the double d
    • format

      public static String format(double[] d, String sep)
      Formats the double array d with the specified separator.
      Parameters:
      d - the double array to be formatted
      sep - the separator between the single values of the double array, e.g. ','
      Returns:
      a String representing the double array d
    • format

      public static String format(double[] d, String sep, int digits)
      Formats the double array d with the specified separator and the specified fraction digits.
      Parameters:
      d - the double array to be formatted
      sep - the separator between the single values of the double array, e.g. ','
      digits - the number of fraction digits
      Returns:
      a String representing the double array d
    • format

      public static String format(double[] d, NumberFormat nf)
      Formats the double array d with the specified number format.
      Parameters:
      d - the double array to be formatted
      nf - the number format to be used for formatting
      Returns:
      a String representing the double array d
    • format

      public static String format(double[] d, String sep, NumberFormat nf)
      Formats the double array d with the specified number format.
      Parameters:
      d - the double array to be formatted
      sep - the separator between the single values of the double array, e.g. ','
      nf - the number format to be used for formatting
      Returns:
      a String representing the double array d
    • format

      public static String format(double[] d)
      Formats the double array d with ',' as separator and 2 fraction digits.
      Parameters:
      d - the double array to be formatted
      Returns:
      a String representing the double array d
    • format

      public static String format(double[] d, int digits)
      Formats the double array d with ', ' as separator and with the specified fraction digits.
      Parameters:
      d - the double array to be formatted
      digits - the number of fraction digits
      Returns:
      a String representing the double array d
    • format

      public static String format(double[][] d)
      Formats the double array d with ',' as separator and 2 fraction digits.
      Parameters:
      d - the double array to be formatted
      Returns:
      a String representing the double array d
    • format

      public static String format(double[][] d, String sep1, String sep2, int digits)
      Formats the array of double arrays d with 'the specified separators and fraction digits.
      Parameters:
      d - the double array to be formatted
      sep1 - the first separator of the outer array
      sep2 - the second separator of the inner array
      digits - the number of fraction digits
      Returns:
      a String representing the double array d
    • format

      public static String format(Double[] f, String sep, int digits)
      Formats the Double array f with the specified separator and the specified fraction digits.
      Parameters:
      f - the Double array to be formatted
      sep - the separator between the single values of the Double array, e.g. ','
      digits - the number of fraction digits
      Returns:
      a String representing the Double array f
    • format

      public static String format(Double[] f)
      Formats the Double array f with ',' as separator and 2 fraction digits.
      Parameters:
      f - the Double array to be formatted
      Returns:
      a String representing the Double array f
    • format

      public static String format(Double[] f, String sep, NumberFormat nf)
      Formats the Double array f with the specified separator and the specified fraction digits.
      Parameters:
      f - the Double array to be formatted
      sep - the separator between the single values of the Double array, e.g. ','
      nf - the number format
      Returns:
      a String representing the Double array f
    • format

      public static String format(Double[] f, NumberFormat nf)
      Formats the Double array f with ',' as separator and 2 fraction digits.
      Parameters:
      f - the Double array to be formatted
      nf - the Number format
      Returns:
      a String representing the Double array f
    • format

      public static String format(float[] f, String sep, int digits)
      Formats the float array f with the specified separator and the specified fraction digits.
      Parameters:
      f - the float array to be formatted
      sep - the separator between the single values of the float array, e.g. ','
      digits - the number of fraction digits
      Returns:
      a String representing the float array f
    • format

      public static String format(float[] f)
      Formats the float array f with ',' as separator and 2 fraction digits.
      Parameters:
      f - the float array to be formatted
      Returns:
      a String representing the float array f
    • format

      public static String format(int[] a, String sep)
      Formats the int array a for printing purposes.
      Parameters:
      a - the int array to be formatted
      sep - the separator between the single values of the float array, e.g. ','
      Returns:
      a String representing the int array a
    • format

      public static String format(int[] a)
      Formats the int array a for printing purposes.
      Parameters:
      a - the int array to be formatted
      Returns:
      a String representing the int array a
    • format

      public static String format(Integer[] a, String sep)
      Formats the Integer array a for printing purposes.
      Parameters:
      a - the Integer array to be formatted
      sep - the separator between the single values of the float array, e.g. ','
      Returns:
      a String representing the Integer array a
    • format

      public static String format(Integer[] a)
      Formats the Integer array a for printing purposes.
      Parameters:
      a - the Integer array to be formatted
      Returns:
      a String representing the Integer array a
    • format

      public static String format(long[] a)
      Formats the long array a for printing purposes.
      Parameters:
      a - the long array to be formatted
      Returns:
      a String representing the long array a
    • format

      public static String format(byte[] a)
      Formats the byte array a for printing purposes.
      Parameters:
      a - the byte array to be formatted
      Returns:
      a String representing the byte array a
    • format

      public static String format(boolean[] b, String sep)
      Formats the boolean array b with ',' as separator.
      Parameters:
      b - the boolean array to be formatted
      sep - the separator between the single values of the double array, e.g. ','
      Returns:
      a String representing the boolean array b
    • format

      public static String format(boolean b)
      Formats the boolean b.
      Parameters:
      b - the boolean to be formatted
      Returns:
      a String representing of the boolean b
    • format

      public static String format(BitSet bitSet, int dim, String sep)
      Returns a string representation of the specified bit set.
      Parameters:
      bitSet - the bitSet
      dim - the overall dimensionality of the bit set
      sep - the separator
      Returns:
      a string representation of the specified bit set.
    • format

      public static String format(int dim, BitSet bitSet)
      Returns a string representation of the specified bit set.
      Parameters:
      dim - the overall dimensionality of the bit set
      bitSet - the bitSet
      Returns:
      a string representation of the specified bit set.
    • format

      public static String format(Collection<String> d, String sep)
      Formats the String collection with the specified separator.
      Parameters:
      d - the String collection to format
      sep - the separator between the single values of the double array, e.g. ' '
      Returns:
      a String representing the String Collection d
    • format

      public static String format(Matrix m, int w, int d)
      Returns a string representation of this matrix.
      Parameters:
      w - column width
      d - number of digits after the decimal
      Returns:
      a string representation of this matrix
    • format

      public static String format(Vector v, int w, int d)
      Returns a string representation of this matrix.
      Parameters:
      w - column width
      d - number of digits after the decimal
      Returns:
      a string representation of this matrix
    • format

      public static String format(Matrix m, String pre)
      Returns a string representation of this matrix. In each line the specified String pre is prefixed.
      Parameters:
      pre - the prefix of each line
      Returns:
      a string representation of this matrix
    • format

      public static String format(Matrix m, NumberFormat nf)
      returns String-representation of Matrix.
      Parameters:
      nf - NumberFormat to specify output precision
      Returns:
      String representation of this Matrix in precision as specified by given NumberFormat
    • format

      public static String format(Matrix m)
      returns String-representation of Matrix.
      Returns:
      String representation of this Matrix
    • format

      public static String format(Vector m, NumberFormat nf)
      returns String-representation of Vector.
      Parameters:
      nf - NumberFormat to specify output precision
      Returns:
      String representation of this Matrix in precision as specified by given NumberFormat
    • format

      public static String format(Vector m)
      Returns String-representation of Vector.
      Returns:
      String representation of this Vector
    • format

      public static String format(Vector v, String pre)
      Returns a string representation of this matrix. In each line the specified String pre is prefixed.
      Parameters:
      pre - the prefix of each line
      Returns:
      a string representation of this matrix
    • format

      public static String format(Matrix m, String pre, NumberFormat nf)
      Returns a string representation of this matrix. In each line the specified String pre<\code> is prefixed.
      Parameters:
      nf - number format for output accuracy
      pre - the prefix of each line
      Returns:
      a string representation of this matrix
    • findSplitpoint

      public static int findSplitpoint(String s, int width)
      Find the first space before position w or if there is none after w.
      Parameters:
      s - String
      width - Width
      Returns:
      index of best whitespace or -1 if no whitespace was found.
    • splitAtLastBlank

      public static List<String> splitAtLastBlank(String s, int width)
      Splits the specified string at the last blank before width. If there is no blank before the given width, it is split at the next.
      Parameters:
      s - the string to be split
      width - int
      Returns:
      string fragments
    • whitespace

      public static String whitespace(int n)
      Returns a string with the specified number of whitespace.
      Parameters:
      n - the number of whitespace characters
      Returns:
      a string with the specified number of blanks
    • pad

      public static String pad(String o, int len)
      Pad a string to a given length by adding whitespace to the right.
      Parameters:
      o - original string
      len - destination length
      Returns:
      padded string of at least length len (and o otherwise)
    • padRightAligned

      public static String padRightAligned(String o, int len)
      Pad a string to a given length by adding whitespace to the left.
      Parameters:
      o - original string
      len - destination length
      Returns:
      padded string of at least length len (and o otherwise)
    • getConsoleWidth

      public static int getConsoleWidth()
      Get the width of the terminal window (on Unix xterms), with a default of 78 characters.
      Returns:
      Terminal width
    • formatTimeDelta

      public static String formatTimeDelta(long time, CharSequence sep)
      Formats a time delta in human readable format.
      Parameters:
      time - time delta in ms
      Returns:
      Formatted string
    • format

      public static String format(String[] d, String sep)
      Formats the string array d with the specified separator.
      Parameters:
      d - the string array to be formatted
      sep - the separator between the single values of the double array, e.g. ','
      Returns:
      a String representing the string array d