Class CartesianProductIterator<T>

java.lang.Object
com.amalgamasimulation.core.combinatorics.CartesianProductIterator<T>
Type Parameters:
T - the type of elements in the input lists and the combinations produced by this iterator
All Implemented Interfaces:
Iterator<List<T>>

public class CartesianProductIterator<T> extends Object implements Iterator<List<T>>
An iterator over all possible combinations (Cartesian product) of the elements from the provided multiple lists of elements of type T, one element from each list. This class provides an iterative approach to generating and traversing each combination, without generating all combinations in memory upfront.

For example, given two lists ["1", "2"] and ["A", "B"], the Cartesian product would be [["1", "A"], ["1", "B"], ["2", "A"], ["2", "B"]].

The elements are generated in the lexicographical order

Author:
Andrey Malykhanov
See Also:
  • Constructor Details

    • CartesianProductIterator

      public CartesianProductIterator(List<? extends List<? extends T>> elementLists)
      Creates a new instance of An iterator over all possible combinations (Cartesian product) of the elements from the provided multiple lists of elements, one element from each list.
      Parameters:
      elementLists - list of lists of elements, from which the combinations are generated
      See Also:
  • Method Details