common
Class SubsetIterator

java.lang.Object
  extended by common.SubsetIterator
All Implemented Interfaces:
java.util.Iterator

public class SubsetIterator
extends java.lang.Object
implements java.util.Iterator

Class for iterating over all subsets of an ordered set. The subsets are represented by BitSet objects; in fact, the same BitSet object is used to represent each subset in turn. Of course, using this class is only practical for iterating over the subsets of a small set, since the number of subsets of a set of size n is 2^n.


Constructor Summary
SubsetIterator(int n)
          Creates a new SubsetIterator over a set of size n.
 
Method Summary
 boolean hasNext()
          Returns true if the set of size n has a subset that hasn't been returned yet.
static void main(java.lang.String[] args)
           
 java.lang.Object next()
          Returns a BitSet representing a subset that hasn't been returned yet.
 void remove()
          Throws an exception -- removal makes no sense for this iterator.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SubsetIterator

public SubsetIterator(int n)
Creates a new SubsetIterator over a set of size n.

Method Detail

hasNext

public boolean hasNext()
Returns true if the set of size n has a subset that hasn't been returned yet.

Specified by:
hasNext in interface java.util.Iterator

next

public java.lang.Object next()
Returns a BitSet representing a subset that hasn't been returned yet. Note that this modifies the BitSet object that was returned by the previous call to next, so you shouldn't rely on that object remaining stable.

Specified by:
next in interface java.util.Iterator

remove

public void remove()
Throws an exception -- removal makes no sense for this iterator.

Specified by:
remove in interface java.util.Iterator

main

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