MCPcopy Index your code
hub / github.com/davidgiven/luje / compareTo

Method compareTo

lib/java/nio/ByteBuffer.java:305–322  ·  view source on GitHub ↗

Compares the remaining bytes of this buffer to another byte buffer's remaining bytes. @param otherBuffer another byte buffer. @return a negative value if this is less than other; 0 if this equals to other; a positive value if this is greater than {@code ot

(ByteBuffer otherBuffer)

Source from the content-addressed store, hash-verified

303 * if {@code other} is not a byte buffer.
304 */
305 public int compareTo(ByteBuffer otherBuffer) {
306 int compareRemaining = (remaining() < otherBuffer.remaining()) ? remaining()
307 : otherBuffer.remaining();
308 int thisPos = position;
309 int otherPos = otherBuffer.position;
310 byte thisByte, otherByte;
311 while (compareRemaining > 0) {
312 thisByte = get(thisPos);
313 otherByte = otherBuffer.get(otherPos);
314 if (thisByte != otherByte) {
315 return thisByte < otherByte ? -1 : 1;
316 }
317 thisPos++;
318 otherPos++;
319 compareRemaining--;
320 }
321 return remaining() - otherBuffer.remaining();
322 }
323
324 /**
325 * Returns a duplicated buffer that shares its content with this buffer.

Callers

nothing calls this directly

Calls 3

getMethod · 0.95
remainingMethod · 0.80
getMethod · 0.65

Tested by

no test coverage detected