package common;

import java.util.Comparator;

public class ArrayUtils {
	public static Integer[] autoBox(int[] array) {
		if (array == null) {
			return null;
		}

		Integer[] converted = new Integer[array.length];
		for (int index = 0; index < array.length; index++) {
			converted[index] = array[index];
		}

		return converted;
	}

	public static Character[] autoBox(char[] array) {
		if (array == null) {
			return null;
		}

		Character[] converted = new Character[array.length];
		for (int index = 0; index < array.length; index++) {
			converted[index] = array[index];
		}

		return converted;
	}

	public static void swap(char[] array, int fooIndex, int barIndex) {
		char temp = array[fooIndex];
		array[fooIndex] = array[barIndex];
		array[barIndex] = temp;
	}

	public static void swap(int[] array, int fooIndex, int barIndex) {
		int temp = array[fooIndex];
		array[fooIndex] = array[barIndex];
		array[barIndex] = temp;
	}

	public static void swap(long[] array, int fooIndex, int barIndex) {
		long temp = array[fooIndex];
		array[fooIndex] = array[barIndex];
		array[barIndex] = temp;
	}

	public static <T> void swap(T[] array, int fooIndex, int barIndex) {
		T temp = array[fooIndex];
		array[fooIndex] = array[barIndex];
		array[barIndex] = temp;
	}

	public static int findIndex(int[] array, int value) {
		for (int index = 0; index < array.length; index++) {
			if (array[index] == value) {
				return index;
			}
		}

		return -1;
	}

	public static <T> int findIndex(T[] array, T value, Comparator<T> comparator) {
		for (int index = 0; index < array.length; index++) {
			if (comparator.compare(array[index], value) == 0) {
				return index;
			}
		}

		return -1;
	}

	public static void swap(Integer[][] table, int a, int b, int c, int d) {
		Integer temp = table[a][b];
		table[a][b] = table[c][d];
		table[c][d] = temp;
	}
}

@@ -66,16 +66,66 @@
 Utils %7B%0A
+%09// Converts an integer array into Integer array.%0A
 %09public 
@@ -156,32 +156,32 @@
 (int%5B%5D array) %7B%0A
-
 %09%09if (array == n
@@ -371,32 +371,85 @@
  converted;%0A%09%7D%0A%0A
+%09// Converts a character array into Character array.%0A
 %09public static C
@@ -698,24 +698,65 @@
 verted;%0A%09%7D%0A%0A
+%09// Swaps elements of a character array.%0A
 %09public stat
@@ -902,32 +902,72 @@
 ex%5D = temp;%0A%09%7D%0A%0A
+%09// Swaps elements of an integer array.%0A
 %09public static v
@@ -1107,32 +1107,68 @@
 ex%5D = temp;%0A%09%7D%0A%0A
+%09// Swaps elements of a long array.%0A
 %09public static v
@@ -1310,32 +1310,64 @@
 ex%5D = temp;%0A%09%7D%0A%0A
+%09// Swaps elements of an array.%0A
 %09public static %3C
@@ -1511,24 +1511,207 @@
 = temp;%0A%09%7D%0A%0A
+%09// Searches the given integer array for the occurrence of the value.%0A%09// If the value exists in the array, returns first index of occurrence of%0A%09// the value. Otherwise, returns -1.%0A
 %09public stat
@@ -1877,32 +1877,235 @@
 %09return -1;%0A%09%7D%0A%0A
+%09// Searches the given array for the occurrence of the value using the%0A%09// comparator passed. If the value exists in the array, returns first index%0A%09// of occurrence of the value. Otherwise, returns -1.%0A
 %09public static %3C
@@ -2324,16 +2324,82 @@
 -1;%0A%09%7D%0A%0A
+%09// Swaps the value in table%5Ba%5D%5Bb%5D with the value in table%5Bc%5D%5Bd%5D.%0A
 %09public 

Add comments