Package java.text

Examples of java.text.ChoiceFormat


        // Test for method java.text.Format [] test_getFormatsByArgumentIndex()

        // test with repeating formats and max argument index < max offset
        Format[] formats = format1.getFormatsByArgumentIndex();
        Format[] correctFormats = new Format[] { DateFormat.getDateInstance(),
                new ChoiceFormat("0#off|1#on"), DateFormat.getTimeInstance(),
                NumberFormat.getCurrencyInstance(), null };

        assertEquals("Test1:Returned wrong number of formats:",
                correctFormats.length, formats.length);
        for (int i = 0; i < correctFormats.length; i++) {
            assertEquals("Test1:wrong format for argument index " + i + ":",
                    correctFormats[i], formats[i]);
        }

        // test with max argument index > max offset
        formats = format2.getFormatsByArgumentIndex();
        correctFormats = new Format[] { DateFormat.getDateInstance(),
                new ChoiceFormat("0#off|1#on"), null,
                NumberFormat.getCurrencyInstance(), null, null, null, null,
                DateFormat.getTimeInstance() };

        assertEquals("Test2:Returned wrong number of formats:",
                correctFormats.length, formats.length);
View Full Code Here


     */
    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 + ":",
View Full Code Here

        // test with repeating formats and max argument index < max offset
        // compare getFormatsByArgumentIndex() results after calls to
        // setFormatsByArgumentIndex(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.setFormatsByArgumentIndex(correctFormats);
        Format[] formats = f1.getFormatsByArgumentIndex();

        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();
        Format[] inputFormats = new Format[] { DateFormat.getDateInstance(),
                new ChoiceFormat("0#off|1#on"),
                NumberFormat.getPercentInstance(),
                NumberFormat.getCurrencyInstance(),
                DateFormat.getTimeInstance(), null, null, null,
                DateFormat.getTimeInstance() };
        f2.setFormatsByArgumentIndex(inputFormats);

        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 = new Format[] { NumberFormat.getCurrencyInstance(),
                DateFormat.getTimeInstance(), DateFormat.getDateInstance(),
                null, new ChoiceFormat("0#off|1#on"),
                DateFormat.getDateInstance() };

        assertEquals("Test2C:Returned wrong number of formats:",
                correctFormats.length, formats.length);
        for (int i = 0; i < correctFormats.length; i++) {
View Full Code Here

    harness.checkPoint("choice");
   
    try
    {
      s = MessageFormat.format("{0,choice,0#zero|1#one|1>many}", new Object[]{new Double(2.0)});
      expected = new ChoiceFormat("0#zero|1#one|1>many").format(new Double(2.0));
      harness.check(s, expected);
    }
    catch (Exception e)
    {
      harness.debug(e);
View Full Code Here

  public void test (TestHarness harness)
    {
      StringBuffer buf = new StringBuffer ();

      ChoiceFormat cf = new ChoiceFormat ("1.0#Sun|2.0#Mon|3.0#Tue|4.0#Wed|5.0#Thu|6.0#Fri|7.0#Sat");
      harness.check (cf.getFormats ().length, 7);
      harness.check (cf.getLimits ().length, 7);
      harness.check (doformat (cf, -9, buf), "Sun");
      harness.check (doformat (cf, 1.5, buf), "Sun");
      harness.check (doformat (cf, 5.5, buf), "Thu");
      harness.check (doformat (cf, 7.0, buf), "Sat");
      harness.check (doformat (cf, 99.5, buf), "Sat");

      cf.applyPattern ("-1.0#Less than one|1.0#One|1.0<One to two, exclusive|2.0#Two to three, inclusive|3.0<Over three, up to four|4.0<Four to five, exclusive|5.0#Five and above");
      harness.check (doformat (cf, -23, buf), "Less than one");
      harness.check (doformat (cf, -.5, buf), "Less than one");
      harness.check (doformat (cf, ChoiceFormat.previousDouble (1.0), buf),
         "Less than one");
      harness.check (doformat (cf, 1.0, buf), "One");
View Full Code Here

public class parse implements Testlet
{
  public void test (TestHarness harness)
    {
      ChoiceFormat cf = new ChoiceFormat ("1.0#Sun|2.0#Mon|3.0#Tue|4.0#Wed|5.0#Thu|6.0#Fri|7.0#Sat");
      ParsePosition pp = new ParsePosition (0);

      Number n = cf.parse ("Wed", pp);
      harness.check (n instanceof Double);
      harness.check (n.doubleValue (), 4.0);
      harness.check (pp.getIndex (), 3);

      pp.setIndex (3);
      n = cf.parse ("ZooMon", pp);
      harness.check (n.doubleValue (), 2.0);
      harness.check (pp.getIndex (), 6);

      pp.setIndex (0);
      n = cf.parse ("Saturday", pp);
      harness.check (n.doubleValue (), 7.0);
      harness.check (pp.getIndex (), 3);

      n = cf.parse ("Saturday", pp);
      harness.check (Double.isNaN (n.doubleValue ()));
      harness.check (pp.getIndex (), 3);
    }
View Full Code Here

    {
      throw new NullPointerException();
    }
    this.pattern = pattern;
    this.locale = locale;
    this.choiceFormat = new ChoiceFormat(pattern);
  }
View Full Code Here

        sym.setDecimalSeparator('.');
        df.setDecimalFormatSymbols(sym);
        FORMAT_ALT = df;
       
        final double[] posneg = new double[]{Double.NEGATIVE_INFINITY, 0};
        FORMAT_LAT_REF = new ChoiceFormat(posneg, new String[]{"S", "N"});
        FORMAT_LON_REF = new ChoiceFormat(posneg, new String[]{"W", "E"});
    }
View Full Code Here

            };
            double[] choiceLimits = { 1, 2 };
           
            MessageFormat fmt = new MessageFormat("");
            fmt.setLocale( Preferences.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

            };
            double[] choiceLimits = { 1, 2 };
           
            MessageFormat fmt = new MessageFormat("");
            fmt.setLocale( Preferences.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

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.