Compare the remaining doubles of this buffer to another double buffer's remaining doubles. @param otherBuffer another double 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 {@
(DoubleBuffer otherBuffer)
| 176 | * if {@code other} is not a double buffer. |
| 177 | */ |
| 178 | public int compareTo(DoubleBuffer otherBuffer) { |
| 179 | int compareRemaining = (remaining() < otherBuffer.remaining()) ? remaining() |
| 180 | : otherBuffer.remaining(); |
| 181 | int thisPos = position; |
| 182 | int otherPos = otherBuffer.position; |
| 183 | double thisDouble, otherDouble; |
| 184 | while (compareRemaining > 0) { |
| 185 | thisDouble = get(thisPos); |
| 186 | otherDouble = otherBuffer.get(otherPos); |
| 187 | // checks for double and NaN inequality |
| 188 | if ((thisDouble != otherDouble) |
| 189 | && ((thisDouble == thisDouble) || (otherDouble == otherDouble))) { |
| 190 | return thisDouble < otherDouble ? -1 : 1; |
| 191 | } |
| 192 | thisPos++; |
| 193 | otherPos++; |
| 194 | compareRemaining--; |
| 195 | } |
| 196 | return remaining() - otherBuffer.remaining(); |
| 197 | } |
| 198 | |
| 199 | /** |
| 200 | * Returns a duplicated buffer that shares its content with this buffer. |