Class FastMessageFormat

  • All Implemented Interfaces:
    Serializable, Cloneable, FastFormat

    public class FastMessageFormat
    extends Object
    implements FastFormat
    A wrapper around the java.text.MessageFormat class. This wrapper limits the possible interactions with the wrapped format class and therefore eliminates the need to clone the choice format whenever the wrapper is cloned.

    The pattern accepted by the this class is the same as the message-format pattern, with the exception that this class allows to escape the special characters using the backslash-character. Unlike the original MessageFormat class, this class allows to set a null-string for parameters that are null.

    Author:
    Thomas Morgner
    See Also:
    Serialized Form
    • Constructor Detail

      • FastMessageFormat

        public FastMessageFormat​(String pattern)
        Creates a new default message format object for the given pattern using the default locale as locale.
        Parameters:
        pattern - the pattern.
      • FastMessageFormat

        public FastMessageFormat​(String pattern,
                                 Locale locale)
        Creates a new default message format object for the given pattern and locale.
        Parameters:
        pattern - the pattern.
        locale - the locale.
      • FastMessageFormat

        public FastMessageFormat​(String pattern,
                                 Locale locale,
                                 TimeZone timeZone)
    • Method Detail

      • getSubFormatCount

        public int getSubFormatCount()
        Returns the number of subformats in the message-formatter.
        Returns:
        the number of subformats.
      • getSubFormat

        protected FastFormat getSubFormat​(int index)
        Returns the subformat at the given index.
        Parameters:
        index - the index.
        Returns:
        a clone of the fast-format or null, if there is no formatter at that position.
      • getLocale

        public Locale getLocale()
        Returns the current locale of the formatter.
        Specified by:
        getLocale in interface FastFormat
        Returns:
        the current locale, never null.
      • getTimeZone

        public TimeZone getTimeZone()
        Returns the current time-zone for date formats.
        Returns:
        the current time zone, never null.
      • getPattern

        public String getPattern()
        Returns the currently active pattern.
        Returns:
        the locale.
      • getSubFormats

        protected FastFormat[] getSubFormats()
        Returns the subformats of this message-format.
        Returns:
        the subformats as deeply cloned array.
      • setSubFormats

        protected void setSubFormats​(FastFormat[] subFormats)
        Redefines the subformats of this message-format.
        Parameters:
        subFormats - the subformats.
      • getNullString

        public String getNullString()
        Returns the null-string that is used whenever a parameter object is null.
        Returns:
        the nullstring.
      • setNullString

        public void setNullString​(String nullString)
        Defines the null-string that is used whenever a parameter object is null.
        Parameters:
        nullString - the nullstring, never null in itself.
      • format

        public String format​(Object parameters)
        Formats the given object in a formatter-specific way.
        Specified by:
        format in interface FastFormat
        Parameters:
        parameters - the parameters for the formatting.
        Returns:
        the formatted string.