code: public Integer[] nextPermutation() {
                  if (permLeft.equals(permTotal)) {
                          permLeft = permLeft.subtract(BigInteger.ONE);
                          return position;
                  }
  
                  // Find largest index j with a[j] < a[j+1]
                  int j = position.length - 2;
                  while (position[j] > position[j + 1]) {
                          j--;
                  }
  
                  // Find index k such that a[k] is smallest integer
                  // greater than a[j] to the right of a[j]
                  int k = position.length - 1;
                  while (position[j] > position[k]) {
                          k--;
                  }
  
                  // Interchange a[j] and a[k]
                  int temp;
                  temp = position[k];
                  position[k] = position[j];
                  position[j] = temp;
  
                  // Put tail end of permutation after j-th position in increasing order
                  int r = position.length - 1;
                  int s = j + 1;
                  while (r > s) {
                          temp = position[s];
                          position[s] = position[r];
                          position[r] = temp;
                          r--;
                          s++;
                  }
  
                  permLeft = permLeft.subtract(BigInteger.ONE);
                  return position;
          }
docs: Generates the next permutation (algorithm from Rosen p. 284)
  
  @return an array containing the next permutation