當前位置: 首頁>>代碼示例>>Java>>正文


Java IntMath.checkedPow方法代碼示例

本文整理匯總了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;
}
 
開發者ID:BuaBook,項目名稱:buabook-common,代碼行數:23,代碼來源:RandomCodeGenerator.java

示例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");
  }
}
 
開發者ID:streamsets,項目名稱:datacollector,代碼行數:23,代碼來源:Configs.java


注:本文中的com.google.common.math.IntMath.checkedPow方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。