ByteBufferUtils { public static int basicHashCode(final ByteBuffer byteBuffer) { int hash = 1; int pos = byteBuffer.position(); int limit = byteBuffer.limit(); for(int i = pos; i < limit; ++i) { hash = 31 * hash + byteBuffer.get(i); } return hash; } private  ByteBufferUtils(); static String byteBufferToString(final ByteBuffer byteBuffer); static String byteBufferToHex(final ByteBuffer byteBuffer); static String byteBufferToHexAll(final ByteBuffer byteBuffer); static String byteBufferInfo(final ByteBuffer byteBuffer); static String byteBufferToAllForms(final ByteBuffer byteBuffer); static int compare(final ByteBuffer left, final ByteBuffer right); static int compareAsLong(final ByteBuffer left, final ByteBuffer right); static int compareAsLong(final ByteBuffer left, final int leftPos,
                                   final ByteBuffer right, final int rightPos); static int compareAsInt(final ByteBuffer left, final ByteBuffer right); static int compareAsInt(final ByteBuffer left, final int leftPos,
                                   final ByteBuffer right, final int rightPos); static boolean containsPrefix(final ByteBuffer buffer, final ByteBuffer prefixBuffer); static void copy(final ByteBuffer sourceBuffer, final ByteBuffer destBuffer); static ByteBuffer copyToDirectBuffer(final ByteBuffer input); static long xxHash(final ByteBuffer byteBuffer); static int basicHashCode(final ByteBuffer byteBuffer);  }
@Test void testBasicHashCode() { ByteBuffer byteBuffer1 = ByteBuffer.wrap(new byte[]{0, 0, 1, 2, 3, 4, 5, 0, 0}); byteBuffer1.position(2); byteBuffer1.limit(7); LOGGER.info(ByteBufferUtils.byteBufferInfo(byteBuffer1)); ByteBuffer byteBuffer2 = ByteBuffer.wrap(new byte[]{0, 1, 2, 3, 4, 5, 0, 0}); byteBuffer2.position(1); byteBuffer2.limit(6); LOGGER.info(ByteBufferUtils.byteBufferInfo(byteBuffer2)); int hash1 = ByteBufferUtils.basicHashCode(byteBuffer1); int hash2 = ByteBufferUtils.basicHashCode(byteBuffer2); assertThat(hash1).isEqualTo(hash2); }