Checks whether this char buffer is equal to another object. If other is not a char buffer then false is returned. Two char buffers are equal if and only if their remaining chars are exactly the same. Position, limit, capacity and mark are not considered. @param other
(Object other)
| 292 | * {@code false} otherwise. |
| 293 | */ |
| 294 | @Override |
| 295 | public boolean equals(Object other) { |
| 296 | if (!(other instanceof CharBuffer)) { |
| 297 | return false; |
| 298 | } |
| 299 | CharBuffer otherBuffer = (CharBuffer) other; |
| 300 | |
| 301 | if (remaining() != otherBuffer.remaining()) { |
| 302 | return false; |
| 303 | } |
| 304 | |
| 305 | int myPosition = position; |
| 306 | int otherPosition = otherBuffer.position; |
| 307 | boolean equalSoFar = true; |
| 308 | while (equalSoFar && (myPosition < limit)) { |
| 309 | equalSoFar = get(myPosition++) == otherBuffer.get(otherPosition++); |
| 310 | } |
| 311 | |
| 312 | return equalSoFar; |
| 313 | } |
| 314 | |
| 315 | /** |
| 316 | * Returns the char at the current position and increases the position by 1. |