本文整理匯總了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");
}
}