@Override public int size() { long size = cumulativeCounts[offset + length] - cumulativeCounts[offset]; return Ints.saturatedCast(size); }
@Override public int size() { return Ints.saturatedCast(size); } }
@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); }
@Override public int size() { return Ints.saturatedCast(size); }
@Override public int size() { return Ints.saturatedCast(size); }
/** * 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); }
/** * Returns the difference 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 saturatedSubtract(int a, int b) { return Ints.saturatedCast((long) a - b); }
/** * 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); }
/** * 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); }
/** * {@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); }
@VisibleForTesting static int computeArrayListCapacity(int arraySize) { checkNonnegative(arraySize, "arraySize"); // TODO(kevinb): Figure out the right behavior, and document it return Ints.saturatedCast(5L + arraySize + (arraySize / 10)); }
@Override public int size() { return Ints.saturatedCast(aggregateForEntries(Aggregate.SIZE)); }
@Override public int size() { return map.size(); }
@Override public int size() { return Ints.saturatedCast(edgeCount()); }
@Override int distinctElements() { return Ints.saturatedCast(aggregateForEntries(Aggregate.DISTINCT)); }
/** An implementation of {@link Multiset#size}. */ static int linearTimeSizeImpl(Multiset<?> multiset) { long size = 0; for (Entry<?> entry : multiset.entrySet()) { size += entry.getCount(); } return Ints.saturatedCast(size); }
public void testSaturatedCast() { for (int value : VALUES) { assertEquals(value, Ints.saturatedCast((long) value)); } assertEquals(GREATEST, Ints.saturatedCast(GREATEST + 1L)); assertEquals(LEAST, Ints.saturatedCast(LEAST - 1L)); assertEquals(GREATEST, Ints.saturatedCast(Long.MAX_VALUE)); assertEquals(LEAST, Ints.saturatedCast(Long.MIN_VALUE)); }
/** * Appends all values from {@code stream}, in order, to the end of the values the built {@link * ImmutableDoubleArray} will contain. */ public Builder addAll(DoubleStream stream) { Spliterator.OfDouble spliterator = stream.spliterator(); long size = spliterator.getExactSizeIfKnown(); if (size > 0) { // known *and* nonempty ensureRoomFor(Ints.saturatedCast(size)); } spliterator.forEachRemaining((DoubleConsumer) this::add); return this; }
/** * Appends all values from {@code stream}, in order, to the end of the values the built {@link * ImmutableLongArray} will contain. */ public Builder addAll(LongStream stream) { Spliterator.OfLong spliterator = stream.spliterator(); long size = spliterator.getExactSizeIfKnown(); if (size > 0) { // known *and* nonempty ensureRoomFor(Ints.saturatedCast(size)); } spliterator.forEachRemaining((LongConsumer) this::add); return this; }
/** * Appends all values from {@code stream}, in order, to the end of the values the built {@link * ImmutableIntArray} will contain. */ public Builder addAll(IntStream stream) { Spliterator.OfInt spliterator = stream.spliterator(); long size = spliterator.getExactSizeIfKnown(); if (size > 0) { // known *and* nonempty ensureRoomFor(Ints.saturatedCast(size)); } spliterator.forEachRemaining((IntConsumer) this::add); return this; }