本文整理汇总了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));
}