Most visited

Recently visited

Added in API level 24

MeasureFormat

public class MeasureFormat
extends UFormat

java.lang.Object
   ↳ java.text.Format
     ↳ android.icu.text.UFormat
       ↳ android.icu.text.MeasureFormat


度量对象的格式化程序。

要格式化一个Measure对象,首先使用MeasureFormat工厂方法创建一个格式化对象。 然后使用该对象的格式或formatMeasures方法。 以下是示例代码:

      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));
 

这个班级不会从一个单位转换到另一个单位。 它只是格式化它给出的任何单位

只要不推荐使用不推荐使用的子类TimeUnitFormat,该类就不可变且线程安全。 TimeUnitFormat不是线程安全的,并且是可变的。 虽然这个类有现有的子类,但这个类不支持新的子类。

也可以看看:

Summary

Nested classes

枚举 MeasureFormat.FormatWidth

格式化宽度枚举。

Public methods

final boolean equals(Object other)

当且仅当它们具有相同的formatWidth,locale和相等的数字格式时,两个MeasureFormats a和b才相等。

StringBuffer format(Object obj, StringBuffer toAppendTo, FieldPosition pos)

能够格式化收藏<? 扩展Measure>,Measure [],并通过委托formatMeasures进行度量。

StringBuilder formatMeasures(StringBuilder appendTo, FieldPosition fieldPosition, Measure... measures)

格式化一系列措施。

final String formatMeasures(Measure... measures)

格式化一系列措施。

static MeasureFormat getCurrencyFormat()

为默认的 FORMAT语言环境返回CurrencyAmount对象的格式化程序。

static MeasureFormat getCurrencyFormat(Locale locale)

返回给定 Locale CurrencyAmount对象的格式化程序。

static MeasureFormat getCurrencyFormat(ULocale locale)

返回给定语言环境中CurrencyAmount对象的格式化程序。

static MeasureFormat getInstance(Locale locale, MeasureFormat.FormatWidth formatWidth, NumberFormat format)

Locale ,formatWidth和格式创建一个格式。

static MeasureFormat getInstance(Locale locale, MeasureFormat.FormatWidth formatWidth)

Locale和formatWidth创建一个格式。

static MeasureFormat getInstance(ULocale locale, MeasureFormat.FormatWidth formatWidth)

根据语言环境,格式宽度和格式创建格式。

static MeasureFormat getInstance(ULocale locale, MeasureFormat.FormatWidth formatWidth, NumberFormat format)

根据语言环境,格式宽度和格式创建格式。

final ULocale getLocale()

获取此实例的区域设置。

NumberFormat getNumberFormat()

获取数字格式的副本。

MeasureFormat.FormatWidth getWidth()

获取此实例正在使用的格式宽度。

final int hashCode()

返回对象的哈希码值。

Inherited methods

From class java.text.Format
From class java.lang.Object

Public methods

equals

Added in API level 24
boolean equals (Object other)

当且仅当它们具有相同的formatWidth,locale和相等的数字格式时,两个MeasureFormats a和b才相等。

Parameters
other Object: the reference object with which to compare.
Returns
boolean true if this object is the same as the obj argument; false otherwise.

format

Added in API level 24
StringBuffer format (Object obj, 
                StringBuffer toAppendTo, 
                FieldPosition pos)

能够格式化收藏<? 扩展Measure>,Measure [],并通过委托formatMeasures进行度量。 如果pos参数标识NumberFormat字段,则其索引将设置为遇到的第一个此类字段的开头和结尾。 MeasureFormat本身不提供任何字段。 调用formatMeasures方法优于调用此方法,因为它们提供更好的性能。

Parameters
obj Object: must be a Collection<? extends Measure>, Measure[], or Measure object.
toAppendTo StringBuffer: Formatted string appended here.
pos FieldPosition: Identifies a field in the formatted text.
Returns
StringBuffer the string buffer passed in as toAppendTo, with formatted text appended

也可以看看:

formatMeasures

Added in API level 24
StringBuilder formatMeasures (StringBuilder appendTo, 
                FieldPosition fieldPosition, 
                Measure... measures)

格式化一系列措施。 如果fieldPosition参数标识一个NumberFormat字段,则其索引被设置为遇到的第一个这样的字段的开始和结尾。 MeasureFormat本身不提供任何字段。

Parameters
appendTo StringBuilder: the formatted string appended here.
fieldPosition FieldPosition: Identifies a field in the formatted text.
measures Measure: the measures to format.
Returns
StringBuilder appendTo.

也可以看看:

formatMeasures

Added in API level 24
String formatMeasures (Measure... measures)

格式化一系列措施。 使用ListFormatter单位列表。 因此,例如,可以格式为“3英尺2英寸”。 零值被格式化(例如,“3英尺,0英寸”)。 呼叫者有责任按适当的顺序获得适当的值,并使用适当的数值。 通常情况下,单位应该降序排列,除了最后一个度量值之外的所有值都具有整数值(例如,不是“3.2英尺,2英寸”)。

Parameters
measures Measure: a sequence of one or more measures.
Returns
String the formatted string.

getCurrencyFormat

Added in API level 24
MeasureFormat getCurrencyFormat ()

为默认的 FORMAT区域设置返回CurrencyAmount对象的格式化程序。

Returns
MeasureFormat a formatter object

也可以看看:

getCurrencyFormat

Added in API level 24
MeasureFormat getCurrencyFormat (Locale locale)

返回给定 Locale CurrencyAmount对象的格式化程序。

Parameters
locale Locale: desired Locale
Returns
MeasureFormat a formatter object

getCurrencyFormat

Added in API level 24
MeasureFormat getCurrencyFormat (ULocale locale)

返回给定语言环境中CurrencyAmount对象的格式化程序。

Parameters
locale ULocale: desired locale
Returns
MeasureFormat a formatter object

getInstance

Added in API level 24
MeasureFormat getInstance (Locale locale, 
                MeasureFormat.FormatWidth formatWidth, 
                NumberFormat format)

Locale ,formatWidth和格式创建一个格式。

Parameters
locale Locale: the Locale.
formatWidth MeasureFormat.FormatWidth: hints how long formatted strings should be.
format NumberFormat: This is defensively copied.
Returns
MeasureFormat The new MeasureFormat object.

getInstance

Added in API level 24
MeasureFormat getInstance (Locale locale, 
                MeasureFormat.FormatWidth formatWidth)

Locale和formatWidth创建一个格式。

Parameters
locale Locale: the Locale.
formatWidth MeasureFormat.FormatWidth: hints how long formatted strings should be.
Returns
MeasureFormat The new MeasureFormat object.

getInstance

Added in API level 24
MeasureFormat getInstance (ULocale locale, 
                MeasureFormat.FormatWidth formatWidth)

根据语言环境,格式宽度和格式创建格式。

Parameters
locale ULocale: the locale.
formatWidth MeasureFormat.FormatWidth: hints how long formatted strings should be.
Returns
MeasureFormat The new MeasureFormat object.

getInstance

Added in API level 24
MeasureFormat getInstance (ULocale locale, 
                MeasureFormat.FormatWidth formatWidth, 
                NumberFormat format)

根据语言环境,格式宽度和格式创建格式。

Parameters
locale ULocale: the locale.
formatWidth MeasureFormat.FormatWidth: hints how long formatted strings should be.
format NumberFormat: This is defensively copied.
Returns
MeasureFormat The new MeasureFormat object.

getLocale

Added in API level 24
ULocale getLocale ()

获取此实例的区域设置。

Returns
ULocale

getNumberFormat

Added in API level 24
NumberFormat getNumberFormat ()

获取数字格式的副本。

Returns
NumberFormat

getWidth

Added in API level 24
MeasureFormat.FormatWidth getWidth ()

获取此实例正在使用的格式宽度。

Returns
MeasureFormat.FormatWidth

hashCode

Added in API level 24
int hashCode ()

返回对象的哈希码值。 此方法支持哈希表的好处,例如HashMap提供的哈希表。

hashCode的总合同是:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals(Object) method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals(java.lang.Object) method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.

尽可能合理实用,由类Object定义的hashCode方法确实为不同的对象返回不同的整数。 (这通常通过将对象的内部地址转换为整数来实现,但Java TM编程语言不需要此实现技术。)

Returns
int a hash code value for this object.

Hooray!