Search in sources :

Example 6 with ChoiceFormat

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

the class ChoiceFormatTest method test_hashCode.

/**
     * @tests java.text.ChoiceFormat#hashCode()
     */
public void test_hashCode() {
    // Test for method int java.text.ChoiceFormat.hashCode()
    ChoiceFormat f2 = new ChoiceFormat("0#Less than one|1#one|1<Between one and two|2<Greater than two");
    assertTrue("Different hash", f1.hashCode() == f2.hashCode());
}
Also used : ChoiceFormat(java.text.ChoiceFormat)

Example 7 with ChoiceFormat

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

the class ChoiceFormatTest method test_clone.

/**
     * @tests java.text.ChoiceFormat#clone()
     */
public void test_clone() {
    // Test for method java.lang.Object java.text.ChoiceFormat.clone()
    ChoiceFormat f = (ChoiceFormat) f1.clone();
    assertTrue("Not equal", f.equals(f1));
    f.setChoices(new double[] { 0, 1, 2 }, new String[] { "0", "1", "2" });
    assertTrue("Equal", !f.equals(f1));
}
Also used : ChoiceFormat(java.text.ChoiceFormat)

Example 8 with ChoiceFormat

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

the class ChoiceFormatTest method test_equalsLjava_lang_Object.

/**
     * @tests java.text.ChoiceFormat#equals(java.lang.Object)
     */
public void test_equalsLjava_lang_Object() {
    // Test for method boolean
    // java.text.ChoiceFormat.equals(java.lang.Object)
    String patternString = "-2#Inverted Orange| 0#No Orange| 0<Almost No Orange| 1#Normal Orange| 2#Expensive Orange";
    double[] appleLimits = { 1, 2, 3, 4, 5 };
    String[] appleFormats = { "Tiny Apple", "Small Apple", "Medium Apple", "Large Apple", "Huge Apple" };
    double[] orangeLimits = { -2, 0, ChoiceFormat.nextDouble(0), 1, 2 };
    String[] orangeFormats = { "Inverted Orange", "No Orange", "Almost No Orange", "Normal Orange", "Expensive Orange" };
    ChoiceFormat appleChoiceFormat = new ChoiceFormat(appleLimits, appleFormats);
    ChoiceFormat orangeChoiceFormat = new ChoiceFormat(orangeLimits, orangeFormats);
    ChoiceFormat orangeChoiceFormat2 = new ChoiceFormat(patternString);
    ChoiceFormat hybridChoiceFormat = new ChoiceFormat(appleLimits, orangeFormats);
    assertTrue("Apples should not equal oranges", !appleChoiceFormat.equals(orangeChoiceFormat));
    assertTrue("Different limit list--should not appear as equal", !orangeChoiceFormat.equals(hybridChoiceFormat));
    assertTrue("Different format list--should not appear as equal", !appleChoiceFormat.equals(hybridChoiceFormat));
    assertTrue("Should be equal--identical format", appleChoiceFormat.equals(appleChoiceFormat));
    assertTrue("Should be equals--same limits, same formats", orangeChoiceFormat.equals(orangeChoiceFormat2));
    ChoiceFormat f2 = new ChoiceFormat("0#Less than one|1#one|1<Between one and two|2<Greater than two");
    assertTrue("Not equal", f1.equals(f2));
}
Also used : ChoiceFormat(java.text.ChoiceFormat)

Example 9 with ChoiceFormat

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

the class ChoiceFormatTest method test_parseLjava_lang_StringLjava_text_ParsePosition.

/**
     * @tests java.text.ChoiceFormat#parse(java.lang.String,
     *        java.text.ParsePosition)
     */
public void test_parseLjava_lang_StringLjava_text_ParsePosition() {
    // Test for method java.lang.Number
    // java.text.ChoiceFormat.parse(java.lang.String,
    // java.text.ParsePosition)
    ChoiceFormat format = new ChoiceFormat("1#one|2#two|3#three");
    assertEquals("Case insensitive", 0, format.parse("One", new ParsePosition(0)).intValue());
    ParsePosition pos = new ParsePosition(0);
    Number result = f1.parse("Greater than two", pos);
    assertTrue("Not a Double1", result instanceof Double);
    assertTrue("Wrong value ~>2", result.doubleValue() == ChoiceFormat.nextDouble(2));
    assertEquals("Wrong position ~16", 16, pos.getIndex());
    pos = new ParsePosition(0);
    assertTrue("Incorrect result", Double.isNaN(f1.parse("12one", pos).doubleValue()));
    assertEquals("Wrong position ~0", 0, pos.getIndex());
    pos = new ParsePosition(2);
    result = f1.parse("12one and two", pos);
    assertTrue("Not a Double2", result instanceof Double);
    assertEquals("Ignored parse position", 1.0D, result.doubleValue(), 0.0D);
    assertEquals("Wrong position ~5", 5, pos.getIndex());
}
Also used : ChoiceFormat(java.text.ChoiceFormat) ParsePosition(java.text.ParsePosition)

Example 10 with ChoiceFormat

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

the class ChoiceFormatTest method test_toPattern.

/**
	 * @tests java.text.ChoiceFormat#toPattern()
	 */
public void test_toPattern() {
    // Regression for HARMONY-59
    ChoiceFormat cf = new ChoiceFormat("");
    assertEquals("", cf.toPattern());
    cf = new ChoiceFormat("-1#NEGATIVE_ONE|0#ZERO|1#ONE|1<GREATER_THAN_ONE");
    assertEquals("-1.0#NEGATIVE_ONE|0.0#ZERO|1.0#ONE|1.0<GREATER_THAN_ONE", cf.toPattern());
    MessageFormat mf = new MessageFormat("CHOICE {1,choice}");
    String ptrn = mf.toPattern();
    assertEquals("Unused message format returning incorrect pattern", "CHOICE {1,choice,}", ptrn);
    String pattern = f1.toPattern();
    assertTrue("Wrong pattern: " + pattern, pattern.equals("0.0#Less than one|1.0#one|1.0<Between one and two|2.0<Greater than two"));
    cf = new ChoiceFormat("-1#is negative| 0#is zero or fraction | 1#is one |1.0<is 1+|2#is two |2<is more than 2.");
    String str = "org.apache.harmony.tests.java.lang.share.MyResources2";
    cf.applyPattern(str);
    ptrn = cf.toPattern();
    assertEquals("Return value should be empty string for invalid pattern", 0, ptrn.length());
}
Also used : MessageFormat(java.text.MessageFormat) ChoiceFormat(java.text.ChoiceFormat)

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