ChecksumHashFunction( ImmutableSupplier<? extends Checksum> checksumSupplier, int bits, String toString) { this.checksumSupplier = checkNotNull(checksumSupplier); checkArgument(bits == 32 || bits == 64, "bits (%s) must be either 32 or 64", bits); this.bits = bits; this.toString = checkNotNull(toString); }
/** * Specifies the ordering of the generated multimap's keys. * * @since 8.0 */ @CanIgnoreReturnValue public Builder<K, V> orderKeysBy(Comparator<? super K> keyComparator) { this.keyComparator = checkNotNull(keyComparator); return this; }
/** * Returns a {@code ByteSink} that writes base-encoded bytes to the specified {@code CharSink}. */ @GwtIncompatible // ByteSink,CharSink public final ByteSink encodingSink(final CharSink encodedSink) { checkNotNull(encodedSink); return new ByteSink() { @Override public OutputStream openStream() throws IOException { return encodingStream(encodedSink.openStream()); } }; }
/** * Calls {@code next()} on {@code iterator}, either {@code numberToAdvance} times or until {@code * hasNext()} returns {@code false}, whichever comes first. * * @return the number of elements the iterator was advanced * @since 13.0 (since 3.0 as {@code Iterators.skip}) */ @CanIgnoreReturnValue public static int advance(Iterator<?> iterator, int numberToAdvance) { checkNotNull(iterator); checkArgument(numberToAdvance >= 0, "numberToAdvance must be nonnegative"); int i; for (i = 0; i < numberToAdvance && iterator.hasNext(); i++) { iterator.next(); } return i; }
/** * Sets a custom {@code Equivalence} strategy for comparing keys. * * <p>By default, the map uses {@link Equivalence#identity} to determine key equality when {@link * #weakKeys} is specified, and {@link Equivalence#equals()} otherwise. The only place this is * used is in {@link Interners.WeakInterner}. */ @CanIgnoreReturnValue @GwtIncompatible // To be supported MapMaker keyEquivalence(Equivalence<Object> equivalence) { checkState(keyEquivalence == null, "key equivalence was already set to %s", keyEquivalence); keyEquivalence = checkNotNull(equivalence); this.useCustomMap = true; return this; }
/** @since 12.0 */ @GwtIncompatible // NavigableSet @Override public ImmutableSortedSet<E> subSet( E fromElement, boolean fromInclusive, E toElement, boolean toInclusive) { checkNotNull(fromElement); checkNotNull(toElement); checkArgument(comparator.compare(fromElement, toElement) <= 0); return subSetImpl(fromElement, fromInclusive, toElement, toInclusive); }
/** * Specifies the ordering of the generated multimap's values for each key. * * @since 8.0 */ @CanIgnoreReturnValue public Builder<K, V> orderValuesBy(Comparator<? super V> valueComparator) { this.valueComparator = checkNotNull(valueComparator); return this; }
/** * Associates the specified range with the specified value. * * @throws IllegalArgumentException if {@code range} is empty */ @CanIgnoreReturnValue public Builder<K, V> put(Range<K> range, V value) { checkNotNull(range); checkNotNull(value); checkArgument(!range.isEmpty(), "Range must not be empty, but was %s", range); entries.add(Maps.immutableEntry(range, value)); return this; }
/** * Returns a {@code ByteSource} that reads base-encoded bytes from the specified {@code * CharSource}. */ @GwtIncompatible // ByteSource,CharSource public final ByteSource decodingSource(final CharSource encodedSource) { checkNotNull(encodedSource); return new ByteSource() { @Override public InputStream openStream() throws IOException { return decodingStream(encodedSource.openStream()); } }; }
SeparatedBaseEncoding(BaseEncoding delegate, String separator, int afterEveryChars) { this.delegate = checkNotNull(delegate); this.separator = checkNotNull(separator); this.afterEveryChars = afterEveryChars; checkArgument( afterEveryChars > 0, "Cannot add a separator after every %s chars", afterEveryChars); }
/** @since 12.0 */ @GwtIncompatible // NavigableSet @Override public ContiguousSet<C> subSet( C fromElement, boolean fromInclusive, C toElement, boolean toInclusive) { checkNotNull(fromElement); checkNotNull(toElement); checkArgument(comparator().compare(fromElement, toElement) <= 0); return subSetImpl(fromElement, fromInclusive, toElement, toInclusive); }
/** Specifies the ordering of the generated table's columns. */ @CanIgnoreReturnValue public Builder<R, C, V> orderColumnsBy(Comparator<? super C> columnComparator) { this.columnComparator = checkNotNull(columnComparator, "columnComparator"); return this; }
/** * Returns a {@code UnsignedLong} representing the same value as the specified {@code BigInteger}. * This is the inverse operation of {@link #bigIntegerValue()}. * * @throws IllegalArgumentException if {@code value} is negative or {@code value >= 2^64} */ @CanIgnoreReturnValue public static UnsignedLong valueOf(BigInteger value) { checkNotNull(value); checkArgument( value.signum() >= 0 && value.bitLength() <= Long.SIZE, "value (%s) is outside the range for an unsigned long value", value); return fromLongBits(value.longValue()); }
@GwtIncompatible static Reader ignoringReader(final Reader delegate, final String toIgnore) { checkNotNull(delegate); checkNotNull(toIgnore); return new Reader() { @Override public int read() throws IOException { int readChar; do { readChar = delegate.read(); } while (readChar != -1 && toIgnore.indexOf((char) readChar) >= 0); return readChar; } @Override public int read(char[] cbuf, int off, int len) throws IOException { throw new UnsupportedOperationException(); } @Override public void close() throws IOException { delegate.close(); } }; }
/** Creates a BloomFilter. */ private BloomFilter( LockFreeBitArray bits, int numHashFunctions, Funnel<? super T> funnel, Strategy strategy) { checkArgument(numHashFunctions > 0, "numHashFunctions (%s) must be > 0", numHashFunctions); checkArgument( numHashFunctions <= 255, "numHashFunctions (%s) must be <= 255", numHashFunctions); this.bits = checkNotNull(bits); this.numHashFunctions = numHashFunctions; this.funnel = checkNotNull(funnel); this.strategy = checkNotNull(strategy); }
@GwtIncompatible // To be supported (synchronously). public CacheBuilder<K, V> refreshAfterWrite(long duration, TimeUnit unit) { checkNotNull(unit); checkState(refreshNanos == UNSET_INT, "refresh was already set to %s ns", refreshNanos); checkArgument(duration > 0, "duration must be positive: %s %s", duration, unit); this.refreshNanos = unit.toNanos(duration); return this;
/** Specifies the ordering of the generated table's rows. */ @CanIgnoreReturnValue public Builder<R, C, V> orderRowsBy(Comparator<? super R> rowComparator) { this.rowComparator = checkNotNull(rowComparator, "rowComparator"); return this; }
/** * {@inheritDoc} * * @throws IllegalArgumentException if {@code rowKey} is not in {@link #rowKeySet()} or {@code * columnKey} is not in {@link #columnKeySet()}. */ @CanIgnoreReturnValue @Override public V put(R rowKey, C columnKey, @NullableDecl V value) { checkNotNull(rowKey); checkNotNull(columnKey); Integer rowIndex = rowKeyToIndex.get(rowKey); checkArgument(rowIndex != null, "Row %s not in %s", rowKey, rowList); Integer columnIndex = columnKeyToIndex.get(columnKey); checkArgument(columnIndex != null, "Column %s not in %s", columnKey, columnList); return set(rowIndex, columnIndex, value); }
@GwtIncompatible // invokeAccessibleNonThrowingMethod private static List<StackTraceElement> jlaStackTrace(final Throwable t) { checkNotNull(t); /* * TODO(cpovirk): Consider optimizing iterator() to catch IOOBE instead of doing bounds checks. * * TODO(cpovirk): Consider the UnsignedBytes pattern if it performs faster and doesn't cause * AOSP grief. */ return new AbstractList<StackTraceElement>() { @Override public StackTraceElement get(int n) { return (StackTraceElement) invokeAccessibleNonThrowingMethod(getStackTraceElementMethod, jla, t, n); } @Override public int size() { return (Integer) invokeAccessibleNonThrowingMethod(getStackTraceDepthMethod, jla, t); } }; }
private TopKSelector(Comparator<? super T> comparator, int k) { this.comparator = checkNotNull(comparator, "comparator"); this.k = k; checkArgument(k >= 0, "k must be nonnegative, was %s", k); this.buffer = (T[]) new Object[k * 2]; this.bufferSize = 0; this.threshold = null; }