@Override public long padToLong() { long retVal = (bytes[0] & 0xFF); for (int i = 1; i < Math.min(bytes.length, 8); i++) { retVal |= (bytes[i] & 0xFFL) << (i * 8); } return retVal; }
@Override public int compare(double[] left, double[] right) { int minLength = Math.min(left.length, right.length); for (int i = 0; i < minLength; i++) { int result = Double.compare(left[i], right[i]); if (result != 0) { return result; } } return left.length - right.length; }
@Override public int read(byte[] b, int off, int len) throws IOException { if (left == 0) { return -1; } len = (int) Math.min(len, left); int result = in.read(b, off, len); if (result != -1) { left -= result; } return result; }
@Override public void setFixedLengthStreamingMode(long contentLength) { if (super.connected) throw new IllegalStateException("Already connected"); if (chunkLength > 0) throw new IllegalStateException("Already in chunked mode"); if (contentLength < 0) throw new IllegalArgumentException("contentLength < 0"); this.fixedContentLength = contentLength; super.fixedContentLength = (int) Math.min(contentLength, Integer.MAX_VALUE); }
@Override public ByteSource slice(long offset, long length) { checkArgument(offset >= 0, "offset (%s) may not be negative", offset); checkArgument(length >= 0, "length (%s) may not be negative", length); offset = Math.min(offset, this.length); length = Math.min(length, this.length - offset); int newOffset = this.offset + (int) offset; return new ByteArrayByteSource(bytes, newOffset, (int) length); }
private void encodeBase64Lines(StringBuilder out, ByteString data) { String base64 = data.base64(); for (int i = 0; i < base64.length(); i += 64) { out.append(base64, i, Math.min(i + 64, base64.length())).append('\n'); } }
@Override public int compare(long[] left, long[] right) { int minLength = Math.min(left.length, right.length); for (int i = 0; i < minLength; i++) { if (left[i] != right[i]) { return UnsignedLongs.compare(left[i], right[i]); } } return left.length - right.length; }
@Override public int compare(int[] left, int[] right) { int minLength = Math.min(left.length, right.length); for (int i = 0; i < minLength; i++) { if (left[i] != right[i]) { return UnsignedInts.compare(left[i], right[i]); } } return left.length - right.length; }
/** Returns best-effort-sized StringBuilder based on the given collection size. */ static StringBuilder newStringBuilderForCollection(int size) { checkNonnegative(size, "size"); return new StringBuilder((int) Math.min(size * 8L, Ints.MAX_POWER_OF_TWO)); }
@Override public int compare(int[] left, int[] right) { int minLength = Math.min(left.length, right.length); for (int i = 0; i < minLength; i++) { int result = Ints.compare(left[i], right[i]); if (result != 0) { return result; } } return left.length - right.length; }
@Override public int compare(char[] left, char[] right) { int minLength = Math.min(left.length, right.length); for (int i = 0; i < minLength; i++) { int result = Chars.compare(left[i], right[i]); if (result != 0) { return result; } } return left.length - right.length; }
public SpscArrayQueue(int capacity) { super(Pow2.roundToPowerOfTwo(capacity)); this.mask = length() - 1; this.producerIndex = new AtomicLong(); this.consumerIndex = new AtomicLong(); lookAheadStep = Math.min(capacity / 4, MAX_LOOK_AHEAD_STEP); }
ConcatMapEagerDelayErrorSubscriber(Subscriber<? super R> actual, Function<? super T, ? extends Publisher<? extends R>> mapper, int maxConcurrency, int prefetch, ErrorMode errorMode) { this.downstream = actual; this.mapper = mapper; this.maxConcurrency = maxConcurrency; this.prefetch = prefetch; this.errorMode = errorMode; this.subscribers = new SpscLinkedArrayQueue<InnerQueuedSubscriber<R>>(Math.min(prefetch, maxConcurrency)); this.errors = new AtomicThrowable(); this.requested = new AtomicLong(); }
@Override public Spliterator<T> spliterator() { if (iterable instanceof List) { final List<T> list = (List<T>) iterable; int toSkip = Math.min(list.size(), numberToSkip); return list.subList(toSkip, list.size()).spliterator(); } else { return Streams.stream(iterable).skip(numberToSkip).spliterator(); } } };
@Override public void write(Buffer source, long byteCount) throws IOException { long toRead = Math.min(remainingByteCount, byteCount); if (toRead > 0) { source.read(buffer, toRead); } long toSkip = byteCount - toRead; if (toSkip > 0) { source.skip(toSkip); } remainingByteCount -= toRead; receivedByteCount += byteCount; }
private void writeContinuationFrames(int streamId, long byteCount) throws IOException { while (byteCount > 0) { int length = (int) Math.min(maxFrameSize, byteCount); byteCount -= length; frameHeader(streamId, length, TYPE_CONTINUATION, byteCount == 0 ? FLAG_END_HEADERS : 0); sink.write(hpackBuffer, length); } }
@Override public int count(Object element) { int count1 = multiset1.count(element); return (count1 == 0) ? 0 : Math.min(count1, multiset2.count(element)); }
HashIterator() { nextSegmentIndex = segments.length - 1; nextTableIndex = -1; advance(); }
@Override public int read(char[] cbuf, int off, int len) throws IOException { return super.read(cbuf, off, Math.min(chunk, len)); } };
public void testEviction_maxSizeOneSegment() { IdentityLoader<Integer> loader = identityLoader(); LoadingCache<Integer, Integer> cache = CacheBuilder.newBuilder().concurrencyLevel(1).maximumSize(MAX_SIZE).build(loader); for (int i = 0; i < 2 * MAX_SIZE; i++) { cache.getUnchecked(i); assertEquals(Math.min(i + 1, MAX_SIZE), cache.size()); } assertEquals(MAX_SIZE, cache.size()); CacheTesting.checkValidState(cache); }