private int getRunLength(T[] array, int firstId, int lastId,
            Comparator<T> comparator) {

        int runEnd = firstId + 1;
        if (runEnd < lastId) {
            // if the range is > 1 we search for the end index of the run
            if (comparator.compare(array[runEnd++], array[firstId]) >= 0) {
                while (runEnd < lastId && comparator.compare(array[runEnd], array[runEnd - 1]) >= 0) {
                    runEnd++;
                }
            } else {
                while (runEnd < lastId && comparator.compare(array[runEnd], array[runEnd - 1]) < 0) {
                    runEnd++;
                }
                // the run's order is descending, it has to be reversed
                // original algorithm returned a descending = 1 value and the
                // reverse was done in the sort method. Looks good to have it here though
                reverseArray(array, firstId, runEnd);
            }

            return runEnd - firstId;
        }
        //runEnd == lastId -> length = 1
        return 1;
    }
Return the length of the run beginning at lastId, in the slice [lastId,
lastId]. firstId &lt; lastId is required on entry. "A run" is the longest
ascending sequence, with

array[0] <= array[1] <= array[2] <= ...

or the longest descending sequence, with

array[0] > array[1] > array[2] > ...

The original algorithm is returning a "descending" boolean that allow the
caller to reverse the array. Here for simplicity we reverse the array
when the run is descending

@param array the array to search for run length
@param firstId index of the first element of the run
@param lastId index+1 of the last element of the run
@param comparator the comparator
@return the length of the run beginning at the specified position in the
specified array
jme3-core/src/main/java/com/jme3/util/ListSort.java