本文整理汇总了Java中java.text.ChoiceFormat.format方法的典型用法代码示例。如果您正苦于以下问题:Java ChoiceFormat.format方法的具体用法?Java ChoiceFormat.format怎么用?Java ChoiceFormat.format使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.text.ChoiceFormat
的用法示例。
在下文中一共展示了ChoiceFormat.format方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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);
}
}
}
示例2: testFormat
import java.text.ChoiceFormat; //导入方法依赖的package包/类
private void testFormat(ChoiceFormat f, String pattern) throws Throwable {
double[] numbers = { Double.NEGATIVE_INFINITY, -1.0, 0, 0.9, 1, 1.5, 2,
2.1, Double.POSITIVE_INFINITY};
//Framework fw = new Framework();
String[] values = getValues();
//Object [] values = new Object[numbers.length];
testNextDouble();
for (int i = 0; i < numbers.length; i++) {
String format = f.format(numbers[i]);
if (!values[i].equals(format)) {
throw new Throwable("ChoiceFormat.format(" + numbers[i]
+ ") ==" + format + " != " + values[i] + "\nPattern: '" + pattern + "'");
}
}
//System.out.println(fw
// .generateGetter("values", values, String.class));
}
示例3: ChoiceFormat
import java.text.ChoiceFormat; //导入方法依赖的package包/类
/**
* @tests java.text.ChoiceFormat#ChoiceFormat(double[], java.lang.String[])
*/
public void test_Constructor$D$Ljava_lang_String() {
// Test for method java.text.ChoiceFormat(double [], java.lang.String
// [])
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"));
}
示例4: test_ConstructorLjava_lang_String
import java.text.ChoiceFormat; //导入方法依赖的package包/类
/**
* @tests java.text.ChoiceFormat#ChoiceFormat(java.lang.String)
*/
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"));
}