JAL-2029 many-to-many EnsemblCDS-to-Uniprot mappings
[jalview.git] / src / jalview / util / ArrayUtils.java
diff --git a/src/jalview/util/ArrayUtils.java b/src/jalview/util/ArrayUtils.java
new file mode 100644 (file)
index 0000000..92085c3
--- /dev/null
@@ -0,0 +1,27 @@
+package jalview.util;
+
+public class ArrayUtils
+{
+  /**
+   * Reverse the given array 'in situ'
+   * 
+   * @param arr
+   */
+  public static void reverseIntArray(int[] arr)
+  {
+    if (arr != null)
+    {
+      /*
+       * swap [k] with [end-k] up to the half way point in the array
+       * if length is odd, the middle entry is left untouched by the excitement
+       */
+      int last = arr.length - 1;
+      for (int k = 0; k < arr.length / 2; k++)
+      {
+        int temp = arr[k];
+        arr[k] = arr[last - k];
+        arr[last - k] = temp;
+      }
+    }
+  }
+}