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

        if (firstId == start) {
            start++;
        }

        while (start < lastId) {
            T pivot = array[start];

            //  set left to where start belongs 
            int left = firstId;
            int right = start;

            /* Invariants:
             * pivot >= all in [firstId, left).
             * pivot  < all in [right, start).
             * The second is vacuously true at the start.
             */
            while (left < right) {
                int middle = (left + right) >>> 1;
                if (comparator.compare(pivot, array[middle]) < 0) {
                    right = middle;
                } else {
                    left = middle + 1;
                }
            }

            /*
             * The invariants still hold, so pivot >= all in [firstId, left) and
             * pivot < all in [left, start), so pivot belongs at left.  Note
             * that if there are elements equal to pivot, left points to the
             * first slot after them -- that's why this sort is stable.
             * Slide over to make room.            
             */
            int nbElems = start - left;
            /*
             * Grabbed from the Java7 TimSort, this switch optimizes
             * arraycopy() in case there are only 1 or 2 elements to copy.
             */
            switch (nbElems) {
                case 2:
                    array[left + 2] = array[left + 1];
                case 1:
                    array[left + 1] = array[left];
                    break;
                default:
                    System.arraycopy(array, left, array, left + 1, nbElems);
            }
            array[left] = pivot;
            start++;
        }
    }
Binary sort is the best method for sorting small arrays: it does few
compares, but can do data movement quadratic in the number of elements.
[firstId, lastId] is a contiguous slice of a list, and is sorted via
binary insertion. This sort is stable. On entry, must have firstId <=
start <= lastId, and that [firstId, start) is already sorted (pass start
== firstId if you don't know!).

@param array the array to sort
@param firstId the index of the first element to sort
@param lastId the index+ of the last element to sort
@param start the index of the element to start sorting range.
[firstId,start] is assumed to be already sorted.
@param comparator the comparator
jme3-core/src/main/java/com/jme3/util/ListSort.java