当前位置: 首页>>代码示例>>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;未经允许,请勿转载。