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


Java Ints.saturatedCast方法代碼示例

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


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

示例1: ApacheThriftMethodInvoker

import com.google.common.primitives.Ints; //導入方法依賴的package包/類
public ApacheThriftMethodInvoker(
        ListeningExecutorService executorService,
        ListeningScheduledExecutorService delayService,
        TTransportFactory transportFactory,
        TProtocolFactory protocolFactory,
        Duration connectTimeout,
        Duration requestTimeout,
        Optional<HostAndPort> socksProxy,
        Optional<SSLContext> sslContext)
{
    this.executorService = requireNonNull(executorService, "executorService is null");
    this.delayService = requireNonNull(delayService, "delayService is null");
    this.transportFactory = requireNonNull(transportFactory, "transportFactory is null");
    this.protocolFactory = requireNonNull(protocolFactory, "protocolFactory is null");
    this.connectTimeoutMillis = Ints.saturatedCast(requireNonNull(connectTimeout, "connectTimeout is null").toMillis());
    this.requestTimeoutMillis = Ints.saturatedCast(requireNonNull(requestTimeout, "requestTimeout is null").toMillis());
    this.socksProxy = requireNonNull(socksProxy, "socksProxy is null");
    this.sslContext = requireNonNull(sslContext, "sslContext is null");
}
 
開發者ID:airlift,項目名稱:drift,代碼行數:20,代碼來源:ApacheThriftMethodInvoker.java

示例2: size

import com.google.common.primitives.Ints; //導入方法依賴的package包/類
@Override
public int size() {
  // racy single-check idiom
  Integer result = size;
  if (result == null) {
    long total = 0;
    for (Range<C> range : ranges) {
      total += ContiguousSet.create(range, domain).size();
      if (total >= Integer.MAX_VALUE) {
        break;
      }
    }
    result = size = Ints.saturatedCast(total);
  }
  return result.intValue();
}
 
開發者ID:paul-hammant,項目名稱:googles-monorepo-demo,代碼行數:17,代碼來源:ImmutableRangeSet.java

示例3: edges

import com.google.common.primitives.Ints; //導入方法依賴的package包/類
/**
 * An implementation of {@link BaseGraph#edges()} defined in terms of {@link #nodes()} and {@link
 * #successors(Object)}.
 */
@Override
public Set<EndpointPair<N>> edges() {
  return new AbstractSet<EndpointPair<N>>() {
    @Override
    public UnmodifiableIterator<EndpointPair<N>> iterator() {
      return EndpointPairIterator.of(AbstractBaseGraph.this);
    }

    @Override
    public int size() {
      return Ints.saturatedCast(edgeCount());
    }

    @Override
    public boolean contains(@Nullable Object obj) {
      if (!(obj instanceof EndpointPair)) {
        return false;
      }
      EndpointPair<?> endpointPair = (EndpointPair<?>) obj;
      return isDirected() == endpointPair.isOrdered()
          && nodes().contains(endpointPair.nodeU())
          && successors(endpointPair.nodeU()).contains(endpointPair.nodeV());
    }
  };
}
 
開發者ID:paul-hammant,項目名稱:googles-monorepo-demo,代碼行數:30,代碼來源:AbstractBaseGraph.java

示例4: indexOf

import com.google.common.primitives.Ints; //導入方法依賴的package包/類
@Override
int indexOf(Object target) {
  if (contains(target)) {
    @SuppressWarnings("unchecked") // if it's contained, it's definitely a C
    C c = (C) target;
    long total = 0;
    for (Range<C> range : ranges) {
      if (range.contains(c)) {
        return Ints.saturatedCast(total + ContiguousSet.create(range, domain).indexOf(c));
      } else {
        total += ContiguousSet.create(range, domain).size();
      }
    }
    throw new AssertionError("impossible");
  }
  return -1;
}
 
開發者ID:zugzug90,項目名稱:guava-mock,代碼行數:18,代碼來源:ImmutableRangeSet.java

示例5: size

import com.google.common.primitives.Ints; //導入方法依賴的package包/類
@Override
public int size() {
  Segment<K, V, E, S>[] segments = this.segments;
  long sum = 0;
  for (int i = 0; i < segments.length; ++i) {
    sum += segments[i].count;
  }
  return Ints.saturatedCast(sum);
}
 
開發者ID:paul-hammant,項目名稱:googles-monorepo-demo,代碼行數:10,代碼來源:MapMakerInternalMap.java

示例6: size

import com.google.common.primitives.Ints; //導入方法依賴的package包/類
/**
 * Returns the number of elements remaining in {@code iterator}. The iterator
 * will be left exhausted: its {@code hasNext()} method will return
 * {@code false}.
 */
public static int size(Iterator<?> iterator) {
  long count = 0L;
  while (iterator.hasNext()) {
    iterator.next();
    count++;
  }
  return Ints.saturatedCast(count);
}
 
開發者ID:paul-hammant,項目名稱:googles-monorepo-demo,代碼行數:14,代碼來源:Iterators.java

示例7: size

import com.google.common.primitives.Ints; //導入方法依賴的package包/類
/**
 * {@inheritDoc}
 *
 * <p>If the data in the multiset is modified by any other threads during this method,
 * it is undefined which (if any) of these modifications will be reflected in the result.
 */
@Override
public int size() {
  long sum = 0L;
  for (AtomicInteger value : countMap.values()) {
    sum += value.get();
  }
  return Ints.saturatedCast(sum);
}
 
開發者ID:zugzug90,項目名稱:guava-mock,代碼行數:15,代碼來源:ConcurrentHashMultiset.java

示例8: edges

import com.google.common.primitives.Ints; //導入方法依賴的package包/類
/**
 * An implementation of {@link BaseGraph#edges()} defined in terms of {@link #nodes()} and {@link
 * #successors(Object)}.
 */
@Override
public Set<EndpointPair<N>> edges() {
  return new AbstractSet<EndpointPair<N>>() {
    @Override
    public UnmodifiableIterator<EndpointPair<N>> iterator() {
      return EndpointPairIterator.of(AbstractBaseGraph.this);
    }

    @Override
    public int size() {
      return Ints.saturatedCast(edgeCount());
    }

    // Mostly safe: We check contains(u) before calling successors(u), so we perform unsafe
    // operations only in weird cases like checking for an EndpointPair<ArrayList> in a
    // Graph<LinkedList>.
    @SuppressWarnings("unchecked")
    @Override
    public boolean contains(@Nullable Object obj) {
      if (!(obj instanceof EndpointPair)) {
        return false;
      }
      EndpointPair<?> endpointPair = (EndpointPair<?>) obj;
      return isDirected() == endpointPair.isOrdered()
          && nodes().contains(endpointPair.nodeU())
          && successors((N) endpointPair.nodeU()).contains(endpointPair.nodeV());
    }
  };
}
 
開發者ID:zugzug90,項目名稱:guava-mock,代碼行數:34,代碼來源:AbstractBaseGraph.java

示例9: size

import com.google.common.primitives.Ints; //導入方法依賴的package包/類
/**
 * {@inheritDoc}
 *
 * <p>If the data in the multiset is modified by any other threads during this
 * method, it is undefined which (if any) of these modifications will be
 * reflected in the result.
 */
@Override public int size() {
  long sum = 0L;
  for (Integer value : countMap.values()) {
    sum += value;
  }
  return Ints.saturatedCast(sum);
}
 
開發者ID:zugzug90,項目名稱:guava-mock,代碼行數:15,代碼來源:ConcurrentHashMultisetBenchmark.java

示例10: distinctElements

import com.google.common.primitives.Ints; //導入方法依賴的package包/類
@Override
int distinctElements() {
  return Ints.saturatedCast(aggregateForEntries(Aggregate.DISTINCT));
}
 
開發者ID:paul-hammant,項目名稱:googles-monorepo-demo,代碼行數:5,代碼來源:TreeMultiset.java

示例11: MemoryInputStream

import com.google.common.primitives.Ints; //導入方法依賴的package包/類
public MemoryInputStream(Memory mem)
{
    this(mem, Ints.saturatedCast(mem.size));
}
 
開發者ID:Netflix,項目名稱:sstable-adaptor,代碼行數:5,代碼來源:MemoryInputStream.java

示例12: available

import com.google.common.primitives.Ints; //導入方法依賴的package包/類
@Override
public int available()
{
    return Ints.saturatedCast(buffer.remaining() + memRemaining());
}
 
開發者ID:Netflix,項目名稱:sstable-adaptor,代碼行數:6,代碼來源:MemoryInputStream.java

示例13: size

import com.google.common.primitives.Ints; //導入方法依賴的package包/類
@Override
public int size() {
  return Ints.saturatedCast(size);
}
 
開發者ID:zugzug90,項目名稱:guava-mock,代碼行數:5,代碼來源:AbstractMapBasedMultiset.java

示例14: saturatedAdd

import com.google.common.primitives.Ints; //導入方法依賴的package包/類
/**
 * Returns the sum of {@code a} and {@code b} unless it would overflow or underflow in which case
 * {@code Integer.MAX_VALUE} or {@code Integer.MIN_VALUE} is returned, respectively.
 *
 * @since 20.0
 */
@Beta
public static int saturatedAdd(int a, int b) {
  return Ints.saturatedCast((long) a + b);
}
 
開發者ID:zugzug90,項目名稱:guava-mock,代碼行數:11,代碼來源:IntMath.java

示例15: saturatedMultiply

import com.google.common.primitives.Ints; //導入方法依賴的package包/類
/**
 * Returns the product of {@code a} and {@code b} unless it would overflow or underflow in which
 * case {@code Integer.MAX_VALUE} or {@code Integer.MIN_VALUE} is returned, respectively.
 *
 * @since 20.0
 */
@Beta
public static int saturatedMultiply(int a, int b) {
  return Ints.saturatedCast((long) a * b);
}
 
開發者ID:zugzug90,項目名稱:guava-mock,代碼行數:11,代碼來源:IntMath.java


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