org.pokersource.util

Class NestedLoopEnumeration

Implemented Interfaces:
Enumeration

public class NestedLoopEnumeration
extends java.lang.Object
implements 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()
Object
nextElement()
Return an integer array listing the next loop indices for each dimension.

Constructor Details

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)

Method Details

hasMoreElements

public boolean hasMoreElements()

nextElement

public Object nextElement()
Return an integer array listing the next loop indices for each dimension.
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!