com.google.gwt.benchmarks.client.impl
Class PermutationIterator

java.lang.Object
  extended by com.google.gwt.benchmarks.client.impl.PermutationIterator
All Implemented Interfaces:
java.util.Iterator<PermutationIterator.Permutation>

public class PermutationIterator
extends java.lang.Object
implements java.util.Iterator<PermutationIterator.Permutation>

Iterates over all the possible permutations available in a list of Iterables.

The simplest way to iterate over the permutations of multiple iterators is in a nested for loop. The PermutationIterator turns that for loop inside out into a single iterator, which enables you to access each permutation in a piecemeal fashion.


Nested Class Summary
static class PermutationIterator.Permutation
          A single permutation of all the iterators.
 
Constructor Summary
PermutationIterator(java.util.List<? extends java.lang.Iterable<?>> iterables)
          Constructs a new PermutationIterator that provides the values for each possible permutation of iterables.
 
Method Summary
 boolean hasNext()
          Returns a new Permutation containing the values of the next permutation.
static void main(java.lang.String[] args)
           
 PermutationIterator.Permutation next()
           
 void remove()
           
 void skipCurrentRange()
          Skips the remaining set of values in the bottom Iterable.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PermutationIterator

public PermutationIterator(java.util.List<? extends java.lang.Iterable<?>> iterables)
Constructs a new PermutationIterator that provides the values for each possible permutation of iterables.

Parameters:
iterables - non-null. Each Iterable must have at least one element. iterables.size() must be > 1 TODO(tobyr) Consider if empty Iterables ever make sense in the context of permutations.
Method Detail

main

public static void main(java.lang.String[] args)

hasNext

public boolean hasNext()
Returns a new Permutation containing the values of the next permutation.

Specified by:
hasNext in interface java.util.Iterator<PermutationIterator.Permutation>
Returns:
a non-null Permutation

next

public PermutationIterator.Permutation next()
Specified by:
next in interface java.util.Iterator<PermutationIterator.Permutation>

remove

public void remove()
Specified by:
remove in interface java.util.Iterator<PermutationIterator.Permutation>

skipCurrentRange

public void skipCurrentRange()
Skips the remaining set of values in the bottom Iterable. This method affects the results of both hasNext() and next().