class 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;
	}

}