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