本文整理匯總了Java中java.util.NavigableSet.contains方法的典型用法代碼示例。如果您正苦於以下問題:Java NavigableSet.contains方法的具體用法?Java NavigableSet.contains怎麽用?Java NavigableSet.contains使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.util.NavigableSet
的用法示例。
在下文中一共展示了NavigableSet.contains方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: checkNonPrime
import java.util.NavigableSet; //導入方法依賴的package包/類
/**
* Verifies whether all {@code BigInteger}s in the tested range for which
* {@code isProbablePrime()} returns {@code false} are <i>not</i>
* prime numbers.
*
* @return true if and only if the test succeeds
*/
private static boolean checkNonPrime(NavigableSet<BigInteger> primes,
int certainty) {
int maxPrime = DEFAULT_UPPER_BOUND;
try {
maxPrime = primes.last().intValueExact();
} catch (ArithmeticException e) {
// ignore it
}
// Create a list of non-prime BigIntegers.
SplittableRandom splitRandom = RandomFactory.getSplittableRandom();
List<BigInteger> nonPrimeBigInts = (splitRandom)
.ints(NUM_NON_PRIMES, 2, maxPrime).mapToObj(BigInteger::valueOf)
.filter(b -> !b.isProbablePrime(certainty)).collect(toList());
// If there are any non-probable primes also in the primes list then fail.
boolean failed = nonPrimeBigInts.stream().anyMatch(primes::contains);
// In the event, print which purported non-primes were actually prime.
if (failed) {
for (BigInteger bigInt : nonPrimeBigInts) {
if (primes.contains(bigInt)) {
System.err.println("Prime value thought to be non-prime: " + bigInt);
}
}
}
return !failed;
}