Class DefaultSubsetIterator<T>

  • Type Parameters:
    T - The element class which is iterated.
    All Implemented Interfaces:
    java.util.Iterator<java.util.Set<T>>

    public class DefaultSubsetIterator<T>
    extends SubsetIterator<T>
    Iterates over all subsets of a given sets. The order is given by the increment of a bitset as follows. Let {1,2,3,4} a set where a subsets should be enumerated. Then a bitset 0000 of the same length is initialized. At every next() operation the bitset is incremented in the standard way (0000->0001,... 0101->0110,...) and the set is returned which contains exactly the elements at the indices with 1 in the bitset.
    Author:
    Matthias Thimm
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.util.BitSet currentItem
      The number of the current item as a bit set.
      private java.util.List<T> set
      The set over which subsets are iterated.
    • Constructor Summary

      Constructors 
      Constructor Description
      DefaultSubsetIterator​(java.util.Set<T> set)
      Creates a new subset iterator for the given set.
    • Method Summary

      Modifier and Type Method Description
      boolean hasNext()  
      private java.util.BitSet increment​(java.util.BitSet bitSet)
      Increments the given bit set, returns null if an overflow happens.
      java.util.Set<T> next()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • Methods inherited from interface java.util.Iterator

        forEachRemaining
    • Field Detail

      • set

        private java.util.List<T> set
        The set over which subsets are iterated.
      • currentItem

        private java.util.BitSet currentItem
        The number of the current item as a bit set.
    • Constructor Detail

      • DefaultSubsetIterator

        public DefaultSubsetIterator​(java.util.Set<T> set)
        Creates a new subset iterator for the given set.
        Parameters:
        set - some set.
    • Method Detail

      • hasNext

        public boolean hasNext()
        Specified by:
        hasNext in interface java.util.Iterator<T>
        Specified by:
        hasNext in class SubsetIterator<T>
      • next

        public java.util.Set<T> next()
        Specified by:
        next in interface java.util.Iterator<T>
        Specified by:
        next in class SubsetIterator<T>
      • increment

        private java.util.BitSet increment​(java.util.BitSet bitSet)
        Increments the given bit set, returns null if an overflow happens.
        Parameters:
        bitSet - some bit set.
        Returns:
        the incremented bit set