rdblue commented on a change in pull request #2102:
URL: https://github.com/apache/iceberg/pull/2102#discussion_r560332904



##########
File path: core/src/main/java/org/apache/iceberg/util/ArrayUtil.java
##########
@@ -59,4 +68,239 @@ private ArrayUtil() {
       return null;
     }
   }
+
+  /**
+   * This code is borrowed from `org.apache.commons:commons-lang3`.
+   * <p>
+   * Converts an array of object Booleans to primitives.
+   * <p>
+   * This method returns {@code null} for a {@code null} input array.
+   *
+   * @param array  a {@code Boolean} array, may be {@code null}
+   * @return a {@code boolean} array, {@code null} if null array input
+   * @throws NullPointerException if array content is {@code null}
+   */
+  public static boolean[] toPrimitive(final Boolean[] array) {
+    if (array == null) {
+      return null;
+    } else if (array.length == 0) {
+      return EMPTY_BOOLEAN_ARRAY;
+    }
+    final boolean[] result = new boolean[array.length];
+    for (int i = 0; i < array.length; i++) {
+      result[i] = array[i].booleanValue();
+    }
+    return result;
+  }
+
+  /**
+   * This code is borrowed from `org.apache.commons:commons-lang3`.
+   * <p>
+   * Converts an array of object Bytes to primitives.
+   * <p>
+   * This method returns {@code null} for a {@code null} input array.
+   *
+   * @param array  a {@code Byte} array, may be {@code null}
+   * @return a {@code byte} array, {@code null} if null array input
+   * @throws NullPointerException if array content is {@code null}
+   */
+  public static byte[] toPrimitive(final Byte[] array) {
+    if (array == null) {
+      return null;
+    } else if (array.length == 0) {
+      return EMPTY_BYTE_ARRAY;
+    }
+    final byte[] result = new byte[array.length];
+    for (int i = 0; i < array.length; i++) {
+      result[i] = array[i].byteValue();
+    }
+    return result;
+  }
+
+  /**
+   * This code is borrowed from `org.apache.commons:commons-lang3`.
+   * <p>
+   * Converts an array of object Shorts to primitives.
+   * <p>
+   * This method returns {@code null} for a {@code null} input array.
+   *
+   * @param array  a {@code Short} array, may be {@code null}
+   * @return a {@code byte} array, {@code null} if null array input
+   * @throws NullPointerException if array content is {@code null}
+   */
+  public static short[] toPrimitive(final Short[] array) {
+    if (array == null) {
+      return null;
+    } else if (array.length == 0) {
+      return EMPTY_SHORT_ARRAY;
+    }
+    final short[] result = new short[array.length];
+    for (int i = 0; i < array.length; i++) {
+      result[i] = array[i].shortValue();
+    }
+    return result;
+  }
+
+  /**
+   * This code is borrowed from `org.apache.commons:commons-lang3`.
+   * <p>
+   * Converts an array of object Integers to primitives.
+   * <p>
+   * This method returns {@code null} for a {@code null} input array.
+   *
+   * @param array  a {@code Integer} array, may be {@code null}
+   * @return an {@code int} array, {@code null} if null array input
+   * @throws NullPointerException if array content is {@code null}
+   */
+  public static int[] toPrimitive(final Integer[] array) {
+    if (array == null) {
+      return null;
+    } else if (array.length == 0) {
+      return EMPTY_INT_ARRAY;
+    }
+    final int[] result = new int[array.length];
+    for (int i = 0; i < array.length; i++) {
+      result[i] = array[i].intValue();
+    }
+    return result;
+  }
+
+  /**
+   * This code is borrowed from `org.apache.commons:commons-lang3`.
+   * <p>
+   * Converts an array of object Longs to primitives.
+   * <p>
+   * This method returns {@code null} for a {@code null} input array.
+   *
+   * @param array  a {@code Long} array, may be {@code null}
+   * @return a {@code long} array, {@code null} if null array input
+   * @throws NullPointerException if array content is {@code null}
+   */
+  public static long[] toPrimitive(final Long[] array) {
+    if (array == null) {
+      return null;
+    } else if (array.length == 0) {
+      return EMPTY_LONG_ARRAY;
+    }
+    final long[] result = new long[array.length];
+    for (int i = 0; i < array.length; i++) {
+      result[i] = array[i].longValue();
+    }
+    return result;
+  }
+
+  /**
+   * This code is borrowed from `org.apache.commons:commons-lang3`.
+   * <p>
+   * Converts an array of object Floats to primitives.
+   * <p>
+   * This method returns {@code null} for a {@code null} input array.
+   *
+   * @param array  a {@code Float} array, may be {@code null}
+   * @return a {@code float} array, {@code null} if null array input
+   * @throws NullPointerException if array content is {@code null}
+   */
+  public static float[] toPrimitive(final Float[] array) {
+    if (array == null) {
+      return null;
+    } else if (array.length == 0) {
+      return EMPTY_FLOAT_ARRAY;
+    }
+    final float[] result = new float[array.length];
+    for (int i = 0; i < array.length; i++) {
+      result[i] = array[i].floatValue();
+    }
+    return result;
+  }
+
+  /**
+   * This code is borrowed from `org.apache.commons:commons-lang3`.
+   * <p>
+   * Converts an array of object Doubles to primitives.
+   * <p>
+   * This method returns {@code null} for a {@code null} input array.
+   *
+   * @param array  a {@code Double} array, may be {@code null}
+   * @return a {@code double} array, {@code null} if null array input
+   * @throws NullPointerException if array content is {@code null}
+   */
+  public static double[] toPrimitive(final Double[] array) {
+    if (array == null) {
+      return null;
+    } else if (array.length == 0) {
+      return EMPTY_DOUBLE_ARRAY;
+    }
+    final double[] result = new double[array.length];
+    for (int i = 0; i < array.length; i++) {
+      result[i] = array[i].doubleValue();
+    }
+    return result;
+  }
+
+  /**
+   * This code is borrowed from `org.apache.commons:commons-lang3`.

Review comment:
       Could you move this comment so it is the last paragraph? It is important 
to note, but not as important as the usage docs.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to