com.rachum.amir.util.permutation
Class PermutationGenerator<T>

java.lang.Object
  extended by com.rachum.amir.util.permutation.PermutationGenerator<T>
Type Parameters:
T - the type of objects in the permutations
All Implemented Interfaces:
java.lang.Iterable<java.util.List<T>>, java.util.Iterator<java.util.List<T>>

public class PermutationGenerator<T>
extends java.lang.Object
implements java.util.Iterator<java.util.List<T>>, java.lang.Iterable<java.util.List<T>>

Gets a list of objects and allows to either iterate over all the permutations on it or get specific permutation by lexicographic ordering.

Version:
1.0
Author:
Amir Rachum

Constructor Summary
PermutationGenerator(java.util.List<T> list)
           
PermutationGenerator(T... ts)
           
 
Method Summary
 java.util.List<T> get(int index)
           
 boolean hasNext()
           
 java.util.Iterator<java.util.List<T>> iterator()
           
 java.util.List<T> next()
           
 void remove()
           
 int size()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PermutationGenerator

public PermutationGenerator(T... ts)
Parameters:
ts - a list of objects
See Also:
PermutationGenerator(List)

PermutationGenerator

public PermutationGenerator(java.util.List<T> list)
Parameters:
list - a list of objects. The order of the list will define the natural ordering of the objects. i.e., the given list order is considered the first permutation.
See Also:
PermutationGenerator(Object...)
Method Detail

hasNext

public boolean hasNext()
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>>

iterator

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

get

public java.util.List<T> get(int index)
Parameters:
index - the index of the requested permutation, in lexicographic order.
Returns:
the permutation with the specified index.

size

public int size()
Returns:
the number of permutations available.