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 `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 generalised alternate formats.

  Since:
    1.0

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `FormattableUtils()` `FormattableUtils` instances should NOT be constructed in standard programming.

  - ### Method Summary

    All Methods Static Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `static Formatter` | `append(CharSequence seq, Formatter formatter, int flags, int width, int precision)` Handles the common `Formattable` operations of truncate-pad-append, with no ellipsis on precision overflow, and padding width underflow with spaces.
    `static Formatter` | `append(CharSequence seq, Formatter formatter, int flags, int width, int precision, char padChar)` Handles the common `Formattable` operations of truncate-pad-append, with no ellipsis on precision overflow.
    `static Formatter` | `append(CharSequence seq, Formatter formatter, int flags, int width, int precision, char padChar, CharSequence ellipsis)` Handles the common `Formattable` operations of truncate-pad-append.
    `static Formatter` | `append(CharSequence seq, Formatter formatter, int flags, int width, int precision, CharSequence ellipsis)` Handles the common `Formattable` operations of truncate-pad-append, padding width underflow with spaces.
    `static String` | `toString(Formattable formattable)` Get the default formatted representation of the specified `Formattable`.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### FormattableUtils

          public FormattableUtils()

      `FormattableUtils` instances 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 Detail

    - #### toString

          public static String toString(Formattable formattable)

      Get the default formatted representation of the specified `Formattable`.
      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 common `Formattable` operations of truncate-pad-append, with no ellipsis on precision overflow, and padding width underflow with spaces.
      Parameters:
        `seq` - the string to handle, not null
        `formatter` - the destination formatter, not null
        `flags` - the flags for formatting, see `Formattable`
        `width` - the width of the output, see `Formattable`
        `precision` - the precision of the output, see `Formattable`
      Returns:
        the `formatter` instance, not null

    - #### append

          public static Formatter append(CharSequence seq,
                                         Formatter formatter,
                                         int flags,
                                         int width,
                                         int precision,
                                         char padChar)

      Handles the common `Formattable` operations of truncate-pad-append, with no ellipsis on precision overflow.
      Parameters:
        `seq` - the string to handle, not null
        `formatter` - the destination formatter, not null
        `flags` - the flags for formatting, see `Formattable`
        `width` - the width of the output, see `Formattable`
        `precision` - the precision of the output, see `Formattable`
        `padChar` - the pad character to use
      Returns:
        the `formatter` instance, not null

    - #### append

          public static Formatter append(CharSequence seq,
                                         Formatter formatter,
                                         int flags,
                                         int width,
                                         int precision,
                                         CharSequence ellipsis)

      Handles the common `Formattable` operations of truncate-pad-append, padding width underflow with spaces.
      Parameters:
        `seq` - the string to handle, not null
        `formatter` - the destination formatter, not null
        `flags` - the flags for formatting, see `Formattable`
        `width` - the width of the output, see `Formattable`
        `precision` - the precision of the output, see `Formattable`
        `ellipsis` - the ellipsis to use when precision dictates truncation, null or empty causes a hard truncation
      Returns:
        the `formatter` instance, not null

    - #### append

          public static Formatter append(CharSequence seq,
                                         Formatter formatter,
                                         int flags,
                                         int width,
                                         int precision,
                                         char padChar,
                                         CharSequence ellipsis)

      Handles the common `Formattable` operations of truncate-pad-append.
      Parameters:
        `seq` - the string to handle, not null
        `formatter` - the destination formatter, not null
        `flags` - the flags for formatting, see `Formattable`
        `width` - the width of the output, see `Formattable`
        `precision` - the precision of the output, see `Formattable`
        `padChar` - the pad character to use
        `ellipsis` - the ellipsis to use when precision dictates truncation, null or empty causes a hard truncation
      Returns:
        the `formatter` instance, not null

Copyright © 2014–2017 The Apache Software Foundation. All rights reserved.