java.text.ChoiceFormat#format ( )源码实例Demo

下面列出了java.text.ChoiceFormat#format ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: dragonwell8_jdk   文件: Bug4387255.java
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);
        }
    }
}
 
源代码2 项目: TencentKona-8   文件: Bug4387255.java
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);
        }
    }
}
 
源代码3 项目: openjdk-jdk8u   文件: Bug4387255.java
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);
        }
    }
}
 
源代码4 项目: openjdk-jdk9   文件: Bug4387255.java
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);
        }
    }
}
 
源代码5 项目: jdk8u_jdk   文件: Bug4387255.java
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);
        }
    }
}
 
源代码6 项目: j2objc   文件: MessageRegressionTest.java
@Test
public void Test4106660()
{
    double[] limits = {3, 1, 2};
    String[] formats = {"Three", "One", "Two"};
    ChoiceFormat cf = new ChoiceFormat(limits, formats);
    double d = 5.0;
    String str = cf.format(d);
    if (!str.equals("Two"))
        errln("format(" + d + ") = " + cf.format(d));
}
 
源代码7 项目: j2objc   文件: MessageRegressionTest.java
/**
 * @bug 4142938
 * Test the applyPattern and toPattern handling of single quotes
 * by ChoiceFormat.  (This is in here because this was a bug reported
 * against MessageFormat.)  The single quote is used to quote the
 * pattern characters '|', '#', '<', and '\u2264'.  Two quotes in a row
 * is a quote literal.
 */
@Test
public void TestChoicePatternQuote() {
    String[] DATA = {
        // Pattern                  0 value           1 value
        "0#can''t|1#can",           "can't",          "can",
        "0#'pound(#)=''#'''|1#xyz", "pound(#)='#'",   "xyz",
        "0#'1<2 | 1\u22641'|1#''",  "1<2 | 1\u22641", "'",
    };
    for (int i=0; i<DATA.length; i+=3) {
        try {
            ChoiceFormat cf = new ChoiceFormat(DATA[i]);
            for (int j=0; j<=1; ++j) {
                String out = cf.format(j);
                if (!out.equals(DATA[i+1+j]))
                    errln("Fail: Pattern \"" + DATA[i] + "\" x "+j+" -> " +
                          out + "; want \"" + DATA[i+1+j] + '"');
            }
            String pat = cf.toPattern();
            String pat2 = new ChoiceFormat(pat).toPattern();
            if (!pat.equals(pat2))
                errln("Fail: Pattern \"" + DATA[i] + "\" x toPattern -> \"" + pat + '"');
            else
                logln("Ok: Pattern \"" + DATA[i] + "\" x toPattern -> \"" + pat + '"');
        }
        catch (IllegalArgumentException e) {
            errln("Fail: Pattern \"" + DATA[i] + "\" -> " + e);
        }
    }
}
 
源代码8 项目: j2objc   文件: ChoiceFormatTest.java
/**
 * @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"));
}
 
源代码9 项目: j2objc   文件: ChoiceFormatTest.java
/**
 * @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"));

}
 
 方法所在类
 同类方法