inf.util
Class TupleEnumerator<E>

java.lang.Object
  extended by inf.util.TupleEnumerator<E>
Type Parameters:
E - the element type of the domain
All Implemented Interfaces:
java.util.Iterator<E[]>

public class TupleEnumerator<E>
extends java.lang.Object
implements java.util.Iterator<E[]>

This class can be used to enumerate all possible tuples of a given length n over a given domain D. The domain must be specified as an array of elements of the parameter type of this class. The tuples are also returned as arrays, where each tuple is an element of Dn. Note that the same array will be reused to enumerate all tuples and a copy must be taken if the values need to be retained. Altogether there will be |D|n tuples.

Author:
Gerhard Wickler

Constructor Summary
TupleEnumerator(E[] domain, int length)
           This constructor creates a new TupleEnumerator for the given domain values in the given array, where each returned tuple has the given length.
 
Method Summary
protected  java.lang.Object clone()
           This class does not support cloning and an Exception will be thrown if this method is called.
 int firstChanged()
           This function can be called after a tuple has been obtained from this TupleEnumerator.
 boolean hasNext()
           Tests whether there are more tuples to be enumerated.
 E[] next()
           This function returns the next tuple.
 void remove()
           This function is not supported and causes an Exception.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TupleEnumerator

public TupleEnumerator(E[] domain,
                       int length)

This constructor creates a new TupleEnumerator for the given domain values in the given array, where each returned tuple has the given length.

Parameters:
domain - the possible values for the components of the tuples
length - the length of the expected tuples
Method Detail

clone

protected java.lang.Object clone()
                          throws java.lang.CloneNotSupportedException

This class does not support cloning and an Exception will be thrown if this method is called.

Overrides:
clone in class java.lang.Object
Returns:
nothing
Throws:
java.lang.CloneNotSupportedException - will be thrown

hasNext

public boolean hasNext()

Tests whether there are more tuples to be enumerated.

Specified by:
hasNext in interface java.util.Iterator<E[]>
Returns:
true iff there are more tuples

next

public E[] next()

This function returns the next tuple. Note that all tuples use the same array and thus the previous tuple is not available after a call to this function.

Specified by:
next in interface java.util.Iterator<E[]>
Returns:
the next tuple to be enumerated

remove

public void remove()

This function is not supported and causes an Exception.

Specified by:
remove in interface java.util.Iterator<E[]>

firstChanged

public int firstChanged()

This function can be called after a tuple has been obtained from this TupleEnumerator. The new tuple will differ from the previous tuple in array positions from the returned value to the end of the array. Array positions before the returned value remain unchanged. For the first tuple the returned value will be 0, indicating that all values have changed.

Returns:
the index of the first element that changed in this tuple (compared to the previous tuple)