Class FastMessageFormat
- java.lang.Object
-
- org.pentaho.reporting.libraries.formatting.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 Summary
Constructors Constructor Description FastMessageFormat(String pattern)
Creates a new default message format object for the given pattern using the default locale as locale.FastMessageFormat(String pattern, Locale locale)
Creates a new default message format object for the given pattern and locale.FastMessageFormat(String pattern, Locale locale, TimeZone timeZone)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Object
clone()
Clones the formatter.String
format(Object parameters)
Formats the given object in a formatter-specific way.Locale
getLocale()
Returns the current locale of the formatter.String
getNullString()
Returns the null-string that is used whenever a parameter object is null.String
getPattern()
Returns the currently active pattern.protected FastFormat
getSubFormat(int index)
Returns the subformat at the given index.int
getSubFormatCount()
Returns the number of subformats in the message-formatter.protected FastFormat[]
getSubFormats()
Returns the subformats of this message-format.TimeZone
getTimeZone()
Returns the current time-zone for date formats.void
setNullString(String nullString)
Defines the null-string that is used whenever a parameter object is null.protected void
setSubFormats(FastFormat[] subFormats)
Redefines the subformats of this message-format.
-
-
-
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.
-
-
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 interfaceFastFormat
- 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 interfaceFastFormat
- Parameters:
parameters
- the parameters for the formatting.- Returns:
- the formatted string.
-
clone
public Object clone() throws CloneNotSupportedException
Clones the formatter.- Specified by:
clone
in interfaceFastFormat
- Overrides:
clone
in classObject
- Returns:
- the clone.
- Throws:
CloneNotSupportedException
- if cloning failed.
-
-