Class PermutationIterator<T>

  • All Implemented Interfaces:
    java.util.Iterator<java.util.List<T>>

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

      Constructors 
      Constructor Description
      PermutationIterator​(java.util.List<T> list)
      Set up a permutation generator for the passed list.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      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.
      java.util.List<T> next()  
      void remove()  
      private void swap​(int lower)
      Swap elements lower and lower + 1 of permList
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • Methods inherited from interface java.util.Iterator

        forEachRemaining
    • Field Detail

      • permList

        private final java.util.List<T> permList
      • foundNext

        private boolean foundNext
      • anyLeft

        private boolean anyLeft
      • first

        private boolean first
      • nextSwap

        private int nextSwap
    • Constructor Detail

      • PermutationIterator

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

      • 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 java.util.Iterator<T>
      • next

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

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

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