@Test public void ascendingOrderSort() { Integer[] array = { 5, 4, 3, 2, 1 }; Integer[] sorted = MergeSort.mergeSort(Integer.class, array, ascOrderComparator); assertArrayEquals("Failure => Array returned is not sorted.", sorted, new Integer[] { 1, 2, 3, 4, 5 }); }
public static <T> T[] mergeSort(Class<T> type, T[] array, Comparator<T> comparator) { if (array.length == 0) { @SuppressWarnings("unchecked") T[] toReturn = (T[]) Array.newInstance(type, 0); return toReturn; } T[] sorted = mergeSort(type, array, 0, array.length - 1, comparator); for (int index = 0; index < array.length; index++) { array[index] = sorted[index]; } return sorted; }
MergeSort { public static <T> T[] mergeSort(Class<T> type, T[] array, Comparator<T> comparator) { if (array.length == 0) { @SuppressWarnings("unchecked") T[] toReturn = (T[]) Array.newInstance(type, 0); return toReturn; } T[] sorted = mergeSort(type, array, 0, array.length - 1, comparator); for (int index = 0; index < array.length; index++) { array[index] = sorted[index]; } return sorted; } }
MergeSort { public static <T> T[] mergeSort(Class<T> type, T[] array, Comparator<T> comparator) { if (array.length == 0) { @SuppressWarnings("unchecked") T[] toReturn = (T[]) Array.newInstance(type, 0); return toReturn; } T[] sorted = mergeSort(type, array, 0, array.length - 1, comparator); for (int index = 0; index < array.length; index++) { array[index] = sorted[index]; } return sorted; }  }
MergeSort { public static <T> T[] mergeSort(Class<T> type, T[] array, Comparator<T> comparator) { if (array.length == 0) { @SuppressWarnings("unchecked") T[] toReturn = (T[]) Array.newInstance(type, 0); return toReturn; } T[] sorted = mergeSort(type, array, 0, array.length - 1, comparator); for (int index = 0; index < array.length; index++) { array[index] = sorted[index]; } return sorted; }  static T[] mergeSort(Class<T> type, T[] array,
			Comparator<T> comparator); static T[] merge(Class<T> type, T[] foo, T[] bar,
			Comparator<T> comparator); }
MergeSort { public static <T> T[] mergeSort(Class<T> type, T[] array, Comparator<T> comparator) { if (array.length == 0) { @SuppressWarnings("unchecked") T[] toReturn = (T[]) Array.newInstance(type, 0); return toReturn; } T[] sorted = mergeSort(type, array, 0, array.length - 1, comparator); for (int index = 0; index < array.length; index++) { array[index] = sorted[index]; } return sorted; }  static T[] mergeSort(Class<T> type, T[] array,
			Comparator<T> comparator); static T[] merge(Class<T> type, T[] foo, T[] bar,
			Comparator<T> comparator);  }