/** * Move the index forward a notch. The algorithm finds the rightmost * index element that can be incremented, increments it, and then * changes the elements to the right to each be 1 plus the element on their left. * <p> * For example, if an index of 5 things taken 3 at a time is at {0 3 4}, only the 0 can * be incremented without running out of room. The next index is {1, 1+1, 1+2) or * {1, 2, 3}. This will be followed by {1, 2, 4}, {1, 3, 4}, and {2, 3, 4}. * <p> * The algorithm is from Applied Combinatorics, by Alan Tucker. * */ private void moveIndex() { int i = rightmostIndexBelowMax(); if (i >= 0) { index[i] = index[i] + 1; for (int j = i + 1; j < m; j++) index[j] = index[j - 1]; } else hasMore = false; }