Interface SortStrategy
- All Known Implementing Classes:
BubbleSortStrategy,HeapSortStrategy,InsertionSortStrategy,MergeSortStrategy,QuickSortStrategy
public interface SortStrategy
Defines the contract for sorting algorithms.
-
Method Summary
-
Method Details
-
sort
Sorts the given integer array and returns profiling metrics.- Parameters:
array- The array to be sorted. Must not be null.- Returns:
- A
BenchmarkMetricobject containing profiling metrics. - Throws:
NullPointerException- If the input array is null.
-
name
Returns the name of the sorting strategy.By convention, the name is derived directly from the sort strategy's class name.
- Returns:
- The unique name of the sorting strategy (e.g. "MergeSort").
- Throws:
IllegalStateException- If the class name does not end with "Strategy".
-
swap
default void swap(int[] array, int i, int j) Swaps two elements at the specified indices within the given array.This method assumes a non-null array and valid indices for optimal performance, and therefore omits argument checks.
- Parameters:
array- The array in which the elements are to be swapped.i- The index of one element to be swapped.j- The index of the other element to be swapped.- Throws:
NullPointerException- ifarrayisnull.ArrayIndexOutOfBoundsException- if eitheriorjis out of bounds.
-