本文整理匯總了Java中com.google.common.math.IntMath.saturatedMultiply方法的典型用法代碼示例。如果您正苦於以下問題:Java IntMath.saturatedMultiply方法的具體用法?Java IntMath.saturatedMultiply怎麽用?Java IntMath.saturatedMultiply使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.google.common.math.IntMath
的用法示例。
在下文中一共展示了IntMath.saturatedMultiply方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: calculateSize
import com.google.common.math.IntMath; //導入方法依賴的package包/類
/**
* The number of permutations with repeated elements is calculated as follows:
*
* <ul>
* <li>For an empty list, it is 1 (base case).
* <li>When r numbers are added to a list of n-r elements, the number of permutations is
* increased by a factor of (n choose r).
* </ul>
*/
private static <E> int calculateSize(
List<E> sortedInputList, Comparator<? super E> comparator) {
int permutations = 1;
int n = 1;
int r = 1;
while (n < sortedInputList.size()) {
int comparison = comparator.compare(sortedInputList.get(n - 1), sortedInputList.get(n));
if (comparison < 0) {
// We move to the next non-repeated element.
permutations = IntMath.saturatedMultiply(permutations, IntMath.binomial(n, r));
r = 0;
if (permutations == Integer.MAX_VALUE) {
return Integer.MAX_VALUE;
}
}
n++;
r++;
}
return IntMath.saturatedMultiply(permutations, IntMath.binomial(n, r));
}