@Test public void sorting_random_arrays_should_produce_identical_result_as_java_sort() { Random r = new Random(4234); for (int i = 0; i < 10000; i++) { short[] original = makeRandomArray(r); short[] javaSorted = Arrays.copyOf(original, original.length); short[] customSorted = Arrays.copyOf(original, original.length); PrimitiveArraySorter.sort(customSorted, Short::compare); Arrays.sort(javaSorted); String errorMsg = String.format("%s != %s (before sorting: %s)", Arrays.toString(customSorted), Arrays.toString(javaSorted), Arrays.toString(original)); assertArrayEquals(errorMsg, customSorted, javaSorted); } }
public static void sort(short[] array, ShortComparator comparator) { sort(array, 0, array.length, comparator); }
PrimitiveArraySorter { public static void sort(short[] array, ShortComparator comparator) { sort(array, 0, array.length, comparator); } }
PrimitiveArraySorter { public static void sort(short[] array, ShortComparator comparator) { sort(array, 0, array.length, comparator); } private  PrimitiveArraySorter(); }
PrimitiveArraySorter { public static void sort(short[] array, ShortComparator comparator) { sort(array, 0, array.length, comparator); } private  PrimitiveArraySorter(); static void sort(short[] array, ShortComparator comparator); static void sort(short[] array, int fromIndex, int toIndex, ShortComparator comparator); static boolean sortAndMerge(short[] array, short[] mergeArray, int pivotIndex, int toIndex, ShortComparator comparator); static void merge(short[] array, short[] mergeArray, int pivotIndex, ShortComparator comparator); static void merge(short[] array, short[] mergeArray, int pivotIndex, int toIndex, ShortComparator comparator); }
PrimitiveArraySorter { public static void sort(short[] array, ShortComparator comparator) { sort(array, 0, array.length, comparator); } private  PrimitiveArraySorter(); static void sort(short[] array, ShortComparator comparator); static void sort(short[] array, int fromIndex, int toIndex, ShortComparator comparator); static boolean sortAndMerge(short[] array, short[] mergeArray, int pivotIndex, int toIndex, ShortComparator comparator); static void merge(short[] array, short[] mergeArray, int pivotIndex, ShortComparator comparator); static void merge(short[] array, short[] mergeArray, int pivotIndex, int toIndex, ShortComparator comparator);  }