Package java.text

Examples of java.text.MessageFormat.applyPattern()


            Locale locale,
            TimeZone timezone)
    {
        MessageFormat mf = new MessageFormat(" ");
        mf.setLocale(locale);
        mf.applyPattern(template);
        if (!timezone.equals(TimeZone.getDefault()))
        {
            Format[] formats = mf.getFormats();
            for (int i = 0; i < formats.length; i++)
            {
View Full Code Here


        assertTrue("Wrong integer number format", format.getFormats()[0]
                .equals(nf));
    assertEquals("Wrong integer number pattern",
        "{0,number,integer}", format.toPattern());

        format.applyPattern("{0, number, {'#'}##0.0E0}");

        /*
         * TODO validate these assertions
         * String actual = ((DecimalFormat)(format.getFormats()[0])).toPattern();
         * assertEquals("Wrong pattern number format", "' {#}'##0.0E0", actual);
View Full Code Here

         * assertEquals("Wrong pattern number format", "' {#}'##0.0E0", actual);
         * assertEquals("Wrong pattern number pattern", "{0,number,' {#}'##0.0E0}", format.toPattern());
         *
         */

        format.applyPattern("{0, choice,0#no|1#one|2#{1,number}}");
    assertEquals("Wrong choice format",
       
            "0.0#no|1.0#one|2.0#{1,number}", ((ChoiceFormat) format.getFormats()[0]).toPattern());
    assertEquals("Wrong choice pattern",
        "{0,choice,0.0#no|1.0#one|2.0#{1,number}}", format.toPattern());
View Full Code Here

        "{0,choice,0.0#no|1.0#one|2.0#{1,number}}", format.toPattern());
    assertEquals("Wrong formatted choice", "3.6", format.format(
        new Object[] { new Integer(2), new Float(3.6) }));

        try {
            format.applyPattern("WRONG MESSAGE FORMAT {0,number,{}");
            fail("Expected IllegalArgumentException for invalid pattern");
        } catch (IllegalArgumentException e) {
        }
       
        // Regression for HARMONY-65
View Full Code Here

       
        // Regression for HARMONY-65
        MessageFormat mf = new MessageFormat("{0,number,integer}");
        String badpattern = "{0,number,#";
        try {
            mf.applyPattern(badpattern);
            fail("Assert 0: Failed to detect unmatched brackets.");
        } catch (IllegalArgumentException e) {
            // expected
        }
    }
View Full Code Here

        // Test for method boolean
        // java.text.MessageFormat.equals(java.lang.Object)
        MessageFormat format1 = new MessageFormat("{0}");
        MessageFormat format2 = new MessageFormat("{1}");
        assertTrue("Should not be equal", !format1.equals(format2));
        format2.applyPattern("{0}");
        assertTrue("Should be equal", format1.equals(format2));
        SimpleDateFormat date = (SimpleDateFormat) DateFormat.getTimeInstance();
        format1.setFormat(0, DateFormat.getTimeInstance());
        format2.setFormat(0, new SimpleDateFormat(date.toPattern()));
        assertTrue("Should be equal2", format1.equals(format2));
View Full Code Here

        MessageFormat format = new MessageFormat("{1,number,integer}");
        StringBuffer buffer = new StringBuffer();
        format.format(new Object[] { "0", new Double(53.863) }, buffer,
                new FieldPosition(0));
    assertEquals("Wrong result", "54", buffer.toString());
        format
                .applyPattern("{0,choice,0#zero|1#one '{1,choice,2#two {2,time}}'}");
        Date date = new Date();
        String expected = "one two "
                + DateFormat.getTimeInstance().format(date);
        String result = format.format(new Object[] { new Double(1.6),
View Full Code Here

        // Test for method void
        // java.text.MessageFormat.setLocale(java.util.Locale)
        MessageFormat format = new MessageFormat("date {0,date}");
        format.setLocale(Locale.CHINA);
        assertEquals("Wrong locale1", Locale.CHINA, format.getLocale());
        format.applyPattern("{1,date}");
        assertEquals("Wrong locale3", DateFormat.getDateInstance(DateFormat.DEFAULT,
                Locale.CHINA), format.getFormats()[0]);
    }

    /**
 
View Full Code Here

     */
    public void test_applyPatternLjava_lang_String() {
        // Test for method void
        // java.text.MessageFormat.applyPattern(java.lang.String)
        MessageFormat format = new MessageFormat("test");
        format.applyPattern("xx {0}");
    assertEquals("Invalid number", "xx 46", format.format(
        new Object[] { new Integer(46) }));
        Date date = new Date();
        String result = format.format(new Object[] { date });
        String expected = "xx " + DateFormat.getInstance().format(date);
View Full Code Here

        String result = format.format(new Object[] { date });
        String expected = "xx " + DateFormat.getInstance().format(date);
        assertTrue("Invalid date:\n" + result + "\n" + expected, result
                .equals(expected));
        format = new MessageFormat("{0,date}{1,time}{2,number,integer}");
        format.applyPattern("nothing");
    assertEquals("Found formats", "nothing", format.toPattern());

        format.applyPattern("{0}");
    assertNull("Wrong format", format.getFormats()[0]);
    assertEquals("Wrong pattern", "{0}", format.toPattern());
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. 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.