code: private void generateNextCombinationIndices()
      {
          if (remainingCombinations == 0)
          {
              throw new IllegalStateException("There are no combinations remaining.  " +
                                              "Generator must be reset to continue using.");
          }
          else if (remainingCombinations < totalCombinations)
          {
              int i = combinationIndices.length - 1;
              while (combinationIndices[i] == elements.length - combinationIndices.length + i)
              {
                  i--;
              }
              ++combinationIndices[i];
              for (int j = i + 1; j < combinationIndices.length; j++)
              {
                  combinationIndices[j] = combinationIndices[i] + j - i;
              }
          }
          --remainingCombinations;
      }
docs: Generate the indices into the elements array for the next combination. The
  algorithm is from Kenneth H. Rosen, Discrete Mathematics and Its Applications,
  2nd edition (NY: McGraw-Hill, 1991), p. 286.