Class CombinationIterator<T>

java.lang.Object
org.plumelib.util.CombinationIterator<T>
Type Parameters:
T - the type of the elements of the collections
All Implemented Interfaces:
Iterator<List<T>>

public class CombinationIterator<T> extends Object implements Iterator<List<T>>
Given a set of collections, yield each combination that takes one element from each collection. Each tuple has a value from each candidate list. Each combination'slength is the same as the number of input lists.

For instance, given [["a1", "a2"], ["b1"], ["c1", "c2", "c3"]], this class yields in turn:

   ["a1", "b1", "c1"]
   ["a1", "b1", "c2"]
   ["a1", "b1", "c3"]
   ["a2", "b1", "c1"]
   ["a2", "b1", "c2"]
   ["a2", "b1", "c3"]
 
  • Constructor Details

    • CombinationIterator

      public CombinationIterator(Collection<? extends Collection<T>> collectionsOfCandidates)
      Creates a CombinationIterator for lists constructed from the given candidates. Each generated list will be the same length as the given list.
      Parameters:
      collectionsOfCandidates - lists of candidate values for each position in generated lists
  • Method Details

    • hasNext

      @EnsuresNonNullIf(expression="nextValue", result=true) public boolean hasNext(@GuardSatisfied CombinationIterator<T> this)
      Specified by:
      hasNext in interface Iterator<T>
    • next

      public List<T> next(@GuardSatisfied CombinationIterator<T> this)
      Specified by:
      next in interface Iterator<T>
    • remove

      public void remove(@GuardSatisfied CombinationIterator<T> this)
      Specified by:
      remove in interface Iterator<T>