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


Java LongMath.saturatedAdd方法代碼示例

本文整理匯總了Java中com.google.common.math.LongMath.saturatedAdd方法的典型用法代碼示例。如果您正苦於以下問題:Java LongMath.saturatedAdd方法的具體用法?Java LongMath.saturatedAdd怎麽用?Java LongMath.saturatedAdd使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.google.common.math.LongMath的用法示例。


在下文中一共展示了LongMath.saturatedAdd方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: concat

import com.google.common.math.LongMath; //導入方法依賴的package包/類
/**
 * Returns a {@link Stream} containing the elements of the first stream, followed by the elements
 * of the second stream, and so on.
 *
 * <p>This is equivalent to {@code Stream.of(streams).flatMap(stream -> stream)}, but the returned
 * stream may perform better.
 *
 * @see Stream#concat(Stream, Stream)
 */
@SafeVarargs
public static <T> Stream<T> concat(Stream<? extends T>... streams) {
  // TODO(lowasser): consider an implementation that can support SUBSIZED
  boolean isParallel = false;
  int characteristics = Spliterator.ORDERED | Spliterator.SIZED | Spliterator.NONNULL;
  long estimatedSize = 0L;
  ImmutableList.Builder<Spliterator<? extends T>> splitrsBuilder =
      new ImmutableList.Builder<>(streams.length);
  for (Stream<? extends T> stream : streams) {
    isParallel |= stream.isParallel();
    Spliterator<? extends T> splitr = stream.spliterator();
    splitrsBuilder.add(splitr);
    characteristics &= splitr.characteristics();
    estimatedSize = LongMath.saturatedAdd(estimatedSize, splitr.estimateSize());
  }
  return StreamSupport.stream(
      CollectSpliterators.flatMap(
          splitrsBuilder.build().spliterator(),
          splitr -> (Spliterator<T>) splitr,
          characteristics,
          estimatedSize),
      isParallel);
}
 
開發者ID:zugzug90,項目名稱:guava-mock,代碼行數:33,代碼來源:Streams.java

示例2: reserveEarliestAvailable

import com.google.common.math.LongMath; //導入方法依賴的package包/類
@Override
final long reserveEarliestAvailable(int requiredPermits, long nowMicros) {
  resync(nowMicros);
  long returnValue = nextFreeTicketMicros;
  double storedPermitsToSpend = min(requiredPermits, this.storedPermits);
  double freshPermits = requiredPermits - storedPermitsToSpend;
  long waitMicros =
      storedPermitsToWaitTime(this.storedPermits, storedPermitsToSpend)
          + (long) (freshPermits * stableIntervalMicros);

  this.nextFreeTicketMicros = LongMath.saturatedAdd(nextFreeTicketMicros, waitMicros);
  this.storedPermits -= storedPermitsToSpend;
  return returnValue;
}
 
開發者ID:zugzug90,項目名稱:guava-mock,代碼行數:15,代碼來源:SmoothRateLimiter.java

示例3: reserveEarliestAvailable

import com.google.common.math.LongMath; //導入方法依賴的package包/類
@Override
  final long reserveEarliestAvailable(int requiredPermits, long nowMicros) {
    resync(nowMicros);
    long returnValue = nextFreeTicketMicros;
    double storedPermitsToSpend = min(requiredPermits, this.storedPermits);
    double freshPermits = requiredPermits - storedPermitsToSpend;
    long waitMicros =
      storedPermitsToWaitTime(this.storedPermits, storedPermitsToSpend)
+ (long) (freshPermits * stableIntervalMicros);
    this.nextFreeTicketMicros = LongMath.saturatedAdd(nextFreeTicketMicros, waitMicros);
    this.storedPermits -= storedPermitsToSpend;
    return returnValue;
  }
 
開發者ID:antlr,項目名稱:codebuff,代碼行數:14,代碼來源:SmoothRateLimiter.java

示例4: reserveEarliestAvailable

import com.google.common.math.LongMath; //導入方法依賴的package包/類
@Override
final long reserveEarliestAvailable(int requiredPermits, long nowMicros) {
  resync(nowMicros);
  long returnValue = nextFreeTicketMicros;
  double storedPermitsToSpend = min(requiredPermits, this.storedPermits);
  double freshPermits = requiredPermits - storedPermitsToSpend;
  long waitMicros =
    storedPermitsToWaitTime(this.storedPermits, storedPermitsToSpend)
    + (long) (freshPermits * stableIntervalMicros);
  this.nextFreeTicketMicros = LongMath.saturatedAdd(nextFreeTicketMicros, waitMicros);
  this.storedPermits -= storedPermitsToSpend;
  return returnValue;
}
 
開發者ID:antlr,項目名稱:codebuff,代碼行數:14,代碼來源:SmoothRateLimiter.java


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