Package org.jbpt.mining
Class Permutations<E>
- java.lang.Object
-
- org.jbpt.mining.Permutations<E>
-
- All Implemented Interfaces:
java.util.Iterator<java.util.List<E>>
public class Permutations<E> extends java.lang.Object implements java.util.Iterator<java.util.List<E>>http://code.google.com/p/google-collections/ Apache License 2.0 The Permutations class provides an iteration of all permutations of an list of objects. Each permutation is simply an ordered list of the group.For example, to see all of the ways we can select a school representative and an alternate from a list of 4 children, begin with an array of names::
To see all 2-permutations of these 4 names, create and use a Permutations enumeration:Listchildren = Collections.asList({Leonardo, Monica, Nathan, Olivia});
This will print out:Permutations
c = new Permutations (children, 2); while (c.hasNext()) { List perm = c.next(); for (int i = 0; i < perm.size(); i++) { System.out.print(perm.get(i) + ); } System.out.println(); } Leonardo Monica Leonardo Nathan Leonardo Olivia Monica Leonardo Monica Nathan Monica Olivia Nathan Leonardo Nathan Monica Nathan Olivia Olivia Leonardo Olivia Monica Olivia Nathan
-
-
Constructor Summary
Constructors Constructor Description Permutations(java.util.List<E> inList)Create a Permutation to iterate through all possible lineups of the supplied array of Objects.Permutations(java.util.List<E> inList, int m)Create a Permutation to iterate through all possible lineups of the supplied array of Objects.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanhasNext()java.util.List<E>next()voidremove()
-
-
-
Constructor Detail
-
Permutations
public Permutations(java.util.List<E> inList)
Create a Permutation to iterate through all possible lineups of the supplied array of Objects.- Parameters:
Object- [] inArray the group to line up- Throws:
CombinatoricException- Should never happen with this interface
-
Permutations
public Permutations(java.util.List<E> inList, int m)
Create a Permutation to iterate through all possible lineups of the supplied array of Objects.- Parameters:
Object- [] inArray the group to line upinArray- java.lang.Object[], the group to line upm- int, the number of objects to use- Throws:
CombinatoricException- if m is greater than the length of inArray, or less than 0.
-
-
Method Detail
-
hasNext
public boolean hasNext()
- Specified by:
hasNextin interfacejava.util.Iterator<E>- Returns:
- true, unless we have already returned the last permutation.
-
next
public java.util.List<E> next()
- Specified by:
nextin interfacejava.util.Iterator<E>- Returns:
- java.lang.Object, the next permutation of the original Object array.
Actually, an array of Objects is returned. The declaration must say just Object, because the Permutations class implements Iterator, which declares that the next() returns a plain Object. Users must cast the returned object to (Object[]).
-
remove
public void remove()
- Specified by:
removein interfacejava.util.Iterator<E>
-
-