Important Note
New users are strongly encouraged to see if
NumberFormatter fits their use case. Although not deprecated, this
class, MeasureFormat, is provided for backwards compatibility only, and has
much more limited capabilities.
To format a Measure object, first create a formatter object using a MeasureFormat factory method. Then use that object's format or formatMeasures methods. Here is sample code:
MeasureFormat fmtFr = MeasureFormat.getInstance(ULocale.FRENCH, FormatWidth.SHORT);
Measure measure = new Measure(23, MeasureUnit.CELSIUS);
// Output: 23 °C
System.out.println(fmtFr.format(measure));
Measure measureF = new Measure(70, MeasureUnit.FAHRENHEIT);
// Output: 70 °F
System.out.println(fmtFr.format(measureF));
MeasureFormat fmtFrFull = MeasureFormat.getInstance(ULocale.FRENCH, FormatWidth.WIDE);
// Output: 70 pieds et 5,3 pouces
System.out.println(fmtFrFull.formatMeasures(new Measure(70, MeasureUnit.FOOT),
new Measure(5.3, MeasureUnit.INCH)));
// Output: 1 pied et 1 pouce
System.out.println(
fmtFrFull.formatMeasures(new Measure(1, MeasureUnit.FOOT), new Measure(1, MeasureUnit.INCH)));
MeasureFormat fmtFrNarrow = MeasureFormat.getInstance(ULocale.FRENCH, FormatWidth.NARROW);
// Output: 1′ 1″
System.out.println(fmtFrNarrow.formatMeasures(new Measure(1, MeasureUnit.FOOT),
new Measure(1, MeasureUnit.INCH)));
MeasureFormat fmtEn = MeasureFormat.getInstance(ULocale.ENGLISH, FormatWidth.WIDE);
// Output: 1 inch, 2 feet
fmtEn.formatMeasures(new Measure(1, MeasureUnit.INCH), new Measure(2, MeasureUnit.FOOT));
This class does not do conversions from one unit to another. It simply formats whatever units it is given
This class is immutable and thread-safe so long as its deprecated subclass, TimeUnitFormat, is never used. TimeUnitFormat is not thread-safe, and is mutable. Although this class has existing subclasses, this class does not support new sub-classes.
com.ibm.icu.text.UFormat
| Modifier and Type | Class and Description |
|---|---|
| public static enum | MeasureFormat.FormatWidth
Formatting width enum. |
| pack-priv static class | |
| pack-priv static class | |
| pack-priv static class |
| Modifier and Type | Field and Description |
|---|---|
| private static final int | |
| private transient MeasureFormat. | |
| private transient MeasureFormat. | |
| private transient MeasureFormat. | |
| private final transient MeasureFormat. | |
| private static final Map | |
| private static final Map | |
| private static final SimpleCache | |
| private static final int | |
| pack-priv static final int | |
| pack-priv static final int | |
| pack-priv static final int | |
| private final transient NumberFormat | |
| private final transient LocalizedNumberFormatter | |
| private final transient MeasureFormat. | |
| private final transient PluralRules | |
| pack-priv static final long | |
| private static final int |
| Access | Constructor and Description |
|---|---|
| pack-priv | |
| private | MeasureFormat(ULocale locale, MeasureFormat.
|
| pack-priv | MeasureFormat(ULocale locale, MeasureFormat.
|
| Modifier and Type | Method and Description |
|---|---|
| pack-priv synchronized void | |
| public final boolean | equals(Object
the reference object with which to compare. other)Overrides java. |
| public StringBuffer | format(Object
must be a Collection<? extends Measure>, Measure[], or Measure object. obj, StringBuffer Formatted string appended here. toAppendTo, FieldPosition Identifies a field in the formatted text. fpos)Implements abstract java. |
| private FormattedStringBuilder | |
| private FormattedStringBuilder | |
| public StringBuilder | Returns: appendTo.the measure object. In above example, 3.5 meters. measure, MeasureUnit the per unit. In above example, it is MeasureUnit.SECOND perUnit, StringBuilder formatted string appended here. appendTo, FieldPosition The field position. pos)Formats a single measure per unit. |
| public final String | Returns: the formatted string.a sequence of one or more measures. measures)Format a sequence of measures. |
| public StringBuilder | Returns: appendTo.the formatted string appended here. appendTo, FieldPosition Identifies a field in the formatted text. fpos, Measure... the measures to format. measures)Formats a sequence of measures. |
| private void | |
| private void | formatMeasuresSlowTrack(ListFormatter listFormatter, Appendable appendTo, FieldPosition fieldPosition, Measure... measures)
|
| private void | |
| private static MeasureFormat. | |
| public static MeasureFormat | Returns: a formatter objectdesired locale locale)Return a formatter for CurrencyAmount objects in the given locale. |
| public static MeasureFormat | Returns: a formatter objectdesired locale)java.Return a formatter for CurrencyAmount objects in the given |
| public static MeasureFormat | Returns: a formatter objectReturn a formatter for CurrencyAmount objects in the default |
| public static MeasureFormat | Returns: The new MeasureFormat object.the locale. locale, MeasureFormat.hints how long formatted strings should be. formatWidthCreate a format from the locale, formatWidth, and format. |
| public static MeasureFormat | Returns: The new MeasureFormat object.the locale, MeasureFormat.java..hints how long formatted strings should be. formatWidthCreate a format from the |
| public static MeasureFormat | Returns: The new MeasureFormat object.the locale. locale, MeasureFormat.hints how long formatted strings should be. formatWidth,This is defensively copied. format)Create a format from the locale, formatWidth, and format. |
| public static MeasureFormat | Returns: The new MeasureFormat object.the locale, MeasureFormat.java..hints how long formatted strings should be. formatWidth,This is defensively copied. format)Create a format from the |
| public final ULocale | |
| public NumberFormat | |
| pack-priv NumberFormat | |
| pack-priv LocalizedNumberFormatter | |
| public static String | Returns: range formatter, such as "{0}–{1}"locale to get the format for forLocale, MeasureFormat.the format width width
Deprecated
This API is ICU internal only.
Return a formatter (compiled SimpleFormatter pattern) for a range, such as "{0}–{1}".
|
| public String | Returns: The display name in the locale and width specified inMeasureFormat#getInstance,
or null if there is no display name available for the specified unit.The unit for which to get a display name. unit)Gets the display name of the specified |
| private synchronized LocalizedNumberFormatter | |
| public MeasureFormat. | |
| public final int | |
| private static String | |
| private static MeasureFormat. | |
| public Measure | parseObject(String
A source, ParsePosition String, part of which should be parsed.A pos)ParsePosition object with index and error
index information as described above.Implements abstract java. Measure.
|
| pack-priv Object | |
| private static Number[] | |
| pack-priv Object | |
| pack-priv MeasureFormat | |
| pack-priv MeasureFormat | |
| private Object |