ByteBuffer { @Override public boolean equals(Object obj) { if (this == obj) { return true; } if ((obj == null) || !(obj instanceof ByteBuffer)) { return false; } ByteBuffer toTest = (ByteBuffer)obj; if (toTest.size() != this.size()) return false; int length = this.size(); for (int i = 0; i < length; i++) { try { if (this.get(i) != toTest.get(i)) { return false; } } catch (Exception e) { logger.error("Impossible case should never happen", e); return false; } } return true; } ByteBuffer();  ByteBuffer(int capacity);  ByteBuffer(byte[] bytes);  ByteBuffer(byte[] bytes, int capacity);  ByteBuffer(byte[] bytes, int offset, int length);  ByteBuffer(byte[] bytes, int offset, int length, int capacity);  ByteBuffer(String string0);  ByteBuffer(String string0, int capacity); int size(); int capacity(); int free(); boolean isFree(int count); boolean isEmpty(); boolean isFull(); void clear(); void add(byte b); void add(byte[] bytes); void add(byte[] bytes, int offset, int length); void delete(int count); byte remove(); byte[] remove(int count); int occurrences(byte b); int occurrences(byte[] bytes); ByteBuffer copy(); ByteBuffer copy(int offset, int length); ByteBuffer copy(int offset, int length, int capacity); byte get(int index); byte[] toArray(); byte[] toArray(int offset, int length); byte[] toArray(int offset, int length, int capacity); void toArray(int offset, int length, byte[] targetBuffer, int targetOffset); boolean startsWith(byte[] prefix); boolean endsWith(byte[] prefix); int indexOf(byte[] bytes); int indexOf(byte[] bytes, int offset); @Override int hashCode(); @Override boolean equals(Object obj); boolean equals(byte[] bytes); @Override String toString(); String toHexString(); String toHexString(int offset, int length);  }
@Test public void equals() throws BufferException { ByteBuffer buffer = createCircledByteBuffer(TEST_BYTES1.length); buffer.add(TEST_BYTES1); ByteBuffer buffer2 = createCircledByteBuffer(TEST_BYTES1.length); buffer2.add(TEST_BYTES1); Assert.assertEquals(false, buffer.equals((Object)TEST_BYTES1)); Assert.assertEquals(true, buffer.equals(buffer2)); buffer2.remove(); Assert.assertEquals(false, buffer.equals(buffer2)); Assert.assertEquals(true, buffer.equals(TEST_BYTES1)); }