jcckit.util
Class Format

java.lang.Object
  extended byjcckit.util.Format
All Implemented Interfaces:
TicLabelFormat

public class Format
extends java.lang.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.

Author:
Franz-Josef Elmer

Constructor Summary
Format(java.lang.String formatString)
          Creates an instance for the specified format string.
 
Method Summary
static Format create(ConfigParameters config, java.lang.String key)
          Creates a new instance based of specified key-value pair of the specified configuration parameters.
 java.lang.String form(double number)
          Format a number.
 java.lang.String form(double[] numbers)
          Format an array of double numbers.
 java.lang.String form(long number)
          Format a number.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Format

public Format(java.lang.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 A plain '%' is coded as '%%'.

Parameters:
formatString - The format string.
Throws:
java.lang.IllegalArgumentException - if invalid format string.
Method Detail

create

public static Format create(ConfigParameters config,
                            java.lang.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 java.lang.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 java.lang.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 java.lang.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.