@Test public void testArrayEquals() { assertTrue(Arrays2.arrayEquals(new int[]{1, 2, 3}, new int[]{1, 2, 3})); assertFalse(Arrays2.arrayEquals(new int[]{1, 2, 3}, new int[]{1, 2})); }
public static <T> boolean arrayEquals(T oldValue, T newValue) { if (isArray(oldValue) && isArray(newValue) && oldValue.getClass().getComponentType().equals(newValue.getClass().getComponentType())) { Class<?> type = oldValue.getClass().getComponentType(); if (type.equals(long.class)) { return Arrays.equals((long[]) oldValue, (long[]) newValue); } else if (type.equals(int.class)) { return Arrays.equals((int[]) oldValue, (int[]) newValue); } else if (type.equals(short.class)) { return Arrays.equals((short[]) oldValue, (short[]) newValue); } else if (type.equals(char.class)) { return Arrays.equals((char[]) oldValue, (char[]) newValue); } else if (type.equals(byte.class)) { return Arrays.equals((byte[]) oldValue, (byte[]) newValue); } else if (type.equals(boolean.class)) { return Arrays.equals((boolean[]) oldValue, (boolean[]) newValue); } else if (type.equals(double.class)) { return Arrays.equals((double[]) oldValue, (double[]) newValue); } else if (type.equals(float.class)) { return Arrays.equals((float[]) oldValue, (float[]) newValue); } else { return Arrays.equals((Object[]) oldValue, (Object[]) newValue); } } return false; }
Arrays2 { public static <T> boolean arrayEquals(T oldValue, T newValue) { if (isArray(oldValue) && isArray(newValue) && oldValue.getClass().getComponentType().equals(newValue.getClass().getComponentType())) { Class<?> type = oldValue.getClass().getComponentType(); if (type.equals(long.class)) { return Arrays.equals((long[]) oldValue, (long[]) newValue); } else if (type.equals(int.class)) { return Arrays.equals((int[]) oldValue, (int[]) newValue); } else if (type.equals(short.class)) { return Arrays.equals((short[]) oldValue, (short[]) newValue); } else if (type.equals(char.class)) { return Arrays.equals((char[]) oldValue, (char[]) newValue); } else if (type.equals(byte.class)) { return Arrays.equals((byte[]) oldValue, (byte[]) newValue); } else if (type.equals(boolean.class)) { return Arrays.equals((boolean[]) oldValue, (boolean[]) newValue); } else if (type.equals(double.class)) { return Arrays.equals((double[]) oldValue, (double[]) newValue); } else if (type.equals(float.class)) { return Arrays.equals((float[]) oldValue, (float[]) newValue); } else { return Arrays.equals((Object[]) oldValue, (Object[]) newValue); } } return false; } }
Arrays2 { public static <T> boolean arrayEquals(T oldValue, T newValue) { if (isArray(oldValue) && isArray(newValue) && oldValue.getClass().getComponentType().equals(newValue.getClass().getComponentType())) { Class<?> type = oldValue.getClass().getComponentType(); if (type.equals(long.class)) { return Arrays.equals((long[]) oldValue, (long[]) newValue); } else if (type.equals(int.class)) { return Arrays.equals((int[]) oldValue, (int[]) newValue); } else if (type.equals(short.class)) { return Arrays.equals((short[]) oldValue, (short[]) newValue); } else if (type.equals(char.class)) { return Arrays.equals((char[]) oldValue, (char[]) newValue); } else if (type.equals(byte.class)) { return Arrays.equals((byte[]) oldValue, (byte[]) newValue); } else if (type.equals(boolean.class)) { return Arrays.equals((boolean[]) oldValue, (boolean[]) newValue); } else if (type.equals(double.class)) { return Arrays.equals((double[]) oldValue, (double[]) newValue); } else if (type.equals(float.class)) { return Arrays.equals((float[]) oldValue, (float[]) newValue); } else { return Arrays.equals((Object[]) oldValue, (Object[]) newValue); } } return false; } private  Arrays2(); }
Arrays2 { public static <T> boolean arrayEquals(T oldValue, T newValue) { if (isArray(oldValue) && isArray(newValue) && oldValue.getClass().getComponentType().equals(newValue.getClass().getComponentType())) { Class<?> type = oldValue.getClass().getComponentType(); if (type.equals(long.class)) { return Arrays.equals((long[]) oldValue, (long[]) newValue); } else if (type.equals(int.class)) { return Arrays.equals((int[]) oldValue, (int[]) newValue); } else if (type.equals(short.class)) { return Arrays.equals((short[]) oldValue, (short[]) newValue); } else if (type.equals(char.class)) { return Arrays.equals((char[]) oldValue, (char[]) newValue); } else if (type.equals(byte.class)) { return Arrays.equals((byte[]) oldValue, (byte[]) newValue); } else if (type.equals(boolean.class)) { return Arrays.equals((boolean[]) oldValue, (boolean[]) newValue); } else if (type.equals(double.class)) { return Arrays.equals((double[]) oldValue, (double[]) newValue); } else if (type.equals(float.class)) { return Arrays.equals((float[]) oldValue, (float[]) newValue); } else { return Arrays.equals((Object[]) oldValue, (Object[]) newValue); } } return false; } private  Arrays2(); static void copy(final double[] sourceArray,
            final double[] destinationArray, final int length); static void reverse(final double[] array); static void reverse(final double[] array, final int start, final int n); static void reverse(final int[] array); static void reverse(final int[] array, final int start, final int n); static void reverse(final Object[] array); static void reverse(final Object[] array, final int start, final int n); static void swap(double array[], int a, int b); static void swap(int array[], int a, int b); static void swap(Object array[], int a, int b); static boolean isNullOrEmpty(Object[] array); static boolean isNullOrEmpty(double[] array); static boolean isNullOrEmpty(int[] array); static T[] copyOf(T[] original); static T[] concat(T[] first, T[] second); static double[] concat(double[]... arrays); static double[] compact(final double[] array); static void shift(double[] array, int shiftsize); static void shift(double[] array, int shiftsize, int fromIndex, int toIndex); static boolean isArray(Object o); static boolean arrayEquals(T oldValue, T newValue); static List<T> unmodifiableList(T... array); }
Arrays2 { public static <T> boolean arrayEquals(T oldValue, T newValue) { if (isArray(oldValue) && isArray(newValue) && oldValue.getClass().getComponentType().equals(newValue.getClass().getComponentType())) { Class<?> type = oldValue.getClass().getComponentType(); if (type.equals(long.class)) { return Arrays.equals((long[]) oldValue, (long[]) newValue); } else if (type.equals(int.class)) { return Arrays.equals((int[]) oldValue, (int[]) newValue); } else if (type.equals(short.class)) { return Arrays.equals((short[]) oldValue, (short[]) newValue); } else if (type.equals(char.class)) { return Arrays.equals((char[]) oldValue, (char[]) newValue); } else if (type.equals(byte.class)) { return Arrays.equals((byte[]) oldValue, (byte[]) newValue); } else if (type.equals(boolean.class)) { return Arrays.equals((boolean[]) oldValue, (boolean[]) newValue); } else if (type.equals(double.class)) { return Arrays.equals((double[]) oldValue, (double[]) newValue); } else if (type.equals(float.class)) { return Arrays.equals((float[]) oldValue, (float[]) newValue); } else { return Arrays.equals((Object[]) oldValue, (Object[]) newValue); } } return false; } private  Arrays2(); static void copy(final double[] sourceArray,
            final double[] destinationArray, final int length); static void reverse(final double[] array); static void reverse(final double[] array, final int start, final int n); static void reverse(final int[] array); static void reverse(final int[] array, final int start, final int n); static void reverse(final Object[] array); static void reverse(final Object[] array, final int start, final int n); static void swap(double array[], int a, int b); static void swap(int array[], int a, int b); static void swap(Object array[], int a, int b); static boolean isNullOrEmpty(Object[] array); static boolean isNullOrEmpty(double[] array); static boolean isNullOrEmpty(int[] array); static T[] copyOf(T[] original); static T[] concat(T[] first, T[] second); static double[] concat(double[]... arrays); static double[] compact(final double[] array); static void shift(double[] array, int shiftsize); static void shift(double[] array, int shiftsize, int fromIndex, int toIndex); static boolean isArray(Object o); static boolean arrayEquals(T oldValue, T newValue); static List<T> unmodifiableList(T... array); static final String[] EMPTY_STRING_ARRAY; static final int[] EMPTY_INT_ARRAY; static final long[] EMPTY_LONG_ARRAY; static final double[] EMPTY_DOUBLE_ARRAY; static final boolean[] EMPTY_BOOLEAN_ARRAY; }