Checks whether this byte buffer is equal to another object. If other is not a byte buffer then false is returned. Two byte buffers are equal if and only if their remaining bytes are exactly the same. Position, limit, capacity and mark are not considered. @param other
(Object other)
| 349 | * {@code false} otherwise. |
| 350 | */ |
| 351 | @Override |
| 352 | public boolean equals(Object other) { |
| 353 | if (!(other instanceof ByteBuffer)) { |
| 354 | return false; |
| 355 | } |
| 356 | ByteBuffer otherBuffer = (ByteBuffer) other; |
| 357 | |
| 358 | if (remaining() != otherBuffer.remaining()) { |
| 359 | return false; |
| 360 | } |
| 361 | |
| 362 | int myPosition = position; |
| 363 | int otherPosition = otherBuffer.position; |
| 364 | boolean equalSoFar = true; |
| 365 | while (equalSoFar && (myPosition < limit)) { |
| 366 | equalSoFar = get(myPosition++) == otherBuffer.get(otherPosition++); |
| 367 | } |
| 368 | |
| 369 | return equalSoFar; |
| 370 | } |
| 371 | |
| 372 | /** |
| 373 | * Returns the byte at the current position and increases the position by 1. |