本文整理汇总了Java中com.google.common.math.IntMath.checkedPow方法的典型用法代码示例。如果您正苦于以下问题:Java IntMath.checkedPow方法的具体用法?Java IntMath.checkedPow怎么用?Java IntMath.checkedPow使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.common.math.IntMath
的用法示例。
在下文中一共展示了IntMath.checkedPow方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: generateCode
import com.google.common.math.IntMath; //导入方法依赖的package包/类
/**
* <b>NOTE</b>: The generated code is not guaranteed to be unique. You should validate it with other generated
* codes where uniqueness is required before using it.
* @param requiredCodeLength
* @return A random sequence of letters and/or numbers of the specified length
* @throws IllegalArgumentException If the specified length is less than or equal to 0
*/
public String generateCode(int requiredCodeLength) throws IllegalArgumentException {
if(requiredCodeLength <= 0)
throw new IllegalArgumentException("Required code length must be positive");
int randomBitLength = IntMath.checkedPow(requiredCodeLength, 2);
String newReferralCode = new BigInteger(randomBitLength, random).toString(TO_STRING_RADIX);
if(newReferralCode.length() > requiredCodeLength)
return newReferralCode.substring(0, requiredCodeLength);
else if(newReferralCode.length() < requiredCodeLength)
return generateCode(requiredCodeLength);
return newReferralCode;
}
示例2: backOffWait
import com.google.common.math.IntMath; //导入方法依赖的package包/类
public void backOffWait(int retryCount) {
// No wait if wait is disabled or this is first re-try
if(retryCount <= 0 || backOff <= 0) {
return;
}
// Wait time period
int waitTime;
// Current exponential back off
try {
waitTime = IntMath.checkedPow(backOff, retryCount);
} catch (ArithmeticException e) {
waitTime = MAX_BACKOFF_WAIT;
}
// Apply upper limit for the wait and finally wait
waitTime = Math.min(waitTime, MAX_BACKOFF_WAIT);
if (!ThreadUtil.sleep(waitTime)) {
LOG.info("Backoff waiting was interrupted");
}
}