Package org.apache.commons.text
Class FormattableUtils
- java.lang.Object
-
- org.apache.commons.text.FormattableUtils
-
public class FormattableUtils extends Object
Provides utilities for working with the
Formattableinterface.The
Formattableinterface provides basic control over formatting when using aFormatter. It is primarily concerned with numeric precision and padding, and is not designed to allow generalised alternate formats.- Since:
- 1.0
-
-
Constructor Summary
Constructors Constructor Description FormattableUtils()FormattableUtilsinstances should NOT be constructed in standard programming.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static 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 ellipsis)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)Get the default formatted representation of the specifiedFormattable.
-
-
-
Method Detail
-
toString
public static String toString(Formattable formattable)
Get the default formatted representation of the specifiedFormattable.- Parameters:
formattable- the instance to convert to a string, not null- Returns:
- the resulting string, not null
-
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, 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
-
append
public static Formatter append(CharSequence seq, Formatter formatter, int flags, int width, int precision, char padChar, CharSequence ellipsis)
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 useellipsis- the ellipsis to use when precision dictates truncation, null or empty causes a hard truncation- Returns:
- the
formatterinstance, not null
-
-