public interface Formattable
The Formattable
interface is used to provide customised
formatting to arbitrary objects via the Formatter
. The
formatTo(java.util.Formatter, int, int, int)
method is called for Formattable
objects used with the 's' conversion operator, allowing the object
to provide its own formatting of its internal data.
Thread safety is left up to the implementing class. Thus,
Formattable
objects are not guaranteed to be thread-safe,
and users should make their own provisions for multiple thread access.
Modifier and Type | Method and Description |
---|---|
void |
formatTo(Formatter formatter,
int flags,
int width,
int precision)
Formats the object using the supplied formatter to the specification
provided by the given flags, width and precision.
|
void formatTo(Formatter formatter, int flags, int width, int precision)
formatter
- the formatter to use for formatting the object.
The formatter gives access to the output stream
and locale via Formatter.out()
and
Formatter.locale()
respectively.flags
- a bit mask constructed from the flags in the
FormattableFlags
class. When no flags
are set, the implementing class should use its
defaults.width
- the minimum number of characters to include.
A value of -1 indicates no minimum. The remaining
space is padded with ' ' either on the left
(the default) or right (if left justification is
specified by the flags).precision
- the maximum number of characters to include.
A value of -1 indicates no maximum. This value
is applied prior to the minimum (the width). Thus,
a value may meet the minimum width initially, but
not when the width value is applied, due to
characters being removed by the precision value.IllegalFormatException
- if there is a problem with
the syntax of the format
specification or a mismatch
between it and the arguments.