Repository: TheAlgorithms/Java
File: src/main/java/com/thealgorithms/sorts/BitonicSort.java (Java)

Code before:
package com.thealgorithms.sorts;

import java.util.Arrays;

/**
 * BitonicSort class implements the SortAlgorithm interface using the bitonic sort technique.
 */
public class BitonicSort implements SortAlgorithm {
    private enum Direction {
        DESCENDING,
        ASCENDING,
    }

    /**
     * Sorts the given array using the Bitonic Sort algorithm.
     *
     * @param <T> the type of elements in the array, which must implement the Comparable interface
     * @param unsorted the array to be sorted
     * @return the sorted array
     */
    @Override
    public <T extends Comparable<T>> T[] sort(T[] unsorted) {
        if (unsorted == null || unsorted.length == 0) {
            return unsorted;
        }

        final int paddedSize = nextPowerOfTwo(unsorted.length);
        T[] paddedArray = Arrays.copyOf(unsorted, paddedSize);

        // Fill the padded part with a maximum value
        final T maxValue = max(unsorted);
        Arrays.fill(paddedArray, unsorted.length, paddedSize, maxValue);

        bitonicSort(paddedArray, 0, paddedSize, Direction.ASCENDING);
        return Arrays.copyOf(paddedArray, unsorted.length);
    }

    private <T extends Comparable<T>> void bitonicSort(T[] arr, int low, int cnt, Direction dir) {
        if (cnt > 1) {
            final int k = cnt / 2;

            // Sort first half in ascending order
            bitonicSort(arr, low, k, Direction.ASCENDING);

            // Sort second half in descending order
            bitonicSort(arr, low + k, cnt - k, Direction.DESCENDING);

            // Merge the whole sequence in ascending order

Review comment (suggestion):
```suggestion
        if (unsorted.length == 0) {
```

I would be consistent with other implementations of `SortAlgorithm` (by the way: the `null` check could happen there).

Code after:
package com.thealgorithms.sorts;

import java.util.Arrays;
import java.util.function.BiPredicate;

/**
 * BitonicSort class implements the SortAlgorithm interface using the bitonic sort technique.
 */
public class BitonicSort implements SortAlgorithm {
    private enum Direction {
        DESCENDING,
        ASCENDING,
    }

    /**
     * Sorts the given array using the Bitonic Sort algorithm.
     *
     * @param <T> the type of elements in the array, which must implement the Comparable interface
     * @param array the array to be sorted
     * @return the sorted array
     */
    @Override
    public <T extends Comparable<T>> T[] sort(T[] array) {
        if (array.length == 0) {
            return array;
        }

        final int paddedSize = nextPowerOfTwo(array.length);
        T[] paddedArray = Arrays.copyOf(array, paddedSize);

        // Fill the padded part with a maximum value
        final T maxValue = max(array);
        Arrays.fill(paddedArray, array.length, paddedSize, maxValue);

        bitonicSort(paddedArray, 0, paddedSize, Direction.ASCENDING);
        return Arrays.copyOf(paddedArray, array.length);
    }

    private <T extends Comparable<T>> void bitonicSort(final T[] array, final int low, final int cnt, final Direction direction) {
        if (cnt > 1) {
            final int k = cnt / 2;

            // Sort first half in ascending order
            bitonicSort(array, low, k, Direction.ASCENDING);

            // Sort second half in descending order
            bitonicSort(array, low + k, cnt - k, Direction.DESCENDING);