Package java.text

Examples of java.text.ChoiceFormat


            };
            double[] choiceLimits = { 1, 2 };
           
            MessageFormat fmt = new MessageFormat("");
            fmt.setLocale( WikiContext.getLocale(m_context) );
            ChoiceFormat cfmt = new ChoiceFormat( choiceLimits, choiceString );
            fmt.applyPattern( type );
            Format[] formats = { NumberFormat.getInstance(), cfmt, NumberFormat.getInstance() };
            fmt.setFormats( formats );
           
            Object[] params = { changed.first() + 1,
View Full Code Here


            errln("setErrorIndex failed, got " + pos.getErrorIndex() + " instead of 4");
       
        if (objs != null) {
            errln("objs should be null");
        }
        ChoiceFormat f = new ChoiceFormat(
            "-1#are negative|0#are no or fraction|1#is one|1.0<is 1+|2#are two|2<are more than 2.");
        pos.setIndex(0); pos.setErrorIndex(-1);
        Number obj = f.parse("are negative", pos);
        if (pos.getErrorIndex() != -1 && obj.doubleValue() == -1.0)
            errln("Parse with \"are negative\" failed, at " + pos.getErrorIndex());
        pos.setIndex(0); pos.setErrorIndex(-1);
        obj = f.parse("are no or fraction ", pos);
        if (pos.getErrorIndex() != -1 && obj.doubleValue() == 0.0)
            errln("Parse with \"are no or fraction\" failed, at " + pos.getErrorIndex());
        pos.setIndex(0); pos.setErrorIndex(-1);
        obj = f.parse("go postal", pos);
        if (pos.getErrorIndex() == -1 && !Double.isNaN(obj.doubleValue()))
            errln("Parse with \"go postal\" failed, at " + pos.getErrorIndex());
    }
View Full Code Here

     */
    public void Test4104976()
    {
        double[] limits = {1, 20};
        String[] formats = {"xyz", "abc"};
        ChoiceFormat cf = new ChoiceFormat(limits, formats);
        try {
            log("Compares to null is always false, returned : ");
            logln(cf.equals(null) ? "TRUE" : "FALSE");
        } catch (Exception foo) {
            errln("ChoiceFormat.equals(null) throws exception.");
        }
    }
View Full Code Here

     */
    public void Test4106659()
    {
        double[] limits = {1, 2, 3};
        String[] formats = {"one", "two"};
        ChoiceFormat cf = null;
        try {
            cf = new ChoiceFormat(limits, formats);
        } catch (Exception foo) {
            logln("ChoiceFormat constructor should check for the array lengths");
            cf = null;
        }
        if (cf != null) errln(cf.format(5));
    }
View Full Code Here

     */
    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));
    }
View Full Code Here

    /* @bug 4106661
     * ChoiceFormat is silent about the pattern usage in javadoc.
     */
    public void Test4106661()
    {
        ChoiceFormat fmt = new ChoiceFormat(
          "-1#are negative| 0#are no or fraction | 1#is one |1.0<is 1+ |2#are two |2<are more than 2.");
        logln("Formatter Pattern : " + fmt.toPattern());

        logln("Format with -INF : " + fmt.format(Double.NEGATIVE_INFINITY));
        logln("Format with -1.0 : " + fmt.format(-1.0));
        logln("Format with 0 : " + fmt.format(0));
        logln("Format with 0.9 : " + fmt.format(0.9));
        logln("Format with 1.0 : " + fmt.format(1));
        logln("Format with 1.5 : " + fmt.format(1.5));
        logln("Format with 2 : " + fmt.format(2));
        logln("Format with 2.1 : " + fmt.format(2.1));
        logln("Format with NaN : " + fmt.format(Double.NaN));
        logln("Format with +INF : " + fmt.format(Double.POSITIVE_INFINITY));
    }
View Full Code Here

    /* @bug 4094906
     * ChoiceFormat should accept \u221E as eq. to INF.
     */
    public void Test4094906()
    {
        ChoiceFormat fmt = new ChoiceFormat(
          "-\u221E<are negative|0<are no or fraction|1#is one|1.0<is 1+|\u221E<are many.");
        if (!fmt.toPattern().startsWith("-\u221E<are negative|0.0<are no or fraction|1.0#is one|1.0<is 1+|\u221E<are many."))
            errln("Formatter Pattern : " + fmt.toPattern());
        logln("Format with -INF : " + fmt.format(Double.NEGATIVE_INFINITY));
        logln("Format with -1.0 : " + fmt.format(-1.0));
        logln("Format with 0 : " + fmt.format(0));
        logln("Format with 0.9 : " + fmt.format(0.9));
        logln("Format with 1.0 : " + fmt.format(1));
        logln("Format with 1.5 : " + fmt.format(1.5));
        logln("Format with 2 : " + fmt.format(2));
        logln("Format with +INF : " + fmt.format(Double.POSITIVE_INFINITY));
    }
View Full Code Here

        String patternText2 = "There are {0} on the disk \"{1}\"";
        MessageFormat form1 = new MessageFormat(patternText1);
        MessageFormat form2 = new MessageFormat(patternText2);
        double[] filelimits = {0,1,2};
        String[] filepart = {"no files","one file","{0,number} files"};
        ChoiceFormat fileform = new ChoiceFormat(filelimits, filepart);
        form1.setFormat(1, fileform);
        form2.setFormat(0, fileform);
        Object[] testArgs = {new Long(12373), "MyDisk"};
        logln(form1.format(testArgs));
        logln(form2.format(testArgs));
View Full Code Here

            "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 + '"');
            }
View Full Code Here

        String patternText2 = "There are {numberOfFiles} on the disk \"{diskName}\"";
        MessageFormat form1 = new MessageFormat(patternText1);
        MessageFormat form2 = new MessageFormat(patternText2);
        double[] filelimits = {0,1,2};
        String[] filepart = {"no files","one file","{numberOfFiles,number} files"};
        ChoiceFormat fileform = new ChoiceFormat(filelimits, filepart);
        form1.setFormat(1, fileform);
        form2.setFormat(0, fileform);
        Map testArgs = new HashMap();
        testArgs.put("diskName", "MyDisk");
        testArgs.put("numberOfFiles", new Long(12373));
View Full Code Here

TOP

Related Classes of java.text.ChoiceFormat

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.