PlatformDependent { public static boolean equals(byte[] bytes1, int startPos1, byte[] bytes2, int startPos2, int length) { if (!hasUnsafe() || !PlatformDependent0.unalignedAccess()) { return equalsSafe(bytes1, startPos1, bytes2, startPos2, length); } return PlatformDependent0.equals(bytes1, startPos1, bytes2, startPos2, length); } private  PlatformDependent(); static boolean isAndroid(); static boolean isWindows(); static boolean isRoot(); static int javaVersion(); static boolean canEnableTcpNoDelayByDefault(); static boolean hasUnsafe(); static boolean isUnaligned(); static boolean directBufferPreferred(); static long maxDirectMemory(); static boolean hasJavassist(); static File tmpdir(); static int bitMode(); static int addressSize(); static long allocateMemory(long size); static void freeMemory(long address); static void throwException(Throwable t); static ConcurrentMap<K, V> newConcurrentHashMap(); static LongCounter newLongCounter(); static ConcurrentMap<K, V> newConcurrentHashMap(int initialCapacity); static ConcurrentMap<K, V> newConcurrentHashMap(int initialCapacity, float loadFactor); static ConcurrentMap<K, V> newConcurrentHashMap(
            int initialCapacity, float loadFactor, int concurrencyLevel); static ConcurrentMap<K, V> newConcurrentHashMap(Map<? extends K, ? extends V> map); static void freeDirectBuffer(ByteBuffer buffer); static long directBufferAddress(ByteBuffer buffer); static Object getObject(Object object, long fieldOffset); static Object getObjectVolatile(Object object, long fieldOffset); static int getInt(Object object, long fieldOffset); static long objectFieldOffset(Field field); static byte getByte(long address); static short getShort(long address); static int getInt(long address); static long getLong(long address); static byte getByte(byte[] data, int index); static short getShort(byte[] data, int index); static int getInt(byte[] data, int index); static long getLong(byte[] data, int index); static void putOrderedObject(Object object, long address, Object value); static void putByte(long address, byte value); static void putShort(long address, short value); static void putInt(long address, int value); static void putLong(long address, long value); static void putByte(byte[] data, int index, byte value); static void putShort(byte[] data, int index, short value); static void putInt(byte[] data, int index, int value); static void putLong(byte[] data, int index, long value); static void copyMemory(long srcAddr, long dstAddr, long length); static void copyMemory(byte[] src, int srcIndex, long dstAddr, long length); static void copyMemory(long srcAddr, byte[] dst, int dstIndex, long length); static boolean equals(byte[] bytes1, int startPos1, byte[] bytes2, int startPos2, int length); static int hashCodeAscii(byte[] bytes, int startPos, int length); static int hashCodeAscii(CharSequence bytes); static AtomicReferenceFieldUpdater<U, W> newAtomicReferenceFieldUpdater(
            Class<? super U> tclass, String fieldName); static AtomicIntegerFieldUpdater<T> newAtomicIntegerFieldUpdater(
            Class<? super T> tclass, String fieldName); static AtomicLongFieldUpdater<T> newAtomicLongFieldUpdater(
            Class<? super T> tclass, String fieldName); static Queue<T> newMpscQueue(); static Queue<T> newFixedMpscQueue(int capacity); static ClassLoader getClassLoader(final Class<?> clazz); static ClassLoader getContextClassLoader(); static ClassLoader getSystemClassLoader(); static Deque<C> newConcurrentDeque(); static final boolean BIG_ENDIAN_NATIVE_ORDER; }
@Test public void testEquals() { byte[] bytes1 = {'H', 'e', 'l', 'l', 'o', ' ', 'W', 'o', 'r', 'l', 'd'}; byte[] bytes2 = {'H', 'e', 'l', 'l', 'o', ' ', 'W', 'o', 'r', 'l', 'd'}; assertNotSame(bytes1, bytes2); assertTrue(PlatformDependent.equals(bytes1, 0, bytes2, 0, bytes1.length)); assertTrue(PlatformDependent.equals(bytes1, 2, bytes2, 2, bytes1.length - 2)); bytes1 = new byte[] {1, 2, 3, 4, 5, 6}; bytes2 = new byte[] {1, 2, 3, 4, 5, 6, 7}; assertNotSame(bytes1, bytes2); assertFalse(PlatformDependent.equals(bytes1, 0, bytes2, 1, bytes1.length)); assertTrue(PlatformDependent.equals(bytes2, 0, bytes1, 0, bytes1.length)); bytes1 = new byte[] {1, 2, 3, 4}; bytes2 = new byte[] {1, 2, 3, 5}; assertFalse(PlatformDependent.equals(bytes1, 0, bytes2, 0, bytes1.length)); assertTrue(PlatformDependent.equals(bytes1, 0, bytes2, 0, 3)); bytes1 = new byte[] {1, 2, 3, 4}; bytes2 = new byte[] {1, 3, 3, 4}; assertFalse(PlatformDependent.equals(bytes1, 0, bytes2, 0, bytes1.length)); assertTrue(PlatformDependent.equals(bytes1, 2, bytes2, 2, bytes1.length - 2)); bytes1 = new byte[0]; bytes2 = new byte[0]; assertNotSame(bytes1, bytes2); assertTrue(PlatformDependent.equals(bytes1, 0, bytes2, 0, 0)); bytes1 = new byte[100]; bytes2 = new byte[100]; for (int i = 0; i < 100; i++) { bytes1[i] = (byte) i; bytes2[i] = (byte) i; } assertTrue(PlatformDependent.equals(bytes1, 0, bytes2, 0, bytes1.length)); bytes1[50] = 0; assertFalse(PlatformDependent.equals(bytes1, 0, bytes2, 0, bytes1.length)); assertTrue(PlatformDependent.equals(bytes1, 51, bytes2, 51, bytes1.length - 51)); assertTrue(PlatformDependent.equals(bytes1, 0, bytes2, 0, 50)); bytes1 = new byte[]{1, 2, 3, 4, 5}; bytes2 = new byte[]{3, 4, 5}; assertFalse(PlatformDependent.equals(bytes1, 0, bytes2, 0, bytes2.length)); assertTrue(PlatformDependent.equals(bytes1, 2, bytes2, 0, bytes2.length)); assertTrue(PlatformDependent.equals(bytes2, 0, bytes1, 2, bytes2.length)); for (int i = 0; i < 1000; ++i) { bytes1 = new byte[i]; r.nextBytes(bytes1); bytes2 = bytes1.clone(); assertTrue(PlatformDependent.equals(bytes1, 0, bytes2, 0, bytes1.length)); } }