This class represents an iterator (implemented in the output port pattern) over all distinct N-tuples, which can be chosen from {@code N} sets of integers. More formally,for {@code N} integer arrays: array1,array2,...,arrayN, this class allows to iterate over all possible integer arrays of the form [i1, i2,...,iN], where all numbers numbers ij are different and i1 is chosen from array1, i2 is chosen from array2 and so on.
Consider the example: int[] a1 = {1, 2, 3}; int[] a2 = {2, 3}; DistinctCombinationsPort dcp = new DistinctCombinationsPort(a1, a2); int[] tuple; while ((tuple = dcp.take()) != null) System.out.println(Arrays.toString(tuple));
This code will produce the following sequence: [1, 2] [1, 3] [2, 3] [3, 2]
This class is implemented via output port pattern and the calculation of the next tuple occurs only on the invocation of {@link #take()}. Note: method {@link #take()} returns the same reference on each invocation.So, if it is needed not only to obtain the information from {@link #take()}, but also save the result, it is necessary to clone the returned array.
@author Dmitry Bolotin
@author Stanislav Poslavsky
@since 1.0