Compare the remaining chars of this buffer to another char buffer's remaining chars. @param otherBuffer another char buffer. @return a negative value if this is less than otherBuffer; 0 if this equals to otherBuffer; a positive value if this is greater tha
(CharBuffer otherBuffer)
| 246 | * if {@code otherBuffer} is not a char buffer. |
| 247 | */ |
| 248 | public int compareTo(CharBuffer otherBuffer) { |
| 249 | int compareRemaining = (remaining() < otherBuffer.remaining()) ? remaining() |
| 250 | : otherBuffer.remaining(); |
| 251 | int thisPos = position; |
| 252 | int otherPos = otherBuffer.position; |
| 253 | char thisByte, otherByte; |
| 254 | while (compareRemaining > 0) { |
| 255 | thisByte = get(thisPos); |
| 256 | otherByte = otherBuffer.get(otherPos); |
| 257 | if (thisByte != otherByte) { |
| 258 | return thisByte < otherByte ? -1 : 1; |
| 259 | } |
| 260 | thisPos++; |
| 261 | otherPos++; |
| 262 | compareRemaining--; |
| 263 | } |
| 264 | return remaining() - otherBuffer.remaining(); |
| 265 | } |
| 266 | |
| 267 | /** |
| 268 | * Returns a duplicated buffer that shares its content with this buffer. |