Final answer:
The InsertionSorter class implements the insertion sort algorithm in Java, with the sort method sorting a Comparable array in place and returning the number of swaps. The array should not be null, and equal values must not be swapped to maintain stability.
Step-by-step explanation:
The student is tasked with creating a public class named InsertionSorter that implements the insertion sort algorithm in Java. This class will have a class method sort which accepts an array of Comparable objects and sorts them in place in ascending order. The method should also return the number of swaps made during the sorting process as an integer. If the input array is null, the method should throw an IllegalArgumentException. Since we are sorting the array in place, we will be modifying the original array directly, without using additional memory for another array.
The insertion sort algorithm should work as follows: it will start with the first element of the array as the sorted part and incrementally take the next element from the unsorted part, moving it backwards through the sorted section until it finds its correct position. It's important to remember that the original problem statement specifies not to swap equal values; this ensures the stability of the sort and the correctness of the implementation with respect to the instructions provided. If two elements are equal, they should maintain their original order.