org.pokersource.util
Class NestedLoopEnumeration
java.lang.Object
org.pokersource.util.NestedLoopEnumeration
- All Implemented Interfaces:
- java.util.Enumeration
public class NestedLoopEnumeration
- extends java.lang.Object
- implements java.util.Enumeration
An iterator that steps through an abritrary number of nested loops, each
starting at zero and ending at its own upper limit. Useful when the
number of nested loops is known only at runtime. Example: if the
limits are set to {2, 3, 2}, then the iterator will return the following
values:
{0, 0, 0}
{0, 0, 1}
{0, 1, 0}
{0, 1, 1}
{0, 2, 0}
{0, 2, 1}
{1, 0, 0}
{1, 0, 1}
{1, 1, 0}
{1, 1, 1}
{1, 2, 0}
{1, 2, 1}
- Author:
- Michael Maurer <mjmaurer@yahoo.com>
Constructor Summary |
NestedLoopEnumeration(int[] limits)
Initializes a nested loop iterator with limits.length dimensions. |
Method Summary |
boolean |
hasMoreElements()
|
java.lang.Object |
nextElement()
Return an integer array listing the next loop indices for each
dimension. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
NestedLoopEnumeration
public NestedLoopEnumeration(int[] limits)
- Initializes a nested loop iterator with limits.length dimensions.
- Parameters:
limits
- limits[i] is the upper limit of the ith nested loop (the
loop runs from 0 to limits[i]-1 inclusive)
hasMoreElements
public boolean hasMoreElements()
- Specified by:
hasMoreElements
in interface java.util.Enumeration
nextElement
public java.lang.Object nextElement()
- Return an integer array listing the next loop indices for each
dimension.
- Specified by:
nextElement
in interface java.util.Enumeration
- Returns:
- An object of int[] type; the ith value is the loop variable
for the ith nested loop.
PokerSource Home Page - Learn how you can contribute!