Compare the remaining shorts of this buffer to another short buffer's remaining shorts. @param otherBuffer another short buffer. @return a negative value if this is less than otherBuffer; 0 if this equals to otherBuffer; a positive value if this is greater
(ShortBuffer otherBuffer)
| 177 | * if {@code otherBuffer} is not a short buffer. |
| 178 | */ |
| 179 | public int compareTo(ShortBuffer otherBuffer) { |
| 180 | int compareRemaining = (remaining() < otherBuffer.remaining()) ? remaining() |
| 181 | : otherBuffer.remaining(); |
| 182 | int thisPos = position; |
| 183 | int otherPos = otherBuffer.position; |
| 184 | short thisByte, otherByte; |
| 185 | while (compareRemaining > 0) { |
| 186 | thisByte = get(thisPos); |
| 187 | otherByte = otherBuffer.get(otherPos); |
| 188 | if (thisByte != otherByte) { |
| 189 | return thisByte < otherByte ? -1 : 1; |
| 190 | } |
| 191 | thisPos++; |
| 192 | otherPos++; |
| 193 | compareRemaining--; |
| 194 | } |
| 195 | return remaining() - otherBuffer.remaining(); |
| 196 | } |
| 197 | |
| 198 | /** |
| 199 | * Returns a duplicated buffer that shares its content with this buffer. |