Package org.apache.commons.text
Class FormattableUtils
java.lang.Object
org.apache.commons.text.FormattableUtils
Provides utilities for working with the
Formattable interface.
The Formattable interface provides basic control over formatting
when using a Formatter. It is primarily concerned with numeric precision
and padding, and is not designed to allow generalized alternate formats.
- Since:
- 1.0
-
Constructor Summary
ConstructorsConstructorDescriptionFormattableUtilsinstances should NOT be constructed in standard programming. -
Method Summary
Modifier and TypeMethodDescriptionstatic Formatterappend(CharSequence seq, Formatter formatter, int flags, int width, int precision) Handles the commonFormattableoperations of truncate-pad-append, with no ellipsis on precision overflow, and padding width underflow with spaces.static Formatterappend(CharSequence seq, Formatter formatter, int flags, int width, int precision, char padChar) Handles the commonFormattableoperations of truncate-pad-append, with no ellipsis on precision overflow.static Formatterappend(CharSequence seq, Formatter formatter, int flags, int width, int precision, char padChar, CharSequence truncateEllipsis) Handles the commonFormattableoperations of truncate-pad-append.static Formatterappend(CharSequence seq, Formatter formatter, int flags, int width, int precision, CharSequence ellipsis) Handles the commonFormattableoperations of truncate-pad-append, padding width underflow with spaces.static StringtoString(Formattable formattable) Gets the default formatted representation of the specifiedFormattable.
-
Constructor Details
-
FormattableUtils
public FormattableUtils()FormattableUtilsinstances should NOT be constructed in standard programming. Instead, the methods of the class should be invoked statically.This constructor is public to permit tools that require a JavaBean instance to operate.
-
-
Method Details
-
append
public static Formatter append(CharSequence seq, Formatter formatter, int flags, int width, int precision) Handles the commonFormattableoperations of truncate-pad-append, with no ellipsis on precision overflow, and padding width underflow with spaces.- Parameters:
seq- the string to handle, not nullformatter- the destination formatter, not nullflags- the flags for formatting, seeFormattablewidth- the width of the output, seeFormattableprecision- the precision of the output, seeFormattable- Returns:
- The
formatterinstance, not null
-
append
public static Formatter append(CharSequence seq, Formatter formatter, int flags, int width, int precision, char padChar) Handles the commonFormattableoperations of truncate-pad-append, with no ellipsis on precision overflow.- Parameters:
seq- the string to handle, not nullformatter- the destination formatter, not nullflags- the flags for formatting, seeFormattablewidth- the width of the output, seeFormattableprecision- the precision of the output, seeFormattablepadChar- the pad character to use- Returns:
- The
formatterinstance, not null
-
append
public static Formatter append(CharSequence seq, Formatter formatter, int flags, int width, int precision, char padChar, CharSequence truncateEllipsis) Handles the commonFormattableoperations of truncate-pad-append.- Parameters:
seq- the string to handle, not nullformatter- the destination formatter, not nullflags- the flags for formatting, seeFormattablewidth- the width of the output, seeFormattableprecision- the precision of the output, seeFormattablepadChar- the pad character to usetruncateEllipsis- the ellipsis to use when precision dictates truncation, null or empty causes a hard truncation- Returns:
- The
formatterinstance, not null - Throws:
IllegalArgumentException- ifellipsis.length() > precision, given thatellipsisis not null andprecision >= 0
-
append
public static Formatter append(CharSequence seq, Formatter formatter, int flags, int width, int precision, CharSequence ellipsis) Handles the commonFormattableoperations of truncate-pad-append, padding width underflow with spaces.- Parameters:
seq- the string to handle, not nullformatter- the destination formatter, not nullflags- the flags for formatting, seeFormattablewidth- the width of the output, seeFormattableprecision- the precision of the output, seeFormattableellipsis- the ellipsis to use when precision dictates truncation, null or empty causes a hard truncation- Returns:
- The
formatterinstance, not null - Throws:
IllegalArgumentException- ifellipsis.length() > precision, given thatellipsisis not null andprecision >= 0
-
toString
Gets the default formatted representation of the specifiedFormattable.- Parameters:
formattable- the instance to convert to a string, not null- Returns:
- The resulting string, not null
-