Package java.text

Examples of java.text.ChoiceFormat


   */
  public void test_setRoundingMode_NullRoundingMode() {
    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(null);
      // Follow the behavior of RI
      fail("UnsupportedOperationException expected");
    } catch (UnsupportedOperationException e) {
View Full Code Here


   */
  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
View Full Code Here

  @Test
  public void test() {
    MessageFormat form = new MessageFormat("The disk \"{1}\" contains {0}.");
     double[] filelimits = {0,1,2};
     String[] filepart = {"no files","one file","{0,number} files"};
     ChoiceFormat fileform = new ChoiceFormat(filelimits, filepart);
     form.setFormatByArgumentIndex(0, fileform);

     int fileCount = 1273;
     String diskName = "MyDisk";
     Object[] testArgs = {new Long(fileCount), diskName};
View Full Code Here

              if (!doFormat) {
                // 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 affixes, in order to set up a
View Full Code Here

        MessageFormat fmt = new MessageFormat("");
        fmt.setLocale(Locale.getDefault());
        double[] limits = {1, 2};
        String[] keys = {RESOURCE_BUNDLE.getString("compile.errors.one"),
                RESOURCE_BUNDLE.getString("compile.errors.several")};
        ChoiceFormat choice = new ChoiceFormat(limits, keys);
        fmt.applyPattern(RESOURCE_BUNDLE.getString("compile.errors.pattern"));
        Format[] formats = {choice, NumberFormat.getInstance()};
        fmt.setFormats(formats);
        return fmt.format(new Object[]{numErrors});
    }
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

                                    Currency.SYMBOL_NAME,
                                    isChoiceFormat);
            // If this is a ChoiceFormat currency, then format an
            // arbitrary value; pick something != 1; more common.
            currencySymbol = isChoiceFormat[0]
                ? new ChoiceFormat(currname).format(2.0)
                : currname;
        } else {
            intlCurrencySymbol = "XXX";
            currencySymbol = "\u00A4"; // 'OX' currency symbol
        }
View Full Code Here

public class ChoiceFormatCreator implements Creator
{
  public Object create (String parentNS, String parentTag, Element elm, Object parentObj, DecodeEngine decodeEngine)
  {
    decodeEngine.setDoAdd (false);
    return new ChoiceFormat ("dummy choice");
  }
View Full Code Here

     * Returns a message indicating the number of files generated, for logging.
     */
    private String generatedFilesMessage(List<File> generated) {
        double[] limits = {0, 1, 2};
        String[] files = {"No files", "1 file", "{0,number} files"};
        ChoiceFormat choice = new ChoiceFormat(limits, files);
        MessageFormat format = new MessageFormat("{0} generated.");
        format.setFormatByArgumentIndex(0, choice);
        return format.format(new Object[]{generated.size()});
    }
View Full Code Here

                break;
            }
            break;
        case TYPE_CHOICE:
            try {
                newFormat = new ChoiceFormat(segments[3].toString());
            } catch (Exception e) {
                maxOffset = oldMaxOffset;
                throw new IllegalArgumentException("Choice Pattern incorrect");
            }
            break;
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.