ChoiceFormat 类

定义

A ChoiceFormat 允许将格式附加到一系列数字。

[Android.Runtime.Register("java/text/ChoiceFormat", DoNotGenerateAcw=true)]
public class ChoiceFormat : Java.Text.NumberFormat
[<Android.Runtime.Register("java/text/ChoiceFormat", DoNotGenerateAcw=true)>]
type ChoiceFormat = class
    inherit NumberFormat
继承
属性

注解

A ChoiceFormat 允许将格式附加到一系列数字。 它通常用于 MessageFormat 处理复数。 该选项使用双精度值升序列表进行指定,其中每个项指定下一项的半打开间隔: <blockquote>

X matches j if and only if limit[j] &le; X &lt; limit[j+1]

</blockquote> 如果不存在匹配项,则使用第一个或最后一个索引,具体取决于数字 (X) 是否太低或太高。 如果限制数组不按升序排列,格式设置的结果将不正确。 ChoiceFormat 也接受 &#92;u221E 等效于无穷大(INF)。

<strong Note:</strong>ChoiceFormat> 不同于其他Format类,即使用构造函数创建ChoiceFormat对象(而不是getInstance样式工厂方法)。 不需要工厂方法,因为 ChoiceFormat 不需要给定区域设置的任何复杂设置。 事实上, ChoiceFormat 不实现任何区域设置特定的行为。

创建时 ChoiceFormat,必须指定格式数组和限制数组。 这些数组的长度必须相同。 例如,<ul<>li<>em>limits</em> = {1,2,3,4,5,6,7}<br em>formats</em> = {“Sun”,“Mon”,“Tue”,“Wed”,“Thur”,“Fri”,“Sat”}<li<>em>limits</em = {0, 1, ChoiceFormat.nextDouble(1)}><<br<>em>formats</em>> = {“no files”, “one file”, “many files”}<br> (nextDouble可用于获取下一个更高的双精度,使半开间隔)。 </ul>

下面是显示格式和分析的简单示例: <blockquote>

{@code
            double[] limits = {1,2,3,4,5,6,7};
            String[] dayOfWeekNames = {"Sun","Mon","Tue","Wed","Thur","Fri","Sat"};
            ChoiceFormat form = new ChoiceFormat(limits, dayOfWeekNames);
            ParsePosition status = new ParsePosition(0);
            for (double i = 0.0; i <= 8.0; ++i) {
                status.setIndex(0);
                System.out.println(i + " -> " + form.format(i) + " -> "
                                         + form.parse(form.format(i),status));
            }
            }

</blockquote> 下面是一个更复杂的示例,其模式格式为: <blockquote>

{@code
            double[] filelimits = {0,1,2};
            String[] filepart = {"are no files","is one file","are {2} files"};
            ChoiceFormat fileform = new ChoiceFormat(filelimits, filepart);
            Format[] testFormats = {fileform, null, NumberFormat.getInstance()};
            MessageFormat pattform = new MessageFormat("There {0} on {1}");
            pattform.setFormats(testFormats);
            Object[] testArgs = {null, "ADisk", null};
            for (int i = 0; i < 4; ++i) {
                testArgs[0] = new Integer(i);
                testArgs[2] = testArgs[0];
                System.out.println(pattform.format(testArgs));
            }
            }

</blockquote>

指定 ChoiceFormat 对象的模式非常简单。 例如: <blockquote>

{@code
            ChoiceFormat fmt = new ChoiceFormat(
                 "-1#is negative| 0#is zero or fraction | 1#is one |1.0<is 1+ |2#is two |2<is more than 2.");
            System.out.println("Formatter Pattern : " + fmt.toPattern());

            System.out.println("Format with -INF : " + fmt.format(Double.NEGATIVE_INFINITY));
            System.out.println("Format with -1.0 : " + fmt.format(-1.0));
            System.out.println("Format with 0 : " + fmt.format(0));
            System.out.println("Format with 0.9 : " + fmt.format(0.9));
            System.out.println("Format with 1.0 : " + fmt.format(1));
            System.out.println("Format with 1.5 : " + fmt.format(1.5));
            System.out.println("Format with 2 : " + fmt.format(2));
            System.out.println("Format with 2.1 : " + fmt.format(2.1));
            System.out.println("Format with NaN : " + fmt.format(Double.NaN));
            System.out.println("Format with +INF : " + fmt.format(Double.POSITIVE_INFINITY));
            }

</blockquote> 和输出结果如下所示: <blockquote>

{@code
            Format with -INF : is negative
            Format with -1.0 : is negative
            Format with 0 : is zero or fraction
            Format with 0.9 : is zero or fraction
            Format with 1.0 : is one
            Format with 1.5 : is 1+
            Format with 2 : is two
            Format with 2.1 : is more than 2.
            Format with NaN : is negative
            Format with +INF : is more than 2.
            }

</blockquote>

<h2>“synchronization”>Synchronization</h2>

选项格式未同步。 建议为每个线程创建单独的格式实例。 如果多个线程同时访问格式,则必须在外部同步。

在 1.1 中添加。

Java文档java.text.ChoiceFormat

本页的某些部分是根据 创建和共享的工作进行的修改,并根据 许可证中所述的条款使用。

构造函数

名称 说明
ChoiceFormat(Double[], String[])

使用限制和相应的格式构造。

ChoiceFormat(IntPtr, JniHandleOwnership)

创建 JNI 对象的托管表示形式时使用的构造函数;由运行时调用。

ChoiceFormat(String)

基于模式具有限制和相应格式的构造。

字段

名称 说明
FractionField

用于构造 FieldPosition 对象的字段常量。

(继承自 NumberFormat)
IntegerField

用于构造 FieldPosition 对象的字段常量。

(继承自 NumberFormat)

属性

名称 说明
Class

返回此 Object的运行时类。

(继承自 Object)
Currency

获取格式设置货币值时此数字格式使用的货币。 - 或 - 设置格式设置货币值格式时此数字格式使用的货币。

(继承自 NumberFormat)
GroupingUsed

如果采用此格式使用分组,则返回 true。 - 或 - 设置是否将使用此格式的分组。

(继承自 NumberFormat)
Handle

基础 Android 实例的句柄。

(继承自 Object)
JniIdentityHashCode

A ChoiceFormat 允许将格式附加到一系列数字。

(继承自 Object)
JniPeerMembers

A ChoiceFormat 允许将格式附加到一系列数字。

MaximumFractionDigits

返回数字的分数部分允许的最大位数。 - 或 - 设置数字的分数部分允许的最大位数。

(继承自 NumberFormat)
MaximumIntegerDigits

返回数字整数部分中允许的最大位数。 - 或 - 设置数字整数部分中允许的最大位数。

(继承自 NumberFormat)
MinimumFractionDigits

返回数字的分数部分允许的最小位数。 - 或 - 设置数字的分数部分允许的最小位数。

(继承自 NumberFormat)
MinimumIntegerDigits

返回数字整数部分中允许的最小位数。 - 或 - 设置数字整数部分中允许的最小位数。

(继承自 NumberFormat)
ParseIntegerOnly

如果此格式将仅将数字分析为整数,则返回 true。 - 或 - 设置是否只应将数字分析为整数。

(继承自 NumberFormat)
PeerReference

A ChoiceFormat 允许将格式附加到一系列数字。

(继承自 Object)
RoundingMode

java.math.RoundingMode获取此 NumberFormat 中使用的值。 - 或 - 设置 java.math.RoundingMode 此 NumberFormat 中使用的值。

(继承自 NumberFormat)
ThresholdClass

此 API 支持 Mono for Android 基础结构,不打算直接从代码使用。

ThresholdType

此 API 支持 Mono for Android 基础结构,不打算直接从代码使用。

方法

名称 说明
ApplyPattern(String)

设置模式。

Clone()

创建并返回此对象的副本。

(继承自 _Format)
Dispose()

A ChoiceFormat 允许将格式附加到一系列数字。

(继承自 Object)
Dispose(Boolean)

A ChoiceFormat 允许将格式附加到一系列数字。

(继承自 Object)
Equals(Object)

指示其他对象是否“等于”此对象。

(继承自 Object)
Format(Double, StringBuffer, FieldPosition)

返回格式为双精度的模式。

Format(Double)

格式的专用化。

(继承自 NumberFormat)
Format(Int64, StringBuffer, FieldPosition)

格式的专用化。

Format(Int64)

格式的专用化。

(继承自 NumberFormat)
Format(Object, StringBuffer, FieldPosition)

设置数字的格式,并将生成的文本追加到给定的字符串缓冲区。

(继承自 NumberFormat)
Format(Object)

设置对象的格式以生成字符串。

(继承自 _Format)
FormatToCharacterIterator(Object)

设置生成 . 的对象 AttributedCharacterIterator的格式。

(继承自 _Format)
GetFormats()

返回与此范围 ChoiceFormat关联的字符串。

GetHashCode()

返回对象的哈希代码值。

(继承自 Object)
GetLimits()

返回此 ChoiceFormat限制。

JavaFinalize()

当垃圾回收确定不再引用该对象时,由对象上的垃圾回收器调用。

(继承自 Object)
NextDouble(Double, Boolean)

查找大于d(如果positivetrue)或小于d(如果positivefalse为)的最大双精度值。

NextDouble(Double)

查找大于 d的最小双精度值。

Notify()

唤醒正在等待此对象的监视器的单个线程。

(继承自 Object)
NotifyAll()

唤醒正在等待此对象的监视器的所有线程。

(继承自 Object)
Parse(String, ParsePosition)

分析输入文本中的数字。

Parse(String)

分析给定字符串开头的文本以生成数字。

(继承自 NumberFormat)
ParseObject(String, ParsePosition)

分析字符串中的文本以生成一个 Number

(继承自 NumberFormat)
ParseObject(String)

分析给定字符串开头的文本以生成对象。

(继承自 _Format)
PreviousDouble(Double)

查找小于 d的最大双精度值。

SetChoices(Double[], String[])

设置要用于格式设置的选项。

SetHandle(IntPtr, JniHandleOwnership)

设置 Handle 属性。

(继承自 Object)
ToArray<T>()

A ChoiceFormat 允许将格式附加到一系列数字。

(继承自 Object)
ToPattern()

获取模式。

ToString()

返回对象的字符串表示形式。

(继承自 Object)
UnregisterFromRuntime()

A ChoiceFormat 允许将格式附加到一系列数字。

(继承自 Object)
Wait()

使当前线程等待,直到唤醒它,通常是通过 em 通知/em< 或 >em<interrupted>/em<。><>

(继承自 Object)
Wait(Int64, Int32)

使当前线程等待直到唤醒,通常是通过 <em>通知</em> 或 <em interrupted>/em<>,或直到经过一定数量的实时。

(继承自 Object)
Wait(Int64)

使当前线程等待直到唤醒,通常是通过 <em>通知</em> 或 <em interrupted>/em<>,或直到经过一定数量的实时。

(继承自 Object)

显式接口实现

名称 说明
IJavaPeerable.Disposed()

A ChoiceFormat 允许将格式附加到一系列数字。

(继承自 Object)
IJavaPeerable.DisposeUnlessReferenced()

A ChoiceFormat 允许将格式附加到一系列数字。

(继承自 Object)
IJavaPeerable.Finalized()

A ChoiceFormat 允许将格式附加到一系列数字。

(继承自 Object)
IJavaPeerable.JniManagedPeerState

A ChoiceFormat 允许将格式附加到一系列数字。

(继承自 Object)
IJavaPeerable.SetJniIdentityHashCode(Int32)

A ChoiceFormat 允许将格式附加到一系列数字。

(继承自 Object)
IJavaPeerable.SetJniManagedPeerState(JniManagedPeerStates)

A ChoiceFormat 允许将格式附加到一系列数字。

(继承自 Object)
IJavaPeerable.SetPeerReference(JniObjectReference)

A ChoiceFormat 允许将格式附加到一系列数字。

(继承自 Object)

扩展方法

名称 说明
GetJniTypeName(IJavaPeerable)

获取实例 self类型的 JNI 名称。

JavaAs<TResult>(IJavaPeerable)

尝试强制self键入TResult,检查强制是否在Java端有效。

JavaCast<TResult>(IJavaObject)

执行 Android 运行时检查的类型转换。

JavaCast<TResult>(IJavaObject)

A ChoiceFormat 允许将格式附加到一系列数字。

TryJavaCast<TResult>(IJavaPeerable, TResult)

尝试强制self键入TResult,检查强制是否在Java端有效。

适用于