Interface SortStrategy

All Known Implementing Classes:
BubbleSortStrategy, HeapSortStrategy, InsertionSortStrategy, MergeSortStrategy, QuickSortStrategy

public interface SortStrategy
Defines the contract for sorting algorithms.
  • Method Summary

    Modifier and Type
    Method
    Description
    default String
    Returns the name of the sorting strategy.
    sort(int[] array)
    Sorts the given integer array and returns profiling metrics.
    default void
    swap(int[] array, int i, int j)
    Swaps two elements at the specified indices within the given array.
  • Method Details

    • sort

      BenchmarkMetric sort(int[] array)
      Sorts the given integer array and returns profiling metrics.
      Parameters:
      array - The array to be sorted. Must not be null.
      Returns:
      A BenchmarkMetric object containing profiling metrics.
      Throws:
      NullPointerException - If the input array is null.
    • name

      default String 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 - if array is null.
      ArrayIndexOutOfBoundsException - if either i or j is out of bounds.