public class Format extends Object
Format
formats numbers, strings and dates according to the
same specification as Visual Basic's
format()
function. This function is described in more detail
here. We
have made the following enhancements to this specification:One format object can be used to format multiple values, thereby amortizing the time required to parse the format string. Example:
double[] values;
Format format = new Format("##,##0.###;(##,##0.###);;Nil");
for (int i = 0; i < values.length; i++) {
System.out.println("Value #" + i + " is " + format.format(values[i]));
}
Still to be implemented:
Modifier and Type | Class and Description |
---|---|
static class |
Format.FormatLocale
A FormatLocale contains all information necessary to format objects
based upon the locale of the end-user.
|
Modifier and Type | Field and Description |
---|---|
static int |
CacheLimit
Maximum number of entries in the format cache used by
get(String, java.util.Locale) . |
Constructor and Description |
---|
Format(String formatString,
Format.FormatLocale locale)
Constructs a
Format in a specific locale. |
Format(String formatString,
Locale locale)
Constructs a
Format in a specific locale. |
Modifier and Type | Method and Description |
---|---|
static Format.FormatLocale |
createLocale(char thousandSeparator,
char decimalPlaceholder,
String dateSeparator,
String timeSeparator,
String currencySymbol,
String currencyFormat,
String[] daysOfWeekShort,
String[] daysOfWeekLong,
String[] monthsShort,
String[] monthsLong,
Locale locale)
Create a
Format.FormatLocale object characterized by the given
properties. |
static Format.FormatLocale |
createLocale(Locale locale) |
String |
format(Object o) |
static Format |
get(String formatString,
Locale locale)
Constructs a
Format in a specific locale, or retrieves
one from the cache if one already exists. |
static Format.FormatLocale |
getBestFormatLocale(Locale locale)
Returns the best
Format.FormatLocale for a given Locale . |
static Format.FormatLocale |
getFormatLocale(Locale locale)
Returns the
Format.FormatLocale which precisely matches Locale ,
if any, or null if there is none. |
String |
getFormatString() |
static String |
getFormatToken(int code)
Returns the format token as a string representation
which corresponds to a given token code.
|
static List<mondrian.util.Format.Token> |
getTokenList() |
static Format.FormatLocale |
registerFormatLocale(Format.FormatLocale formatLocale,
Locale locale)
Registers a
Format.FormatLocale to a given Locale . |
public static final int CacheLimit
get(String, java.util.Locale)
.public Format(String formatString, Locale locale)
Format
in a specific locale.formatString
- the format string; see
this
description for more detailslocale
- The localepublic Format(String formatString, Format.FormatLocale locale)
Format
in a specific locale.formatString
- the format string; see
this
description for more detailslocale
- The localeFormat.FormatLocale
,
createLocale(char, char, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String[], java.lang.String[], java.lang.String[], java.lang.String[], java.util.Locale)
public static List<mondrian.util.Format.Token> getTokenList()
public static String getFormatToken(int code)
code
- The code of the token to obtain.public static Format get(String formatString, Locale locale)
Format
in a specific locale, or retrieves
one from the cache if one already exists.
If the number of entries in the cache exceeds CacheLimit
,
replaces the eldest entry in the cache.
formatString
- the format string; see
this
description for more detailspublic static Format.FormatLocale createLocale(char thousandSeparator, char decimalPlaceholder, String dateSeparator, String timeSeparator, String currencySymbol, String currencyFormat, String[] daysOfWeekShort, String[] daysOfWeekLong, String[] monthsShort, String[] monthsLong, Locale locale)
Format.FormatLocale
object characterized by the given
properties.thousandSeparator
- the character used to separate thousands in
numbers, or ',' by default. For example, 12345 is '12,345 in English,
'12.345 in French.decimalPlaceholder
- the character placed between the integer and
the fractional part of decimal numbers, or '.' by default. For
example, 12.34 is '12.34' in English, '12,34' in French.dateSeparator
- the character placed between the year, month and
day of a date such as '12/07/2001', or '/' by default.timeSeparator
- the character placed between the hour, minute and
second value of a time such as '1:23:45 AM', or ':' by default.daysOfWeekShort
- Short forms of the days of the week.
The array is 1-based, because position
Calendar.SUNDAY
(= 1) must hold Sunday, etc.
The array must have 8 elements.
For example {"", "Sun", "Mon", ..., "Sat"}.daysOfWeekLong
- Long forms of the days of the week.
The array is 1-based, because position
Calendar.SUNDAY
must hold Sunday, etc.
The array must have 8 elements.
For example {"", "Sunday", ..., "Saturday"}.monthsShort
- Short forms of the months of the year.
The array is 0-based, because position
Calendar.JANUARY
(= 0) holds January, etc.
For example {"Jan", ..., "Dec", ""}.monthsLong
- Long forms of the months of the year.
The array is 0-based, because position
Calendar.JANUARY
(= 0) holds January, etc.
For example {"January", ..., "December", ""}.locale
- if this is not null, register that the constructed
FormatLocale
is the default for locale
public static Format.FormatLocale createLocale(Locale locale)
public static Format.FormatLocale getFormatLocale(Locale locale)
Format.FormatLocale
which precisely matches Locale
,
if any, or null if there is none.public static Format.FormatLocale getBestFormatLocale(Locale locale)
Format.FormatLocale
for a given Locale
.
Never returns null, even if locale
is null.public static Format.FormatLocale registerFormatLocale(Format.FormatLocale formatLocale, Locale locale)
Format.FormatLocale
to a given Locale
. Returns the
previous mapping.public String getFormatString()
Copyright © 2018 Hitachi Vantara. All rights reserved.