@Test public void primitiveToWrapper() { assertNull(ArrayUtil.toWrapperIfPrimitive(null)); String[] strArray = ArrayUtil.toWrapperIfPrimitive(new String[0]); assertArrayEquals(new String[0], strArray); Boolean[] booleanArray = ArrayUtil.toWrapperIfPrimitive(new boolean[] {true, false, true}); assertArrayEquals(new Boolean[] {true, false, true}, booleanArray); Character[] charArray = ArrayUtil.toWrapperIfPrimitive(new char[] {'1', '2', '3'}); assertArrayEquals(new Character[] {'1', '2', '3'}, charArray); Byte[] byteArray = ArrayUtil.toWrapperIfPrimitive(new byte[] {1, 2, 3}); assertArrayEquals(new Byte[] {1, 2, 3}, byteArray); Short[] shortArray = ArrayUtil.toWrapperIfPrimitive(new short[] {1, 2, 3}); assertArrayEquals(new Short[] {1, 2, 3}, shortArray); Integer[] intArray = ArrayUtil.toWrapperIfPrimitive(new int[] {1, 2, 3}); assertArrayEquals(new Integer[] {1, 2, 3}, intArray); Long[] longArray = ArrayUtil.toWrapperIfPrimitive(new long[] {1L, 2L, 3L}); assertArrayEquals(new Long[] {1L, 2L, 3L}, longArray); Float[] floatArray = ArrayUtil.toWrapperIfPrimitive(new float[] {1f, 2f, 3f}); assertArrayEquals(new Float[] {1f, 2f, 3f}, floatArray); Double[] doubleArray = ArrayUtil.toWrapperIfPrimitive(new double[] {1d, 2d, 3d}); assertArrayEquals(new Double[] {1d, 2d, 3d}, doubleArray); }
public static <T> T[] toWrapperIfPrimitive(Object froms) { if (froms == null) { return null; } Class<?> type = froms.getClass().getComponentType(); if (!type.isPrimitive()) { return (T[]) froms; } PrimitiveWrapperArray transformTo = PrimitiveWrapperArray.find(froms.getClass()); if (transformTo == null) { return null; } int size = Array.getLength(froms); T[] result = (T[]) Array.newInstance(ClassUtil.getWrapperTypeIfPrimitive(type), size); for (int i = 0; i < size; i++) { T value = (T) Array.get(froms, i); result[i] = value; } return result; }
ArrayUtil { public static <T> T[] toWrapperIfPrimitive(Object froms) { if (froms == null) { return null; } Class<?> type = froms.getClass().getComponentType(); if (!type.isPrimitive()) { return (T[]) froms; } PrimitiveWrapperArray transformTo = PrimitiveWrapperArray.find(froms.getClass()); if (transformTo == null) { return null; } int size = Array.getLength(froms); T[] result = (T[]) Array.newInstance(ClassUtil.getWrapperTypeIfPrimitive(type), size); for (int i = 0; i < size; i++) { T value = (T) Array.get(froms, i); result[i] = value; } return result; } }
ArrayUtil { public static <T> T[] toWrapperIfPrimitive(Object froms) { if (froms == null) { return null; } Class<?> type = froms.getClass().getComponentType(); if (!type.isPrimitive()) { return (T[]) froms; } PrimitiveWrapperArray transformTo = PrimitiveWrapperArray.find(froms.getClass()); if (transformTo == null) { return null; } int size = Array.getLength(froms); T[] result = (T[]) Array.newInstance(ClassUtil.getWrapperTypeIfPrimitive(type), size); for (int i = 0; i < size; i++) { T value = (T) Array.get(froms, i); result[i] = value; } return result; }  }
ArrayUtil { public static <T> T[] toWrapperIfPrimitive(Object froms) { if (froms == null) { return null; } Class<?> type = froms.getClass().getComponentType(); if (!type.isPrimitive()) { return (T[]) froms; } PrimitiveWrapperArray transformTo = PrimitiveWrapperArray.find(froms.getClass()); if (transformTo == null) { return null; } int size = Array.getLength(froms); T[] result = (T[]) Array.newInstance(ClassUtil.getWrapperTypeIfPrimitive(type), size); for (int i = 0; i < size; i++) { T value = (T) Array.get(froms, i); result[i] = value; } return result; }  static boolean isEmpty(T[] arrary); static boolean hasIntersection(T[] from, T[] target); static T[] toWrapperIfPrimitive(Object froms); }
ArrayUtil { public static <T> T[] toWrapperIfPrimitive(Object froms) { if (froms == null) { return null; } Class<?> type = froms.getClass().getComponentType(); if (!type.isPrimitive()) { return (T[]) froms; } PrimitiveWrapperArray transformTo = PrimitiveWrapperArray.find(froms.getClass()); if (transformTo == null) { return null; } int size = Array.getLength(froms); T[] result = (T[]) Array.newInstance(ClassUtil.getWrapperTypeIfPrimitive(type), size); for (int i = 0; i < size; i++) { T value = (T) Array.get(froms, i); result[i] = value; } return result; }  static boolean isEmpty(T[] arrary); static boolean hasIntersection(T[] from, T[] target); static T[] toWrapperIfPrimitive(Object froms);  }