当前位置: 首页>>代码示例>>Java>>正文


Java ChoiceFormat类代码示例

本文整理汇总了Java中java.text.ChoiceFormat的典型用法代码示例。如果您正苦于以下问题:Java ChoiceFormat类的具体用法?Java ChoiceFormat怎么用?Java ChoiceFormat使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ChoiceFormat类属于java.text包,在下文中一共展示了ChoiceFormat类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getShortDescription

import java.text.ChoiceFormat; //导入依赖的package包/类
static String getShortDescription(Difference diff) {
    if (diff == null) {
        return null;
    }
    int n;
    switch (diff.getType()) {
        case Difference.ADD:
            n = diff.getSecondEnd() - diff.getSecondStart() + 1;
            return MessageFormat.format(new ChoiceFormat(NbBundle.getMessage(DiffSidebar.class, "TT_LinesAdded")).format(n), n); // NOI18N      
        case Difference.CHANGE:
            n = diff.getFirstEnd() - diff.getFirstStart() + 1;
            return MessageFormat.format(new ChoiceFormat(NbBundle.getMessage(DiffSidebar.class, "TT_LinesChanged")).format(n), n); // NOI18N      
        case Difference.DELETE:
            n = diff.getFirstEnd() - diff.getFirstStart() + 1;
            return MessageFormat.format(new ChoiceFormat(NbBundle.getMessage(DiffSidebar.class, "TT_LinesDeleted")).format(n), n); // NOI18N      
        default:
            throw new IllegalStateException("Unknown difference type: " + diff.getType()); // NOI18N
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:20,代码来源:DiffSidebar.java

示例2: prepTest

import java.text.ChoiceFormat; //导入依赖的package包/类
/**
 * Create a data file for this test.  The data file must be corrupted by hand.
 */
private static void prepTest() {
    try {
        ObjectOutputStream out = new ObjectOutputStream(
                new FileOutputStream("Bug4185732.ser"));
        final double[] limits = {1,2,3,4,5,6,7};
        final String[] formats = {"Sun","Mon","Tue","Wed","Thur","Fri","Sat"};
        final ChoiceFormat fmt = new ChoiceFormat(limits, formats);
        out.writeObject(fmt);
        out.close();
        System.out.println("You must invalidate the output file before running the test");
        System.out.println("by modifying the length of one of the array");
    } catch (Exception e) {
        System.out.println(e);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:19,代码来源:Bug4185732Test.java

示例3: main

import java.text.ChoiceFormat; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
    ChoiceFormat choiceFormat1 = new ChoiceFormat(doubles, strings);
    ChoiceFormat choiceFormat2 = new ChoiceFormat(pattern);
    if (!choiceFormat1.equals(choiceFormat2)) {
        System.out.println("choiceFormat1: " + choiceFormat1.toPattern());
        System.out.println("choiceFormat2: " + choiceFormat2.toPattern());
        throw new RuntimeException();
    }

    for (int i = 0; i < doubles.length; i++) {
        String result = choiceFormat2.format(doubles[i]);
        if (!result.equals(strings[i])) {
            throw new RuntimeException("Wrong format result - expected " +
                    strings[i] + ", got " + result);
        }
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:18,代码来源:Bug4387255.java

示例4: writeFormatToFile

import java.text.ChoiceFormat; //导入依赖的package包/类
private static void writeFormatToFile(final String name) {
    try {
        ObjectOutputStream out = new ObjectOutputStream(
                new FileOutputStream(name));

        MessageFormat fmt = 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);
        fmt.setFormat(1,fileform); // NOT zero, see below

        out.writeObject(fmt);
        out.close();
    } catch (Exception e) {
        System.out.println(e);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:18,代码来源:Bug4185816Test.java

示例5: test_parseLjava_lang_StringLjava_text_ParsePosition

import java.text.ChoiceFormat; //导入依赖的package包/类
/**
 * @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");
    assertTrue("Case insensitive", Double.isNaN(format
            .parse("One", new ParsePosition(0)).doubleValue()));

    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());
}
 
开发者ID:Sellegit,项目名称:j2objc,代码行数:29,代码来源:ChoiceFormatTest.java

示例6: test_formatD

import java.text.ChoiceFormat; //导入依赖的package包/类
/**
 * @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));
}
 
开发者ID:Sellegit,项目名称:j2objc,代码行数:19,代码来源:ChoiceFormatTest.java

示例7: testBuiltInChoiceFormat

import java.text.ChoiceFormat; //导入依赖的package包/类
/**
 * Test the built in choice format.
 */
public void testBuiltInChoiceFormat() {
    Object[] values = new Number[] {new Integer(1), new Double("2.2"), new Double("1234.5")};
    String choicePattern = null;
    Locale[] availableLocales = ChoiceFormat.getAvailableLocales();

    choicePattern = "{0,choice,1#One|2#Two|3#Many {0,number}}";
    for (int i = 0; i < values.length; i++) {
        checkBuiltInFormat(values[i] + ": " + choicePattern, new Object[] {values[i]}, availableLocales);
    }

    choicePattern = "{0,choice,1#''One''|2#\"Two\"|3#''{Many}'' {0,number}}";
    for (int i = 0; i < values.length; i++) {
        checkBuiltInFormat(values[i] + ": " + choicePattern, new Object[] {values[i]}, availableLocales);
    }
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:19,代码来源:ExtendedMessageFormatTest.java

示例8: testParseBigDecimal

import java.text.ChoiceFormat; //导入依赖的package包/类
@Test
public void testParseBigDecimal ()
{
  final BigDecimal aBD1M = StringParser.parseBigDecimal ("1000000");
  assertEquals (aBD1M, LocaleParser.parseBigDecimal ("1.000.000", L_DE, CGlobal.BIGDEC_MINUS_ONE));
  assertEquals (aBD1M, LocaleParser.parseBigDecimal ("1,000,000", L_EN, CGlobal.BIGDEC_MINUS_ONE));
  assertEquals (aBD1M, LocaleParser.parseBigDecimal ("1,000,000", (DecimalFormat) NumberFormat.getInstance (L_EN)));
  assertEquals (new BigDecimal ("1234567.8901"),
                LocaleParser.parseBigDecimal ("1.234.567,8901", L_DE, CGlobal.BIGDEC_MINUS_ONE));
  assertEquals (CGlobal.BIGDEC_MINUS_ONE,
                LocaleParser.parseBigDecimal ("... und denken", L_EN, CGlobal.BIGDEC_MINUS_ONE));
  final ChoiceFormat aCF = new ChoiceFormat ("-1#negative|0#zero|1.0#one");
  assertEquals (BigDecimal.valueOf (0.0), LocaleParser.parseBigDecimal ("zero", aCF, CGlobal.BIGDEC_MINUS_ONE));

  try
  {
    LocaleParser.parseBigDecimal ("0", (DecimalFormat) null);
    fail ();
  }
  catch (final NullPointerException ex)
  {}
}
 
开发者ID:phax,项目名称:ph-commons,代码行数:23,代码来源:LocaleParserTest.java

示例9: test_getCurrency

import java.text.ChoiceFormat; //导入依赖的package包/类
/**
 * @tests java.text.NumberFormat#getCurrency()
 */
public void test_getCurrency() {
    // Test for method java.util.Currency getCurrency()

    // a subclass that supports currency formatting
    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) {
    }
}
 
开发者ID:shannah,项目名称:cn1,代码行数:21,代码来源:NumberFormatTest.java

示例10: test_setCurrencyLjava_util_Currency

import java.text.ChoiceFormat; //导入依赖的package包/类
/**
 * @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) {
    }
}
 
开发者ID:shannah,项目名称:cn1,代码行数:21,代码来源:NumberFormatTest.java

示例11: test_parseLjava_lang_StringLjava_text_ParsePosition

import java.text.ChoiceFormat; //导入依赖的package包/类
/**
   * @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());
  }
 
开发者ID:shannah,项目名称:cn1,代码行数:29,代码来源:ChoiceFormatTest.java

示例12: test_formatD

import java.text.ChoiceFormat; //导入依赖的package包/类
/**
 * @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));
}
 
开发者ID:shannah,项目名称:cn1,代码行数:19,代码来源:ChoiceFormatTest.java

示例13: describeEverySecond

import java.text.ChoiceFormat; //导入依赖的package包/类
private String describeEverySecond(final int second) {
    final double[] secondsLimit = {1, 2};
    final String[] secondsStrings = {
            resourceBundle.getString("oneSecond"),
            resourceBundle.getString("multipleSeconds")
    };
    final double[] everyLimit = {1,2};
    final String[] everyStrings = {
            resourceBundle.getString("every_one"),
            resourceBundle.getString("every_multi")
    };

    final ChoiceFormat secondsChoiceFormat = new ChoiceFormat(secondsLimit, secondsStrings);
    final ChoiceFormat everyChoiceFormat = new ChoiceFormat(everyLimit, everyStrings);
    final String pattern = resourceBundle.getString("pattern_every_seconds");

    final MessageFormat messageFormat = new MessageFormat(pattern, Locale.UK);

    final Format[] formats = { everyChoiceFormat, secondsChoiceFormat, NumberFormat.getInstance() };
    messageFormat.setFormats(formats);
    final Object[] messageArguments = {second, second, second };
    final String result = messageFormat.format(messageArguments);
    return result;
}
 
开发者ID:jmrozanec,项目名称:cron-utils,代码行数:25,代码来源:TimeDescriptor.java

示例14: setupSearchResultMessageForm

import java.text.ChoiceFormat; //导入依赖的package包/类
/**
 * Uitility for createing the searchable dialog message format.
 *
 * @return reuseable message format.
 */
public MessageFormat setupSearchResultMessageForm() {
    MessageFormat messageForm =
            new MessageFormat(messageBundle.getString(
                    "viewer.utilityPane.search.result.msg"));
    double[] pageLimits = {0, 1, 2};
    String[] resultsStrings = {
            messageBundle.getString(
                    "viewer.utilityPane.search.result.moreFile.msg"),
            messageBundle.getString(
                    "viewer.utilityPane.search.result.oneFile.msg"),
            messageBundle.getString(
                    "viewer.utilityPane.search.result.moreFile.msg")
    };
    ChoiceFormat resultsChoiceForm = new ChoiceFormat(pageLimits,
            resultsStrings);

    Format[] formats = {null, resultsChoiceForm};
    messageForm.setFormats(formats);
    return messageForm;
}
 
开发者ID:pdf4j,项目名称:icepdf,代码行数:26,代码来源:SearchPanel.java

示例15: setupSearchingMessageForm

import java.text.ChoiceFormat; //导入依赖的package包/类
/**
 * Uitility for createing the searching message format.
 *
 * @return reuseable message format.
 */
public MessageFormat setupSearchingMessageForm() {
    // Build Internationalized plural phrase.
    MessageFormat messageForm =
            new MessageFormat(messageBundle.getString(
                    "viewer.utilityPane.search.searching1.msg"));
    double[] fileLimits = {0, 1, 2};
    String[] fileStrings = {
            messageBundle.getString(
                    "viewer.utilityPane.search.searching1.moreFile.msg"),
            messageBundle.getString(
                    "viewer.utilityPane.search.searching1.oneFile.msg"),
            messageBundle.getString(
                    "viewer.utilityPane.search.searching1.moreFile.msg"),
    };
    ChoiceFormat choiceForm = new ChoiceFormat(fileLimits,
            fileStrings);
    Format[] formats = {null, choiceForm, null};
    messageForm.setFormats(formats);

    return messageForm;
}
 
开发者ID:pdf4j,项目名称:icepdf,代码行数:27,代码来源:SearchPanel.java


注:本文中的java.text.ChoiceFormat类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。