public <T extends Comparable<T>> boolean permute(T objects[]) {
        // Pseudocode from Wikipedia
        // Find the largest index k such that a[k] < a[k + 1]. If no such index exists, the permutation is the last
        // permutation.
        int kk = -1, ll = -1, n = objects.length;
        for (int k = 0; k < n - 1; k++) {
            if (objects[k].compareTo(objects[k + 1]) < 0) kk = k;
        }
        if (kk < 0) return false;
    
        // Find the largest index l such that a[k] < a[l]. Since k + 1 is such an index, l is well defined and satisfies
        // k < l.
        for (int l = 0; l < n; l++) {
            if (objects[kk].compareTo(objects[l]) < 0) ll = l;
        }
    
        // Swap a[k] with a[l].
        swap(objects, kk, ll);
    
        // Reverse the sequence from a[k + 1] up to and including the final element a[n].
        int c = 1;
        for (int i = kk + 1; i < n; i++) {
            if (i >= n - c) break;
            swap(objects, i, n - c++);
        }
    
        return true;
    }