Class FormatUtil


  • @AnnotatedFor("nullness")
    public class FormatUtil
    extends java.lang.Object
    This class provides a collection of utilities to ease working with format strings.
    • Constructor Detail

      • FormatUtil

        public FormatUtil()
    • Method Detail

      • asFormat

        @ReturnsFormat
        public static java.lang.String asFormat​(java.lang.String format,
                                                ConversionCategory... cc)
                                         throws java.util.IllegalFormatException
        Returns the first argument if the format string is satisfiable, and if the format's parameters match the passed ConversionCategorys. Otherwise throws an exception.
        Parameters:
        format - a format string
        cc - an array of conversion categories
        Returns:
        the format argument
        Throws:
        java.util.IllegalFormatException - if the format string is incompatible with the conversion categories
      • tryFormatSatisfiability

        public static void tryFormatSatisfiability​(java.lang.String format)
                                            throws java.util.IllegalFormatException
        Throws an exception if the format is not syntactically valid.
        Parameters:
        format - a format string
        Throws:
        java.util.IllegalFormatException - if the format string is invalid
      • formatParameterCategories

        public static ConversionCategory[] formatParameterCategories​(java.lang.String format)
                                                              throws java.util.IllegalFormatException
        Returns a ConversionCategory for every conversion found in the format string.

        Throws an exception if the format is not syntactically valid.

        Throws:
        java.util.IllegalFormatException
      • conversionCharFromFormat

        @Deprecated
        public static char conversionCharFromFormat​(java.lang.String formatSpecifier)
        Deprecated.
        This method is public only for testing. Use private method #conversionCharFromFormat(Matcher).
        Return the conversion character that is in the given format specifier.
        Parameters:
        formatSpecifier - a format specifier
        Returns:
        the conversion character that is in the given format specifier