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; }
CacheBuilder<K, V> setKeyStrength(Strength strength) { checkState(keyStrength == null, "Key strength was already set to %s", keyStrength); keyStrength = checkNotNull(strength); return this; }
@Override public Byte set(int index, Byte element) { checkElementIndex(index, size()); byte oldValue = array[start + index]; // checkNotNull for GWT (do not optimize) array[start + index] = checkNotNull(element); return oldValue; }
@Override public RangeMap subRangeMap(Range range) { checkNotNull(range); return this; } };
@Override protected void parseInteger(CacheBuilderSpec spec, int value) { checkArgument( spec.initialCapacity == null, "initial capacity was already set to ", spec.initialCapacity); spec.initialCapacity = value; } }
@Override public int asInt() { checkState( bytes.length >= 4, "HashCode#asInt() requires >= 4 bytes (it only has %s bytes).", bytes.length); return (bytes[0] & 0xFF) | ((bytes[1] & 0xFF) << 8) | ((bytes[2] & 0xFF) << 16) | ((bytes[3] & 0xFF) << 24); }
/** * Wraps another output stream, counting the number of bytes written. * * @param out the output stream to be wrapped */ public CountingOutputStream(OutputStream out) { super(checkNotNull(out)); }
@Override protected void parseLong(CacheBuilderSpec spec, long value) { checkArgument(spec.maximumSize == null, "maximum size was already set to ", spec.maximumSize); checkArgument( spec.maximumWeight == null, "maximum weight was already set to ", spec.maximumWeight); spec.maximumSize = value; } }
/** * Precondition tester for {@code Iterator.remove()} that throws an exception with a consistent * error message. */ static void checkRemove(boolean canRemove) { checkState(canRemove, "no calls to next() since the last call to remove()"); } }
@Override public Boolean set(int index, Boolean element) { checkElementIndex(index, size()); boolean oldValue = array[start + index]; // checkNotNull for GWT (do not optimize) array[start + index] = checkNotNull(element); return oldValue; }
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); }
/** * Wraps another input stream, counting the number of bytes read. * * @param in the input stream to be wrapped */ public CountingInputStream(InputStream in) { super(checkNotNull(in)); }
MapMaker setValueStrength(Strength strength) { checkState(valueStrength == null, "Value strength was already set to %s", valueStrength); valueStrength = checkNotNull(strength); if (strength != Strength.STRONG) { // STRONG could be used during deserialization. useCustomMap = true; } return this; }
@Override protected void parseDuration(CacheBuilderSpec spec, long duration, TimeUnit unit) { checkArgument(spec.accessExpirationTimeUnit == null, "expireAfterAccess already set"); spec.accessExpirationDuration = duration; spec.accessExpirationTimeUnit = unit; } }
@Override public void addOutEdge(E edge, N node) { N previousNode = outEdgeMap.put(edge, node); checkState(previousNode == null); } }
@Override public Double set(int index, Double element) { checkElementIndex(index, size()); double oldValue = array[start + index]; // checkNotNull for GWT (do not optimize) array[start + index] = checkNotNull(element); return oldValue; }
/** 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); }
/** Creates a new instance that will read lines from the given {@code Readable} object. */ public LineReader(Readable readable) { this.readable = checkNotNull(readable); this.reader = (readable instanceof Reader) ? (Reader) readable : null; }
MapMaker setKeyStrength(Strength strength) { checkState(keyStrength == null, "Key strength was already set to %s", keyStrength); keyStrength = checkNotNull(strength); if (strength != Strength.STRONG) { // STRONG could be used during deserialization. useCustomMap = true; } return this; }
/** Returns its argument if it is non-negative, zero if it is negative. */ static double ensureNonNegative(double value) { checkArgument(!isNaN(value)); if (value > 0.0) { return value; } else { return 0.0; } }