Search in sources :

Example 11 with ChoiceFormat

use of java.text.ChoiceFormat in project j2objc by google.

the class ChoiceFormatTest method testToPatternWithInfinities.

// http://b/19149384
public void testToPatternWithInfinities() {
    final ChoiceFormat fmt = new ChoiceFormat("-∞<are negative|0<are fractions|1#is one|1.0<is 1+|∞<are many.");
    assertEquals("-∞<are negative|0.0<are fractions|1.0#is one|1.0<is 1+|∞<are many.", fmt.toPattern());
}
Also used : ChoiceFormat(java.text.ChoiceFormat)

Example 12 with ChoiceFormat

use of java.text.ChoiceFormat in project j2objc by google.

the class MessageFormatTest method test_setFormatByArgumentIndexILjava_text_Format.

public void test_setFormatByArgumentIndexILjava_text_Format() {
    // test for method setFormatByArgumentIndex(int, Format)
    MessageFormat f1 = (MessageFormat) format1.clone();
    f1.setFormatByArgumentIndex(0, DateFormat.getTimeInstance());
    f1.setFormatByArgumentIndex(4, new ChoiceFormat("1#few|2#ok|3#a lot"));
    // test with repeating formats and max argument index < max offset
    // compare getFormatsByArgumentIndex() results after calls to
    // setFormatByArgumentIndex()
    Format[] formats = f1.getFormatsByArgumentIndex();
    Format[] correctFormats = new Format[] { DateFormat.getTimeInstance(), new ChoiceFormat("0#off|1#on"), DateFormat.getTimeInstance(), NumberFormat.getCurrencyInstance(), new ChoiceFormat("1#few|2#ok|3#a lot") };
    assertEquals("Test1A:Returned wrong number of formats:", correctFormats.length, formats.length);
    for (int i = 0; i < correctFormats.length; i++) {
        assertEquals("Test1B:wrong format for argument index " + i + ":", correctFormats[i], formats[i]);
    }
    // compare getFormats() results after calls to
    // setFormatByArgumentIndex()
    formats = f1.getFormats();
    correctFormats = new Format[] { NumberFormat.getCurrencyInstance(), DateFormat.getTimeInstance(), DateFormat.getTimeInstance(), new ChoiceFormat("1#few|2#ok|3#a lot"), new ChoiceFormat("0#off|1#on"), DateFormat.getTimeInstance() };
    assertEquals("Test1C:Returned wrong number of formats:", correctFormats.length, formats.length);
    for (int i = 0; i < correctFormats.length; i++) {
        assertEquals("Test1D:wrong format for pattern index " + i + ":", correctFormats[i], formats[i]);
    }
    // test setting argumentIndexes that are not used
    MessageFormat f2 = (MessageFormat) format2.clone();
    f2.setFormatByArgumentIndex(2, NumberFormat.getPercentInstance());
    f2.setFormatByArgumentIndex(4, DateFormat.getTimeInstance());
    formats = f2.getFormatsByArgumentIndex();
    correctFormats = format2.getFormatsByArgumentIndex();
    assertEquals("Test2A:Returned wrong number of formats:", correctFormats.length, formats.length);
    for (int i = 0; i < correctFormats.length; i++) {
        assertEquals("Test2B:wrong format for argument index " + i + ":", correctFormats[i], formats[i]);
    }
    formats = f2.getFormats();
    correctFormats = format2.getFormats();
    assertEquals("Test2C:Returned wrong number of formats:", correctFormats.length, formats.length);
    for (int i = 0; i < correctFormats.length; i++) {
        assertEquals("Test2D:wrong format for pattern index " + i + ":", correctFormats[i], formats[i]);
    }
    // test exceeding the argumentIndex number
    MessageFormat f3 = (MessageFormat) format3.clone();
    f3.setFormatByArgumentIndex(1, NumberFormat.getCurrencyInstance());
    formats = f3.getFormatsByArgumentIndex();
    assertEquals("Test3A:Returned wrong number of formats:", 0, formats.length);
    formats = f3.getFormats();
    assertEquals("Test3B:Returned wrong number of formats:", 0, formats.length);
}
Also used : Format(java.text.Format) DecimalFormat(java.text.DecimalFormat) SimpleDateFormat(java.text.SimpleDateFormat) NumberFormat(java.text.NumberFormat) MessageFormat(java.text.MessageFormat) ChoiceFormat(java.text.ChoiceFormat) DateFormat(java.text.DateFormat) MessageFormat(java.text.MessageFormat) ChoiceFormat(java.text.ChoiceFormat)

Example 13 with ChoiceFormat

use of java.text.ChoiceFormat in project j2objc by google.

the class NumberFormatTest method test_setRoundingMode_Normal.

public void test_setRoundingMode_Normal() {
    try {
        // Create a subclass ChoiceFormat which doesn't support
        // RoundingMode
        ChoiceFormat choiceFormat = new ChoiceFormat("0#Less than one|1#one|1<Between one and two|2<Greater than two");
        ((NumberFormat) choiceFormat).setRoundingMode(RoundingMode.CEILING);
        fail("UnsupportedOperationException expected");
    } catch (UnsupportedOperationException e) {
    // expected
    }
}
Also used : ChoiceFormat(java.text.ChoiceFormat) NumberFormat(java.text.NumberFormat)

Example 14 with ChoiceFormat

use of java.text.ChoiceFormat in project j2objc by google.

the class NumberFormatTest method test_setCurrencyLjava_util_Currency.

/**
     * @tests java.text.NumberFormat#setCurrency(java.util.Currency)
     */
public void test_setCurrencyLjava_util_Currency() {
    // Test for method void setCurrency(java.util.Currency)
    // a subclass that supports currency formatting
    Currency currA = Currency.getInstance("ARS");
    NumberFormat format = NumberFormat.getInstance(new Locale("hu", "HU"));
    format.setCurrency(currA);
    assertSame("Returned incorrect currency", currA, format.getCurrency());
    // a subclass that doesn't support currency formatting
    ChoiceFormat cformat = new ChoiceFormat("0#Less than one|1#one|1<Between one and two|2<Greater than two");
    try {
        ((NumberFormat) cformat).setCurrency(currA);
        fail("Expected UnsupportedOperationException");
    } catch (UnsupportedOperationException e) {
    }
}
Also used : Locale(java.util.Locale) Currency(java.util.Currency) ChoiceFormat(java.text.ChoiceFormat) NumberFormat(java.text.NumberFormat)

Example 15 with ChoiceFormat

use of java.text.ChoiceFormat in project robovm by robovm.

the class OldMessageFormatTest method test_setFormats$Ljava_text_Format.

public void test_setFormats$Ljava_text_Format() {
    try {
        MessageFormat f1 = (MessageFormat) format1.clone();
        // case 1: Test with repeating formats and max argument index < max
        // offset
        // compare getFormats() results after calls to setFormats(Format[])
        Format[] correctFormats = new Format[] { DateFormat.getTimeInstance(), new ChoiceFormat("0#off|1#on"), DateFormat.getTimeInstance(), NumberFormat.getCurrencyInstance(), new ChoiceFormat("1#few|2#ok|3#a lot") };
        f1.setFormats(correctFormats);
        Format[] formats = f1.getFormats();
        assertTrue("Test1A:Returned wrong number of formats:", correctFormats.length <= formats.length);
        for (int i = 0; i < correctFormats.length; i++) {
            assertEquals("Test1B:wrong format for argument index " + i + ":", correctFormats[i], formats[i]);
        }
        // case 2: Try to pass null argument to setFormats().
        try {
            f1.setFormats(null);
            fail("Expected exception NullPointerException was not thrown");
        } catch (NullPointerException e) {
        // expected
        }
    } catch (Exception e) {
        fail("Unexpected exception " + e.toString());
    }
}
Also used : Format(java.text.Format) NumberFormat(java.text.NumberFormat) MessageFormat(java.text.MessageFormat) Support_MessageFormat(tests.support.Support_MessageFormat) ChoiceFormat(java.text.ChoiceFormat) DateFormat(java.text.DateFormat) MessageFormat(java.text.MessageFormat) Support_MessageFormat(tests.support.Support_MessageFormat) ChoiceFormat(java.text.ChoiceFormat) ParseException(java.text.ParseException)

Aggregations

ChoiceFormat (java.text.ChoiceFormat)33 NumberFormat (java.text.NumberFormat)15 MessageFormat (java.text.MessageFormat)11 Format (java.text.Format)10 DateFormat (java.text.DateFormat)9 DecimalFormat (java.text.DecimalFormat)7 SimpleDateFormat (java.text.SimpleDateFormat)7 DutySchedule (org.opennms.netmgt.config.users.DutySchedule)4 Currency (java.util.Currency)3 Locale (java.util.Locale)3 Vector (java.util.Vector)3 HttpSession (javax.servlet.http.HttpSession)3 FieldPosition (java.text.FieldPosition)2 ParseException (java.text.ParseException)2 RequestDispatcher (javax.servlet.RequestDispatcher)2 Support_MessageFormat (tests.support.Support_MessageFormat)2 ParsePosition (java.text.ParsePosition)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 ServletException (javax.servlet.ServletException)1