项目:incubator-netbeans
文件:DiffSidebar.java
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
}
}
项目:openjdk-jdk10
文件:Bug4185732Test.java
/**
* 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);
}
}
项目:openjdk-jdk10
文件:Bug4387255.java
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);
}
}
}
项目:openjdk-jdk10
文件:Bug4185816Test.java
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);
}
}
项目:openjdk9
文件:Bug4185732Test.java
/**
* 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,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);
}
}
项目:openjdk9
文件:Bug4387255.java
public static void main(String[] args) throws Exception {
ChoiceFormat choiceFormat1 = new ChoiceFormat(doubles,got " + result);
}
}
}
项目:openjdk9
文件:Bug4185816Test.java
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,see below
out.writeObject(fmt);
out.close();
} catch (Exception e) {
System.out.println(e);
}
}
项目:j2objc
文件:ChoiceFormatTest.java
/**
* @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",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",pos.getIndex());
}
项目:j2objc
文件:ChoiceFormatTest.java
/**
* @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));
}
项目:astor
文件:ExtendedmessageformatTest.java
/**
* 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++) {
checkBuilt@R_939_4045@(values[i] + ": " + choicePattern,new Object[] {values[i]},availableLocales);
}
choicePattern = "{0,1#''One''|2#\"Two\"|3#''{Many}'' {0,availableLocales);
}
}
项目:ph-commons
文件:LocaleParserTest.java
@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,(DecimalFormat) NumberFormat.getInstance (L_EN)));
assertEquals (new BigDecimal ("1234567.8901"),LocaleParser.parseBigDecimal ("1.234.567,8901",CGlobal.BIGDEC_MINUS_ONE));
assertEquals (CGlobal.BIGDEC_MINUS_ONE,LocaleParser.parseBigDecimal ("... und denken",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)
{}
}
项目:cn1
文件:NumberFormatTest.java
/**
* @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) {
}
}
项目:cn1
文件:NumberFormatTest.java
/**
* @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) {
}
}
项目:cn1
文件:ChoiceFormatTest.java
/**
* @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",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",pos.getIndex());
pos = new ParsePosition(0);
assertTrue("Incorrect result",pos)
.doubleValue()));
assertEquals("Wrong position ~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",0.0D);
assertEquals("Wrong position ~5",pos.getIndex());
}
项目:cn1
文件:ChoiceFormatTest.java
/**
* @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.POSITIVE_INFINITY));
}
项目:cron-utils
文件:TimeDescriptor.java
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;
}
项目:icepdf
文件:SearchPanel.java
/**
* 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,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;
}
项目:icepdf
文件:SearchPanel.java
/**
* 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,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;
}
项目:translations
文件:ImplementMethodsAdapter.java
/**
* Count the maximum fields that are used in a message format
* note that a ChoiceFormat can have sub-formats: {0,0#{1}|1#{2}}
* has three parameters,yet the basic messageformat.getFormatsByArgumentIndex().length
* call will have the value of one. This is because the sub-formats are
* handled in a recursive way. Since this is the case,this method needs
* to do something similar to count the fields used.
* @param messageformat message format instance to count the maximum field number used.
* @return the maximum number of fields used in
*/
private int countFields(messageformat messageformat) {
Format[] formats = messageformat.getFormatsByArgumentIndex();
int count = messageformat.getFormatsByArgumentIndex().length;
for (Format ff : formats) {
if (ff instanceof ChoiceFormat) {
ChoiceFormat cf = (ChoiceFormat) ff;
for (Object o : cf.getFormats()) {
// gets a list of the format choice values. the "foo" and "bar" parts of {0,0#foo|1#bar}
if (o != null) {
messageformat subFormat = new messageformat(o.toString());
count = Math.max(count,countFields(subFormat));
}
}
}
}
return count;
}
项目:freeVM
文件:NumberFormatTest.java
/**
* @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",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) {
}
}
项目:freeVM
文件:NumberFormatTest.java
/**
* @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",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) {
}
}
项目:freeVM
文件:ChoiceFormatTest.java
/**
* @tests java.text.ChoiceFormat#parse(java.lang.String,pos.getIndex());
}
项目:freeVM
文件:ChoiceFormatTest.java
/**
* @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.POSITIVE_INFINITY));
}
项目:freeVM
文件:ChoiceFormatTest.java
public int test() {
try {
String pattern = "-1#is negative| 0#is zero or fraction | 1#is one "
+ "|1.0<is 1+ |2#is two |2<is more than 2.";
ChoiceFormat f1 = new ChoiceFormat(pattern);
testFormat(f1,pattern);
ChoiceFormat f2 = new ChoiceFormat("");
f2.applyPattern(pattern);
testFormat(f2,pattern);
} catch (Throwable e) {
return fail(e.getMessage());
}
return pass();
}
项目:freeVM
文件:ChoiceFormatTest.java
private void testFormat(ChoiceFormat f,String pattern) throws Throwable {
double[] numbers = { Double.NEGATIVE_INFINITY,-1.0,0.9,1.5,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));
}
项目:spring-cloud-deployer
文件:MavenArtifactResolver.java
/**
* Resolve an artifact and return its location in the local repository. Aether performs the normal
* Maven resolution process ensuring that the latest update is cached to the local repository.
* In addition,if the {@link MavenProperties#resolvePom} flag is <code>true</code>,* the POM is also resolved and cached.
* @param resource the {@link MavenResource} representing the artifact
* @return a {@link FileSystemResource} representing the resolved artifact in the local repository
* @throws IllegalStateException if the artifact does not exist or the resolution fails
*/
Resource resolve(MavenResource resource) {
Assert.notNull(resource,"MavenResource must not be null");
validateCoordinates(resource);
RepositorySystemSession session = newRepositorySystemSession(this.repositorySystem,this.properties.getLocalRepository());
ArtifactResult resolvedArtifact;
try {
List<ArtifactRequest> artifactRequests = new ArrayList<>(2);
if (properties.isResolvePom()) {
artifactRequests.add(new ArtifactRequest(toPomArtifact(resource),this.remoteRepositories,JavaScopes.RUNTIME));
}
artifactRequests.add(new ArtifactRequest(toJarartifact(resource),JavaScopes.RUNTIME));
List<ArtifactResult> results = this.repositorySystem.resolveArtifacts(session,artifactRequests);
resolvedArtifact = results.get(results.size() - 1);
}
catch (ArtifactResolutionException e) {
ChoiceFormat pluralizer = new ChoiceFormat(
new double[] { 0d,1d,ChoiceFormat.nextDouble(1d) },new String[] { "repositories: ","repository: ","repositories: " });
messageformat messageformat = new messageformat(
"Failed to resolve MavenResource: {0}. Configured remote {1}: {2}");
messageformat.setFormat(1,pluralizer);
String repos = properties.getRemoteRepositories().isEmpty()
? "none"
: StringUtils.collectionToDelimitedString(properties.getRemoteRepositories().keySet(),","[","]");
throw new IllegalStateException(
messageformat.format(new Object[] { resource,properties.getRemoteRepositories().size(),repos }),e);
}
return toResource(resolvedArtifact);
}
项目:j2objc
文件:messageformatTest.java
/**
* @tests java.text.messageformat#getFormats()
*/
public void test_getFormats() {
// Test for method java.text.Format []
// java.text.messageformat.getFormats()
// test with repeating formats and max argument index < max offset
Format[] formats = format1.getFormats();
Format[] correctFormats = new Format[] {
NumberFormat.getCurrencyInstance(),DateFormat.getTimeInstance(),NumberFormat.getPercentInstance(),null,new ChoiceFormat("0#off|1#on"),DateFormat.getDateInstance(),};
assertEquals("Test1:Returned wrong number of formats:",correctFormats.length,formats.length);
for (int i = 0; i < correctFormats.length; i++) {
assertEquals("Test1:wrong format for pattern index " + i + ":",correctFormats[i],formats[i]);
}
// test with max argument index > max offset
formats = format2.getFormats();
correctFormats = new Format[] { NumberFormat.getCurrencyInstance(),DateFormat.getDateInstance() };
assertEquals("Test2:Returned wrong number of formats:",formats.length);
for (int i = 0; i < correctFormats.length; i++) {
assertEquals("Test2:wrong format for pattern index " + i + ":",formats[i]);
}
// test with argument number being zero
formats = format3.getFormats();
assertEquals("Test3: Returned wrong number of formats:",formats.length);
}
项目:j2objc
文件:messageformatTest.java
/**
* @tests java.text.messageformat#getFormatsByArgumentIndex()
*/
public void test_getFormatsByArgumentIndex() {
// 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(),NumberFormat.getCurrencyInstance(),null };
assertEquals("Test1:Returned wrong number of formats:",formats.length);
for (int i = 0; i < correctFormats.length; i++) {
assertEquals("Test1:wrong format for argument index " + i + ":",formats[i]);
}
// test with max argument index > max offset
formats = format2.getFormatsByArgumentIndex();
correctFormats = new Format[] { DateFormat.getDateInstance(),DateFormat.getTimeInstance() };
assertEquals("Test2:Returned wrong number of formats:",formats.length);
for (int i = 0; i < correctFormats.length; i++) {
assertEquals("Test2:wrong format for argument index " + i + ":",formats[i]);
}
// test with argument number being zero
formats = format3.getFormatsByArgumentIndex();
assertEquals("Test3: Returned wrong number of formats:",formats.length);
}
项目:j2objc
文件:ChoiceFormatTest.java
/**
* @tests java.text.ChoiceFormat#clone()
*/
public void test_clone() {
// Test for method java.lang.Object java.text.ChoiceFormat.clone()
ChoiceFormat f = (ChoiceFormat) f1.clone();
assertTrue("Not equal",f.equals(f1));
f.setChoices(new double[] { 0,2 },new String[] { "0","1","2" });
assertTrue("Equal",!f.equals(f1));
}
项目:j2objc
文件:ChoiceFormatTest.java
/**
* @tests java.text.ChoiceFormat#equals(java.lang.Object)
*/
public void test_equalsLjava_lang_Object() {
// Test for method boolean
// java.text.ChoiceFormat.equals(java.lang.Object)
String patternString = "-2#Inverted Orange| 0#No Orange| 0<Almost No Orange| 1#normal Orange| 2#Expensive Orange";
double[] appleLimits = { 1,5 };
String[] appleFormats = { "Tiny Apple","Small Apple","Medium Apple","Large Apple","Huge Apple" };
double[] orangeLimits = { -2,ChoiceFormat.nextDouble(0),2 };
String[] orangeFormats = { "Inverted Orange","No Orange","Almost No Orange","normal Orange","Expensive Orange" };
ChoiceFormat appleChoiceFormat = new ChoiceFormat(appleLimits,appleFormats);
ChoiceFormat orangeChoiceFormat = new ChoiceFormat(orangeLimits,orangeFormats);
ChoiceFormat orangeChoiceFormat2 = new ChoiceFormat(patternString);
ChoiceFormat hybridChoiceFormat = new ChoiceFormat(appleLimits,orangeFormats);
assertTrue("Apples should not equal oranges",!appleChoiceFormat
.equals(orangeChoiceFormat));
assertTrue("Different limit list--should not appear as equal",!orangeChoiceFormat.equals(hybridChoiceFormat));
assertTrue("Different format list--should not appear as equal",!appleChoiceFormat.equals(hybridChoiceFormat));
assertTrue("Should be equal--identical format",appleChoiceFormat
.equals(appleChoiceFormat));
assertTrue("Should be equals--same limits,same formats",orangeChoiceFormat.equals(orangeChoiceFormat2));
ChoiceFormat f2 = new ChoiceFormat(
"0#Less than one|1#one|1<Between one and two|2<Greater than two");
assertTrue("Not equal",f1.equals(f2));
}
项目:j2objc
文件:ChoiceFormatTest.java
/**
* @tests java.text.ChoiceFormat#format(double,java.lang.StringBuffer,* java.text.FieldPosition)
*/
public void test_formatDLjava_lang_StringBufferLjava_text_FieldPosition() {
// Test for method java.lang.StringBuffer
// java.text.ChoiceFormat.format(double,// java.text.FieldPosition)
FieldPosition field = new FieldPosition(0);
StringBuffer buf = new StringBuffer();
String r = f1.format(-1,buf,field).toString();
assertEquals("Wrong choice for -1","Less than one",r);
buf.setLength(0);
r = f1.format(0,field).toString();
assertEquals("Wrong choice for 0",r);
buf.setLength(0);
r = f1.format(1,field).toString();
assertEquals("Wrong choice for 1","one",r);
buf.setLength(0);
r = f1.format(2,field).toString();
assertEquals("Wrong choice for 2","Between one and two",r);
buf.setLength(0);
r = f1.format(3,field).toString();
assertEquals("Wrong choice for 3","Greater than two",r);
// Regression test for HARMONY-1081
assertEquals(0,new ChoiceFormat("|").format(Double.NaN,new StringBuffer(),new FieldPosition(6)).length());
assertEquals(0,new ChoiceFormat("|").format(1,new FieldPosition(6)).length());
assertEquals("Less than one",f1.format(Double.NaN,field).toString());
}
项目:j2objc
文件:ChoiceFormatTest.java
/**
* @tests java.text.ChoiceFormat#hashCode()
*/
public void test_hashCode() {
// Test for method int java.text.ChoiceFormat.hashCode()
ChoiceFormat f2 = new ChoiceFormat(
"0#Less than one|1#one|1<Between one and two|2<Greater than two");
assertTrue("Different hash",f1.hashCode() == f2.hashCode());
}
项目:j2objc
文件:ChoiceFormatTest.java
/**
* @tests java.text.ChoiceFormat#nextDouble(double)
*/
public void test_nextDoubleD() {
// Test for method double java.text.ChoiceFormat.nextDouble(double)
assertTrue("Not greater 5",ChoiceFormat.nextDouble(5) > 5);
assertTrue("Not greater 0",ChoiceFormat.nextDouble(0) > 0);
assertTrue("Not greater -5",ChoiceFormat.nextDouble(-5) > -5);
assertTrue("Not NaN",Double.isNaN(ChoiceFormat.nextDouble(Double.NaN)));
}
项目:j2objc
文件:ChoiceFormatTest.java
/**
* @tests java.text.ChoiceFormat#nextDouble(double,boolean)
*/
public void test_nextDoubleDZ() {
// Test for method double java.text.ChoiceFormat.nextDouble(double,// boolean)
assertTrue("Not greater 0",ChoiceFormat.nextDouble(0,true) > 0);
assertTrue("Not less 0",false) < 0);
}
项目:j2objc
文件:ChoiceFormatTest.java
/**
* @tests java.text.ChoiceFormat#prevIoUsDouble(double)
*/
public void test_prevIoUsDoubleD() {
// Test for method double java.text.ChoiceFormat.prevIoUsDouble(double)
assertTrue("Not less 5",ChoiceFormat.prevIoUsDouble(5) < 5);
assertTrue("Not less 0",ChoiceFormat.prevIoUsDouble(0) < 0);
assertTrue("Not less -5",ChoiceFormat.prevIoUsDouble(-5) < -5);
assertTrue("Not NaN",Double.isNaN(ChoiceFormat
.prevIoUsDouble(Double.NaN)));
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。