Package java.text

Examples of java.text.ChoiceFormat


     * @tests java.text.ChoiceFormat#setChoices(double[], java.lang.String[])
     */
    public void test_setChoices$D$Ljava_lang_String() {
        // Test for method void java.text.ChoiceFormat.setChoices(double [],
        // java.lang.String [])
        ChoiceFormat f = (ChoiceFormat) f1.clone();
        double[] l = new double[] { 0, 1 };
        String[] fs = new String[] { "0", "1" };
        f.setChoices(l, fs);
        assertTrue("Limits copied", f.getLimits() == l);
        assertTrue("Formats copied", f.getFormats() == fs);
    }
View Full Code Here


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

  /**
   * @tests java.text.ChoiceFormat#format(long)
   */
  public void test_formatL() {
    ChoiceFormat fmt = new ChoiceFormat(
        "-1#NEGATIVE_ONE|0#ZERO|1#ONE|1<GREATER_THAN_ONE");

    assertEquals("NEGATIVE_ONE", fmt.format(Long.MIN_VALUE));
    assertEquals("NEGATIVE_ONE", fmt.format(-1));
    assertEquals("ZERO", fmt.format(0));
    assertEquals("ONE", fmt.format(1));
    assertEquals("GREATER_THAN_ONE", fmt.format(Long.MAX_VALUE));
  }
View Full Code Here

 
  /**
   * @tests java.text.ChoiceFormat#format(double)
   */
  public void test_formatD() {
    ChoiceFormat fmt = new ChoiceFormat(
        "-1#NEGATIVE_ONE|0#ZERO|1#ONE|1<GREATER_THAN_ONE");
    assertEquals("NEGATIVE_ONE", fmt.format(Double.NEGATIVE_INFINITY));
    assertEquals("NEGATIVE_ONE", fmt.format(-999999999D));
    assertEquals("NEGATIVE_ONE", fmt.format(-1.1));
    assertEquals("NEGATIVE_ONE", fmt.format(-1.0));
    assertEquals("NEGATIVE_ONE", fmt.format(-0.9));
    assertEquals("ZERO", fmt.format(0.0));
    assertEquals("ZERO", fmt.format(0.9));
    assertEquals("ONE", fmt.format(1.0));
    assertEquals("GREATER_THAN_ONE", fmt.format(1.1));
    assertEquals("GREATER_THAN_ONE", fmt.format(999999999D));
    assertEquals("GREATER_THAN_ONE", fmt.format(Double.POSITIVE_INFINITY));
  }
View Full Code Here

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

     */
    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"));

    }
View Full Code Here

        Currency currH = Currency.getInstance("HUF");
        NumberFormat format = NumberFormat.getInstance(new Locale("hu", "HU"));
        assertSame("Returned incorrect currency", currH, 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).getCurrency();
            fail("Expected UnsupportedOperationException");
        } catch (UnsupportedOperationException e) {
View Full Code Here

        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) {
View Full Code Here

                        // when zero-length is used to mean something.
                        continue;
                    } else if (name.charAt(0) == '=') {
                        name = name.substring(1);
                        if (name.length() > 0 && name.charAt(0) != '=') {
                            ChoiceFormat choice = new ChoiceFormat(name);
                            // Number n =
                            choice.parse(text, pos);
                            int len = pos.getIndex() - start;
                            if (len > max) {
                                iso = item.getKey();
                                max = len;
                            }
View Full Code Here

                                // If the currency is handled by a ChoiceFormat,
                                // then we're not going to use the expanded
                                // patterns.  Instantiate the ChoiceFormat and
                                // return.
                                if (currencyChoice == null) {
                                    currencyChoice = new ChoiceFormat(s);
                                }
                                // We could almost return null or "" here, since the
                                // expanded affixes are almost not used at all
                                // in this situation.  However, one method --
                                // toPattern() -- still does use the expanded
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.