Java class to convert a variable number of for loops to an iterator