tkalkirill commented on a change in pull request #602:
URL: https://github.com/apache/ignite-3/pull/602#discussion_r798313676



##########
File path: 
modules/core/src/main/java/org/apache/ignite/internal/util/ArrayUtils.java
##########
@@ -340,9 +316,58 @@ public static boolean nullOrEmpty(boolean[] arr) {
     }
 
     /**
-     * Stub.
+     * Removes an element from an array with decrementing the array itself.
+     *
+     * @param arr Array.
+     * @param idx Index to remove.
+     * @return New array.
      */
-    private ArrayUtils() {
-        // No op.
+    public static <T> T[] remove(T[] arr, int idx) {
+        int len = arr.length;
+
+        assert idx >= 0 && idx < len : idx + " < " + len;
+
+        if (idx == len - 1) {
+            return Arrays.copyOfRange(arr, 0, len - 1);
+        }
+
+        if (idx == 0) {
+            return Arrays.copyOfRange(arr, 1, len);
+        }
+
+        T[] res = (T[]) Array.newInstance(arr.getClass().getComponentType(), 
len - 1);

Review comment:
       Added.

##########
File path: 
modules/core/src/main/java/org/apache/ignite/internal/util/ArrayUtils.java
##########
@@ -340,9 +316,58 @@ public static boolean nullOrEmpty(boolean[] arr) {
     }
 
     /**
-     * Stub.
+     * Removes an element from an array with decrementing the array itself.
+     *
+     * @param arr Array.
+     * @param idx Index to remove.
+     * @return New array.
      */
-    private ArrayUtils() {
-        // No op.
+    public static <T> T[] remove(T[] arr, int idx) {
+        int len = arr.length;
+
+        assert idx >= 0 && idx < len : idx + " < " + len;
+
+        if (idx == len - 1) {
+            return Arrays.copyOfRange(arr, 0, len - 1);
+        }
+
+        if (idx == 0) {
+            return Arrays.copyOfRange(arr, 1, len);
+        }
+
+        T[] res = (T[]) Array.newInstance(arr.getClass().getComponentType(), 
len - 1);
+
+        System.arraycopy(arr, 0, res, 0, idx);
+        System.arraycopy(arr, idx + 1, res, idx, len - idx - 1);
+
+        return res;
+    }
+
+    /**
+     * Removes an element from an array with decrementing the array itself.
+     *
+     * @param arr Array.
+     * @param idx Index to remove.
+     * @return New array.
+     */
+    public static long[] remove(long[] arr, int idx) {
+        int len = arr.length;
+
+        assert idx >= 0 && idx < len : idx + " < " + len;
+
+        if (idx == len - 1) {
+            return Arrays.copyOfRange(arr, 0, len - 1);
+        }
+
+        if (idx == 0) {
+            return Arrays.copyOfRange(arr, 1, len);
+        }
+
+        long[] res = new long[len - 1];

Review comment:
       Added.




-- 
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.

To unsubscribe, e-mail: [email protected]

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


Reply via email to