|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Object | +--org.metasyntactic.utilities.Odometer
This class enumerates all values of an odometer for you. The values
are returned to you as an int[]. In the zeroth place of
the array is the most significant digit.
The class also can act as a permutation generator. The permutations are returned in lexicographic order. For example, if you want to generate all the 3-permutations of the numbers 0-3:
Odometer o = new Odometer(3, 4, true);
while (o.hasMoreElements()) {
System.out.println(ArrayUtilities.toString(o.nextElement()));
}
produces:
{0, 1, 2}
{0, 1, 3}
{0, 2, 1}
{0, 2, 3}
{0, 3, 1}
{0, 3, 2}
{1, 0, 2}
{1, 0, 3}
{1, 2, 0}
{1, 2, 3}
{1, 3, 0}
{1, 3, 2}
{2, 0, 1}
{2, 0, 3}
{2, 1, 0}
{2, 1, 3}
{2, 3, 0}
{2, 3, 1}
{3, 0, 1}
{3, 0, 2}
| Field Summary | |
protected int[] |
odometer
The current states of the odometer. |
protected boolean |
ongoing
We are done when we have generated the last valid odometer setting before a complete rollover |
protected boolean |
permute
Are we generating only valid permutations? Or are we a normal odometer? |
protected int |
rollover
The digit to rollover on. |
| Constructor Summary | |
Odometer(int digits,
int rollover)
Constructs a normal (non-permuting) odometer. |
|
Odometer(int digits,
int rollover,
boolean permute)
|
|
| Method Summary | |
boolean |
hasNext()
|
static void |
main(java.lang.String[] args)
|
java.lang.Object |
next()
|
int[] |
nextPosition()
|
void |
remove()
|
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
protected final int[] odometer
protected final int rollover
protected final boolean permute
protected boolean ongoing
| Constructor Detail |
public Odometer(int digits,
int rollover)
public Odometer(int digits,
int rollover,
boolean permute)
| Method Detail |
public boolean hasNext()
hasNext in interface java.util.Iteratorpublic void remove()
remove in interface java.util.Iteratorpublic java.lang.Object next()
next in interface java.util.Iteratorpublic int[] nextPosition()
public static void main(java.lang.String[] args)
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||