本文整理汇总了Java中java.text.ChoiceFormat.nextDouble方法的典型用法代码示例。如果您正苦于以下问题:Java ChoiceFormat.nextDouble方法的具体用法?Java ChoiceFormat.nextDouble怎么用?Java ChoiceFormat.nextDouble使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.text.ChoiceFormat
的用法示例。
在下文中一共展示了ChoiceFormat.nextDouble方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: resolve
import java.text.ChoiceFormat; //导入方法依赖的package包/类
/**
* 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),
this.remoteRepositories,
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);
}
示例2: test_equalsLjava_lang_Object
import java.text.ChoiceFormat; //导入方法依赖的package包/类
/**
* @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, 2, 3, 4, 5 };
String[] appleFormats = { "Tiny Apple", "Small Apple", "Medium Apple",
"Large Apple", "Huge Apple" };
double[] orangeLimits = { -2, 0, ChoiceFormat.nextDouble(0), 1, 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));
}
示例3: testNextDouble
import java.text.ChoiceFormat; //导入方法依赖的package包/类
public boolean testNextDouble() throws Throwable {
double[] doubles = { 0, Double.NaN, 1, -1, 1.5, -1.5,
Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY,
Double.MAX_VALUE, Double.MAX_VALUE / 2, Double.MAX_VALUE / -2,
Double.MIN_VALUE, -Double.MAX_VALUE, -Double.MIN_VALUE };
for (int i = 0; i < doubles.length; i++) {
double next = ChoiceFormat.nextDouble(doubles[i]);
double prev = ChoiceFormat.nextDouble(doubles[i], false);
double next2 = ChoiceFormat.nextDouble(doubles[i], true);
if (!"ok".equals(testDoubleAdjacent(doubles[i], next))) {
throw new Throwable("ChoiceFormat.nextDouble(" + doubles[i]
+ ") returns incorrect value (" + next + ")");
}
if (!"ok".equals(testDoubleAdjacent(prev, doubles[i]))) {
throw new Throwable("ChoiceFormat.nextDouble(" + doubles[i]
+ ", false) returns incorrect value (" + prev + ")");
}
if ((!Double.isNaN(next) || !Double.isNaN(next2)) && next != next2) {
throw new Throwable("ChoiceFormat.nextDouble(" + doubles[i]
+ ", true) returns incorrect value\n" + next + "!=" +
next2);
}
}
return true;
}
示例4: requireThatBucketRangesWork
import java.text.ChoiceFormat; //导入方法依赖的package包/类
@Test
public void requireThatBucketRangesWork() {
BucketValue expected = new LongBucket(2, 5);
assertBucketRange(expected, new LongValue(1), false, new LongValue(4), true);
assertBucketRange(expected, new LongValue(1), false, new LongValue(5), false);
assertBucketRange(expected, new LongValue(2), true, new LongValue(4), true);
assertBucketRange(expected, new LongValue(2), true, new LongValue(5), false);
BucketResolver resolver = new BucketResolver();
resolver.push(new LongValue(1), true).push(new LongValue(2), false);
resolver.push(new LongValue(2), true).push(new LongValue(4), true);
resolver.push(new LongValue(4), false).push(new LongValue(5), false);
resolver.push(new LongValue(5), false).push(new LongValue(8), true);
assertBucketOrder(resolver);
expected = new StringBucket("aba ", "bab ");
assertBucketRange(expected, new StringValue("aba"), false, new StringValue("bab"), true);
assertBucketRange(expected, new StringValue("aba"), false, new StringValue("bab "), false);
assertBucketRange(expected, new StringValue("aba "), true, new StringValue("bab"), true);
assertBucketRange(expected, new StringValue("aba "), true, new StringValue("bab "), false);
resolver = new BucketResolver();
resolver.push(new StringValue("aaa"), true).push(new StringValue("aab"), false);
resolver.push(new StringValue("aab"), true).push(new StringValue("aac"), true);
resolver.push(new StringValue("aac"), false).push(new StringValue("aad"), false);
resolver.push(new StringValue("aad"), false).push(new StringValue("aae"), true);
assertBucketOrder(resolver);
RawBuffer r1 = new RawBuffer(new byte[]{0, 1, 3});
RawBuffer r1next = new RawBuffer(new byte[]{0, 1, 3, 0});
RawBuffer r2 = new RawBuffer(new byte[]{0, 2, 2});
RawBuffer r2next = new RawBuffer(new byte[]{0, 2, 2, 0});
RawBuffer r2nextnext = new RawBuffer(new byte[]{0, 2, 2, 0, 4});
expected = new RawBucket(r1next, r2next);
assertBucketRange(expected, new RawValue(r1), false, new RawValue(r2), true);
assertBucketRange(expected, new RawValue(r1), false, new RawValue(r2next), false);
assertBucketRange(expected, new RawValue(r1next), true, new RawValue(r2), true);
assertBucketRange(expected, new RawValue(r1next), true, new RawValue(r2next), false);
resolver = new BucketResolver();
resolver.push(new RawValue(r1), true).push(new RawValue(r1next), false);
resolver.push(new RawValue(r1next), true).push(new RawValue(r2), true);
resolver.push(new RawValue(r2), false).push(new RawValue(r2next), false);
resolver.push(new RawValue(r2next), false).push(new RawValue(r2nextnext), true);
assertBucketOrder(resolver);
double d1next = ChoiceFormat.nextDouble(1.414);
double d2next = ChoiceFormat.nextDouble(3.14159);
double d1 = ChoiceFormat.nextDouble(d1next);
double d2 = ChoiceFormat.nextDouble(d2next);
expected = new DoubleBucket(d1, d2);
assertBucketRange(expected, new DoubleValue(d1next), false, new DoubleValue(d2next), true);
assertBucketRange(expected, new DoubleValue(d1next), false, new DoubleValue(d2), false);
assertBucketRange(expected, new DoubleValue(d1), true, new DoubleValue(d2next), true);
assertBucketRange(expected, new DoubleValue(d1), true, new DoubleValue(d2), false);
resolver = new BucketResolver();
resolver.push(new DoubleValue(d1next), true).push(new DoubleValue(d1), false);
resolver.push(new DoubleValue(d1), true).push(new DoubleValue(d2next), true);
resolver.push(new DoubleValue(d2next), false).push(new DoubleValue(d2), false);
resolver.push(new DoubleValue(d2), false).push(new DoubleValue(ChoiceFormat.nextDouble(d2)), true);
assertBucketOrder(resolver);
}
示例5: nextValue
import java.text.ChoiceFormat; //导入方法依赖的package包/类
/**
* Returns the next distinct value.
*
* @param value The base value.
* @return the next value.
*/
public static DoubleValue nextValue(DoubleValue value) {
return (new DoubleValue(ChoiceFormat.nextDouble(value.getValue())));
}