Package jcckit.util
Class Format
java.lang.Object
jcckit.util.Format
- All Implemented Interfaces:
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 Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic Format
create
(ConfigParameters config, String key) Creates a new instance based of specified key-value pair of the specified configuration parameters.form
(double number) Format a number.form
(double[] numbers) Format an array of double numbers.form
(long number) Format a number.
-
Constructor Details
-
Format
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. - 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
- Parameters:
formatString
- The format string.- Throws:
IllegalArgumentException
- if invalid format string.
- modifier
-
-
Method Details
-
create
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
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
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 interfaceTicLabelFormat
- Parameters:
number
- Number to be formated.- Returns:
- Formated number.
-
form
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.
-