本文整理了Java中java.lang.Math.min()
方法的一些代码示例,展示了Math.min()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Math.min()
方法的具体详情如下:
包路径:java.lang.Math
类名称:Math
方法名:min
[英]Returns the most negative (closest to negative infinity) of the two arguments.
Special cases:
代码示例来源:origin: google/guava
@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;
}
代码示例来源:origin: google/guava
@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;
}
代码示例来源:origin: google/guava
@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;
}
代码示例来源:origin: square/okhttp
@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);
}
代码示例来源:origin: google/guava
@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);
}
代码示例来源:origin: square/okhttp
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');
}
}
代码示例来源:origin: google/guava
@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;
}
代码示例来源:origin: google/guava
@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;
}
代码示例来源:origin: google/guava
/** 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));
}
代码示例来源:origin: google/guava
@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;
}
代码示例来源:origin: google/guava
@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;
}
代码示例来源:origin: ReactiveX/RxJava
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);
}
代码示例来源:origin: ReactiveX/RxJava
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();
}
代码示例来源:origin: google/guava
@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();
}
}
};
代码示例来源:origin: square/okhttp
@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;
}
代码示例来源:origin: square/okhttp
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);
}
}
代码示例来源:origin: google/guava
@Override
public int count(Object element) {
int count1 = multiset1.count(element);
return (count1 == 0) ? 0 : Math.min(count1, multiset2.count(element));
}
代码示例来源:origin: google/guava
HashIterator() {
nextSegmentIndex = segments.length - 1;
nextTableIndex = -1;
advance();
}
代码示例来源:origin: google/guava
@Override
public int read(char[] cbuf, int off, int len) throws IOException {
return super.read(cbuf, off, Math.min(chunk, len));
}
};
代码示例来源:origin: google/guava
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);
}
内容来源于网络,如有侵权,请联系作者删除!