Package jcckit.util

Class Format

java.lang.Object
jcckit.util.Format
All Implemented Interfaces:
TicLabelFormat

public class Format extends Object implements TicLabelFormat
A helper class for formatting numbers according to a printf-like format string. Each instance of this class is initialized by a format string for a single number.
  • Constructor Details

    • Format

      public Format(String formatString)
      Creates an instance for the specified format string. The format string is an alternation of some static texts and format elements. A format element has to start with `%` and it must end with one of the following format descriptors:
      d decimal integer
      o octal integer
      x hex integer
      f floating point number with a fixed decimal point
      e, E floating point number in logarithmic format
      g, G floating point number rendered either in fixed-decimal format of logarithmic format depending on the size of the mantissa.
      The characters between `%` and the decriptor are optional. They can be grouped into
      • modifier
        it is
        • '-' if the formated result should be flushed left
        • '+' if the sign should be always appear
        • '0' if the leading space should be filled with zeros
      • width
        a decimal number given the minimum number of characters of the result
      • precision
      A plain `%` is coded as `%%`.
      Parameters:
      formatString - The format string.
      Throws:
      IllegalArgumentException - if invalid format string.
  • Method Details

    • create

      public static Format create(ConfigParameters config, String key)
      Creates a new instance based of specified key-value pair of the specified configuration parameters.
      Parameters:
      config - Config parameters.
      key - The key of the key-value pair in config containing the format string.
      Returns:
      null if undefined key-value pair or format string is an empty string.
      Throws:
      FactoryException - if the format string is invalid.
    • form

      public String form(long number)
      Format a number. If there are no format elements the numbers will be ignored. If there are more than one format elements the additional format elements will be ignored and only the static parts are taken.
      Parameters:
      number - Number to be formated.
      Returns:
      Formated number.
    • form

      public String form(double number)
      Format a number. If there are no format elements the numbers will be ignored. If there are more than one format elements the additional format elements will be ignored and only the static parts are taken.
      Specified by:
      form in interface TicLabelFormat
      Parameters:
      number - Number to be formated.
      Returns:
      Formated number.
    • form

      public String form(double[] numbers)
      Format an array of double numbers. If there are less format elements than numbers the additional numbers will be ignored. If there are less numbers than format elements the additional format elements will be ignored and only the static parts are taken.
      Parameters:
      numbers - Numbers to be formated.
      Returns:
      Formated numbers.