当前位置: 首页>>代码示例>>Java>>正文


Java ChoiceFormat.format方法代码示例

本文整理汇总了Java中java.text.ChoiceFormat.format方法的典型用法代码示例。如果您正苦于以下问题:Java ChoiceFormat.format方法的具体用法?Java ChoiceFormat.format怎么用?Java ChoiceFormat.format使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.text.ChoiceFormat的用法示例。


在下文中一共展示了ChoiceFormat.format方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: main

import java.text.ChoiceFormat; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
    ChoiceFormat choiceFormat1 = new ChoiceFormat(doubles, strings);
    ChoiceFormat choiceFormat2 = new ChoiceFormat(pattern);
    if (!choiceFormat1.equals(choiceFormat2)) {
        System.out.println("choiceFormat1: " + choiceFormat1.toPattern());
        System.out.println("choiceFormat2: " + choiceFormat2.toPattern());
        throw new RuntimeException();
    }

    for (int i = 0; i < doubles.length; i++) {
        String result = choiceFormat2.format(doubles[i]);
        if (!result.equals(strings[i])) {
            throw new RuntimeException("Wrong format result - expected " +
                    strings[i] + ", got " + result);
        }
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:18,代码来源:Bug4387255.java

示例2: testFormat

import java.text.ChoiceFormat; //导入方法依赖的package包/类
private void testFormat(ChoiceFormat f, String pattern) throws Throwable {

        double[] numbers = { Double.NEGATIVE_INFINITY, -1.0, 0, 0.9, 1, 1.5, 2,
                2.1, Double.POSITIVE_INFINITY};

        //Framework fw = new Framework();

        String[] values = getValues();
        //Object [] values = new Object[numbers.length];
        testNextDouble();
        for (int i = 0; i < numbers.length; i++) {
            String format = f.format(numbers[i]);
            if (!values[i].equals(format)) {
                throw new Throwable("ChoiceFormat.format(" + numbers[i]
                        + ") ==" + format + " != " + values[i] + "\nPattern: '" + pattern + "'");
            }
        }
        //System.out.println(fw
        //        .generateGetter("values", values, String.class));

    }
 
开发者ID:freeVM,项目名称:freeVM,代码行数:22,代码来源:ChoiceFormatTest.java

示例3: ChoiceFormat

import java.text.ChoiceFormat; //导入方法依赖的package包/类
/**
 * @tests java.text.ChoiceFormat#ChoiceFormat(double[], java.lang.String[])
 */
public void test_Constructor$D$Ljava_lang_String() {
    // Test for method java.text.ChoiceFormat(double [], java.lang.String
    // [])
    String formattedString;
    double[] appleLimits = { 1, 2, 3, 4, 5 };
    String[] appleFormats = { "Tiny Apple", "Small Apple", "Medium Apple",
            "Large Apple", "Huge Apple" };
    ChoiceFormat cf = new ChoiceFormat(appleLimits, appleFormats);

    formattedString = cf.format(Double.NEGATIVE_INFINITY);
    assertTrue("a) Incorrect format returned: " + formattedString,
            formattedString.equals("Tiny Apple"));
    formattedString = cf.format(0.5d);
    assertTrue("b) Incorrect format returned: " + formattedString,
            formattedString.equals("Tiny Apple"));
    formattedString = cf.format(1d);
    assertTrue("c) Incorrect format returned: " + formattedString,
            formattedString.equals("Tiny Apple"));
    formattedString = cf.format(1.5d);
    assertTrue("d) Incorrect format returned: " + formattedString,
            formattedString.equals("Tiny Apple"));
    formattedString = cf.format(2d);
    assertTrue("e) Incorrect format returned: " + formattedString,
            formattedString.equals("Small Apple"));
    formattedString = cf.format(2.5d);
    assertTrue("f) Incorrect format returned: " + formattedString,
            formattedString.equals("Small Apple"));
    formattedString = cf.format(3d);
    assertTrue("g) Incorrect format returned: " + formattedString,
            formattedString.equals("Medium Apple"));
    formattedString = cf.format(4d);
    assertTrue("h) Incorrect format returned: " + formattedString,
            formattedString.equals("Large Apple"));
    formattedString = cf.format(5d);
    assertTrue("i) Incorrect format returned: " + formattedString,
            formattedString.equals("Huge Apple"));
    formattedString = cf.format(5.5d);
    assertTrue("j) Incorrect format returned: " + formattedString,
            formattedString.equals("Huge Apple"));
    formattedString = cf.format(6.0d);
    assertTrue("k) Incorrect format returned: " + formattedString,
            formattedString.equals("Huge Apple"));
    formattedString = cf.format(Double.POSITIVE_INFINITY);
    assertTrue("l) Incorrect format returned: " + formattedString,
            formattedString.equals("Huge Apple"));
}
 
开发者ID:Sellegit,项目名称:j2objc,代码行数:50,代码来源:ChoiceFormatTest.java

示例4: test_ConstructorLjava_lang_String

import java.text.ChoiceFormat; //导入方法依赖的package包/类
/**
 * @tests java.text.ChoiceFormat#ChoiceFormat(java.lang.String)
 */
public void test_ConstructorLjava_lang_String() {
    // Test for method java.text.ChoiceFormat(java.lang.String)
    String formattedString;
    String patternString = "-2#Inverted Orange| 0#No Orange| 0<Almost No Orange| 1#Normal Orange| 2#Expensive Orange";
    ChoiceFormat cf = new ChoiceFormat(patternString);

    formattedString = cf.format(Double.NEGATIVE_INFINITY);
    assertTrue("a) Incorrect format returned: " + formattedString,
            formattedString.equals("Inverted Orange"));
    formattedString = cf.format(-3);
    assertTrue("b) Incorrect format returned: " + formattedString,
            formattedString.equals("Inverted Orange"));
    formattedString = cf.format(-2);
    assertTrue("c) Incorrect format returned: " + formattedString,
            formattedString.equals("Inverted Orange"));
    formattedString = cf.format(-1);
    assertTrue("d) Incorrect format returned: " + formattedString,
            formattedString.equals("Inverted Orange"));
    formattedString = cf.format(-0);
    assertTrue("e) Incorrect format returned: " + formattedString,
            formattedString.equals("No Orange"));
    formattedString = cf.format(0);
    assertTrue("f) Incorrect format returned: " + formattedString,
            formattedString.equals("No Orange"));
    formattedString = cf.format(0.1);
    assertTrue("g) Incorrect format returned: " + formattedString,
            formattedString.equals("Almost No Orange"));
    formattedString = cf.format(1);
    assertTrue("h) Incorrect format returned: " + formattedString,
            formattedString.equals("Normal Orange"));
    formattedString = cf.format(1.5);
    assertTrue("i) Incorrect format returned: " + formattedString,
            formattedString.equals("Normal Orange"));
    formattedString = cf.format(2);
    assertTrue("j) Incorrect format returned: " + formattedString,
            formattedString.equals("Expensive Orange"));
    formattedString = cf.format(3);
    assertTrue("k) Incorrect format returned: " + formattedString,
            formattedString.equals("Expensive Orange"));
    formattedString = cf.format(Double.POSITIVE_INFINITY);
    assertTrue("l) Incorrect format returned: " + formattedString,
            formattedString.equals("Expensive Orange"));

}
 
开发者ID:Sellegit,项目名称:j2objc,代码行数:48,代码来源:ChoiceFormatTest.java


注:本文中的java.text.ChoiceFormat.format方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。