|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--com.objectwave.utility.Permutations
The Permutations class provides an enumeration of all permutations of an array 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:Object[] children = {“Leonardo”, “Monica”, “Nathan”, “Olivia”};
This will print out:Permutations c = new Permutations(children, 2); while (c.hasMoreElements()) { Object[] perm = (Object[])c.nextElement(); for (int i = 0; i < perm.length; i++) { System.out.print(perm[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 | |
Permutations(java.lang.Object[] inArray)
Create a Permutation to enumerate through all possible lineups of the supplied array of Objects. |
|
Permutations(java.lang.Object[] inArray,
int m)
Create a Permutation to enumerate through all possible lineups of the supplied array of Objects. |
Method Summary | |
boolean |
hasMoreElements()
|
java.lang.Object |
nextElement()
|
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public Permutations(java.lang.Object[] inArray) throws CombinatoricException
CombinatoricException
- Should never happen
with this interfacepublic Permutations(java.lang.Object[] inArray, int m) throws CombinatoricException
inArray
- java.lang.Object[], the group to line upm
- int, the number of objects to use
CombinatoricException
- if m is greater than
the length of inArray, or less than 0.Method Detail |
public boolean hasMoreElements()
hasMoreElements
in interface java.util.Enumeration
public java.lang.Object nextElement()
nextElement
in interface java.util.Enumeration
Actually, an array of Objects is returned. The declaration must say just “Object,” because the Permutations class implements Enumeration, which declares that the “nextElement()” returns a plain Object. Users must cast the returned object to (Object[]).
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |