|
BenQ Mobile |
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjavax.microedition.global.Formatter
Creates locale-specific renditions of data items. The following data items are handled:
If the selected locale is null or the empty string, formatting is locale-neutral (see below). If the selected locale is non-null and non-empty, but the Formatter implementation does not support it, the constructors throw an UnsupportedLocaleException.
If the selected locale is supported, the formatting is performed according to the rules of the locale. These rules are implementation-specific and are not exposed to application programmers.
To find out which locales are supported in the implementation, call the getSupportedLocales() method.
Mixed combinations (i.e. short date with long time and vice versa) are not supported. In styles with both date and time component are present their mutual depends on the locale.
Locale neutral formatting is provided because the MIDP specification allows the microedition.locale system property to be null. In such cases constructing a formatter will use the locale-neutral values to avoid an exceptional condition. The application can also explicitly request locale-neutral behaviour by passing null as the locale.
Copyright: Copyright (c) Siemens AG 2004 * ALL RIGHTS RESERVED
Field Summary | |
static int |
DATE_LONG
Constant for the long date style. |
static int |
DATE_SHORT
Constant for the short date style. |
static int |
DATETIME_LONG
Constant for the short date and time style. |
static int |
DATETIME_SHORT
Constant for the short date style. |
static int |
TIME_LONG
Constant for the long time style. |
static int |
TIME_SHORT
Constant for the short time style. |
Constructor Summary | |
Formatter()
Constructs a formatter based on the current locale, which is the value of the microedition. |
|
Formatter(java.lang.String locale)
Constructs a formatter for the specified locale. |
Method Summary | |
java.lang.String |
formatCurrency(double number)
Formats a currency amount using locale-specific rules. |
java.lang.String |
formatCurrency(double number,
java.lang.String currencyCode)
Formats a currency amount using the locale-specific rules but using the symbol of the specified currency. |
java.lang.String |
formatDateTime(java.util.Calendar dateTime,
int style)
Formats a date/time instance using locale-specific rules. |
static java.lang.String |
formatMessage(java.lang.String template,
java.lang.String[] params)
Formats a message with a variable number of ordered parameters. |
java.lang.String |
formatNumber(double number)
Formats a decimal number using locale-specific rules. |
java.lang.String |
formatNumber(double number,
int decimals)
Formats a decimal number using locale-specific rules, with the specified number of decimals. |
java.lang.String |
formatNumber(long number)
Formats an integer using locale-specific rules. |
java.lang.String |
formatPercentage(float value,
int decimals)
Formats a percentage with the specified number of decimals using locale-specific rules. |
java.lang.String |
formatPercentage(long value)
Formats a percentage using locale-specific rules. |
java.lang.String |
getLocale()
Gets the locale of this formatter. |
static java.lang.String[] |
getSupportedLocales()
Gets the list of the locales supported by the formatter, as an array of valid microedition.locale values. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final int DATE_SHORT
public static final int DATE_LONG
public static final int TIME_SHORT
public static final int TIME_LONG
public static final int DATETIME_SHORT
public static final int DATETIME_LONG
Constructor Detail |
public Formatter() throws UnsupportedLocaleException
If the system property value is null, locale neutral formatting rules are used. If the implementation does not support the current locale, an UnsupportedLocaleException is thrown.
UnsupportedLocaleException
- if the current
locale is not supported by the implementation
.
public Formatter(java.lang.String locale) throws UnsupportedLocaleException
If the specified locale is null or the empty string, locale neutral formatting rules are used. If the implementation does not support the specified locale, an UnsupportedLocaleException is thrown.
locale
- the locale identifier
UnsupportedLocaleException
- if the specified
locale is not supported by the implementation
locale is not valid according to the MIDP 2.0 specificationMethod Detail |
public java.lang.String getLocale()
public java.lang.String formatDateTime(java.util.Calendar dateTime, int style) throws java.lang.IllegalArgumentException
dateTime
- the date and time to format the formattingstyle
- to use
java.lang.IllegalArgumentException
- if the style constant
is not one of those defined in this classpublic static java.lang.String formatMessage(java.lang.String template, java.lang.String[] params) throws java.lang.IllegalArgumentException
The parameters are passed as an array of strings. This method does not actually format dates, times, and other data; the items must be already formatted and the strings placed in the parameter array. This method then performs a simple string substitution.
If you need to include the { character in the template, it MUST be escaped using {{, so that it is not mistaken for the initial delimiter of a placeholder.
The length of the params array determines the upper bound of the {nn} parameters in the template. If the template contains references to parameter numbers higher than params.length - 1, this method throws an IllegalArgumentException
template
- - the string templateparams
- - the parameters to insert
java.lang.IllegalArgumentException
- -
if the template refers to parameter numbers
larger than params.length - 1
if the template or the parameter array is nullpublic java.lang.String formatCurrency(double number)
number
- - the currency amount to format
public java.lang.String formatCurrency(double number, java.lang.String currencyCode) throws java.lang.IllegalArgumentException
The result MAY include a locale-specific decimal separator and grouping separators. The number of decimals is also locale-specific. This method MUST NOT perform any currency conversions based on exchange rates.
number
- - the currency amount to formatcurrencyCode
- - the ISO 4217 currency code to use
java.lang.IllegalArgumentException
- -
if the currencyCode is not a valid ISO 4217 code
if currencyCode is nullpublic java.lang.String formatNumber(long number)
number
- - the number to format
public java.lang.String formatNumber(double number)
number
- - the number to format.
public java.lang.String formatNumber(double number, int decimals) throws java.lang.IllegalArgumentException
The number of decimals MUST be between 1 and 15. The formatted result MUST have exactly the specified number of decimals, even if some of the trailing digits are zeroes
number
- - the number to format.decimals
- - the number of decimals to use.
java.lang.IllegalArgumentException
- -
if the number of decimals is not between 1 and 15, inclusive.public java.lang.String formatPercentage(long value)
value
- long the value to be formatted
public java.lang.String formatPercentage(float value, int decimals) throws java.lang.IllegalArgumentException
value
- the percentage to format, expressed as a
positive or negative numberdecimals
- the number of decimals to use (1 <= decimals <= 15)
java.lang.IllegalArgumentException
public static java.lang.String[] getSupportedLocales()
If no locales are supported, the list is empty, but never null. As the value null is not technically a valid locale, but a special value to trigger locale-neutral formatting, it must not appear in the array.
|
BenQ Mobile |
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
Copyright © 2006 BenQ Mobile GmbH & Co. OHG or respective copyright owner. All Rights Reserved. BenQ Corp. is a trademark licensee of Siemens AG. |
For further information about Mobility Toolkit (MTK) visit our Developer Portal. |