net.sf.colossus.util
Class PermutationIterator<T>

java.lang.Object
  extended by net.sf.colossus.util.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.


Field Summary
private  boolean anyLeft
           
private  boolean first
           
private  boolean foundNext
           
private  int nextSwap
           
private  java.util.List<T> permList
           
private  PermGen pg
           
 
Constructor Summary
PermutationIterator(java.util.List<T> list)
          Set up a permutation generator for the passed list.
 
Method Summary
 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
 

Field Detail

permList

private final java.util.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 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<java.util.List<T>>

next

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

remove

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

swap

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