Class PermutationIterator<T>

java.lang.Object
net.sf.colossus.util.PermutationIterator<T>
All Implemented Interfaces:
Iterator<List<T>>

public final class PermutationIterator<T> extends Object implements Iterator<List<T>>
An iterator that returns permutations of the originally passed list. The first permutation is the unmodified list.
  • Field Details

    • permList

      private final List<T> permList
    • pg

      private final PermGen pg
    • foundNext

      private boolean foundNext
    • anyLeft

      private boolean anyLeft
    • first

      private boolean first
    • nextSwap

      private int nextSwap
  • Constructor Details

    • PermutationIterator

      public PermutationIterator(List<T> list)
      Set up a permutation generator for the passed list.
  • Method Details

    • hasNext

      public boolean hasNext()
      hasNext should not change things if called repeatedly, so when it's called we'll lazily evaluate the next permutation, and then keep returning true until next() is called.
      Specified by:
      hasNext in interface Iterator<T>
    • next

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

      public void remove()
      Specified by:
      remove in interface Iterator<T>
    • swap

      private void swap(int lower)
      Swap elements lower and lower + 1 of permList