本文整理匯總了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");
}
示例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();
}
示例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());
}
};
}
示例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;
}
示例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);
}
示例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);
}
示例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);
}
示例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());
}
};
}
示例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);
}
示例10: distinctElements
import com.google.common.primitives.Ints; //導入方法依賴的package包/類
@Override
int distinctElements() {
return Ints.saturatedCast(aggregateForEntries(Aggregate.DISTINCT));
}
示例11: MemoryInputStream
import com.google.common.primitives.Ints; //導入方法依賴的package包/類
public MemoryInputStream(Memory mem)
{
this(mem, Ints.saturatedCast(mem.size));
}
示例12: available
import com.google.common.primitives.Ints; //導入方法依賴的package包/類
@Override
public int available()
{
return Ints.saturatedCast(buffer.remaining() + memRemaining());
}
示例13: size
import com.google.common.primitives.Ints; //導入方法依賴的package包/類
@Override
public int size() {
return Ints.saturatedCast(size);
}
示例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);
}
示例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);
}