Interface MultiSetIterator<E>

  • Type Parameters:
    E - the class of the elements of this multi-set. Created: Fri Oct 3 21:37:29 2014
    All Superinterfaces:
    java.util.Iterator<E>
    All Known Implementing Classes:
    AbstractMultiSet.MultiSetIteratorImpl

    public interface MultiSetIterator<E>
    extends java.util.Iterator<E>
    Generalization of iterator suitable e.g. for sets to MultiSets. Needed in addition: methods on multiplicity of element read last.

    Not clear whether one should not allow addMult. why not unify addMult and removeMult? This would require a different implementation. Problem is also that MultiSet is not (yet) a collection.

    Version:
    1.0
    Author:
    Ernst Reissner
    • Method Summary

      All Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      int getMult()
      Returns the current multiplicity of the element last read by Iterator.next(), provided that element was not removed in the meantime.
      MultiSet.Multiplicity getMultObj()  
      void remove()
      Removes from the underlying MultiSet the last element returned by Iterator.next(), provided that element was not removed in the meantime and this method is supported by this iterator.
      int removeMult​(int removeMult)
      Removes from the underlying MultiSet the last element returned by invocation of Iterator.next() with multiplicity given by removeMult, provided that element was not removed in the meantime and this method is supported by this iterator.
      int setMult​(int setMult)
      Endows the element of the underlying MultiSet returned by the last invocation of Iterator.next() with multiplicity given by setMult, provided that element was not removed in the meantime and this method is supported by this iterator.
      • Methods inherited from interface java.util.Iterator

        forEachRemaining, hasNext, next
    • Method Detail

      • remove

        void remove()
        Removes from the underlying MultiSet the last element returned by Iterator.next(), provided that element was not removed in the meantime and this method is supported by this iterator.

        Invoking this method removes that element from the set associated with MultiSet. After this, neither setMult(int) nor removeMult(int) nor getMult() may be invoked before next invocation of Iterator.next().

        The behavior of this iterator is unspecified if the underlying MultiSet is modified while the iteration is in progress in any way other than by calling methods of an iterator.

        Specified by:
        remove in interface java.util.Iterator<E>
        Throws:
        java.lang.UnsupportedOperationException - if removing is not supported by this iterator. This is in particular true if the underlying MultiSet is immutable.
        java.lang.IllegalStateException - provided this method is supported by this iterator: if the method Iterator.next() has not yet been called or if, after last invocation of Iterator.next() the element returned by this invocation has been removed from the underlying MultiSet invoking remove(), setMult(int) or removeMult(int) or a combination in an appropriate way.
      • getMult

        int getMult()
        Returns the current multiplicity of the element last read by Iterator.next(), provided that element was not removed in the meantime. This multiplicity could have been modified after last invocation of Iterator.next() by invoking remove(), setMult(int) or removeMult(int). If the multiplicity became zero, this means that it has been completely removed and so its multiplicity cannot be queried any more.
        Returns:
        the multiplicity of the element this method refers to. This is a positive integer.
        Throws:
        java.lang.IllegalStateException - if the method Iterator.next() has not yet been called or if, after last invocation of Iterator.next() the element returned by this invocation has been removed from the underlying MultiSet invoking remove(), setMult(int) or removeMult(int) or a combination in an appropriate way.
      • setMult

        int setMult​(int setMult)
        Endows the element of the underlying MultiSet returned by the last invocation of Iterator.next() with multiplicity given by setMult, provided that element was not removed in the meantime and this method is supported by this iterator.

        For setMult=0, invoking this method removes that element from the set associated with MultiSet. After this, neither setMult(int) nor removeMult(int) nor remove() nor getMult() may be invoked before next invocation of Iterator.next().

        The behavior of this iterator is unspecified if the underlying MultiSet is modified while the iteration is in progress in any way other than by calling methods of an iterator.

        Parameters:
        setMult - a non-negative number signifying the new multiplicity of the element read last by Iterator.next().
        Returns:
        the multiplicity of the element this method refers to before invoking this method.
        Throws:
        java.lang.UnsupportedOperationException - if setting multiplicity is not supported by this iterator. This is in particular true if the underlying MultiSet is immutable.
        java.lang.IllegalStateException - provided this method is supported by this iterator: if the method Iterator.next() has not yet been called or if, after last invocation of Iterator.next() the element returned by this invocation has been removed from the underlying MultiSet invoking remove(), setMult(int) or removeMult(int) or a combination in an appropriate way.
        java.lang.IllegalArgumentException - if setMult is negative and if the abovementioned exceptions are not thrown.
      • removeMult

        int removeMult​(int removeMult)
        Removes from the underlying MultiSet the last element returned by invocation of Iterator.next() with multiplicity given by removeMult, provided that element was not removed in the meantime and this method is supported by this iterator.

        If removeMult is the multiplicity of that element, invoking this method removes that element from the set associated with MultiSet. After this, neither setMult(int) nor remove() nor remove() nor getMult() may be invoked before next invocation of Iterator.next().

        The behavior of this iterator is unspecified if the underlying MultiSet is modified while the iteration is in progress in any way other than by calling methods of an iterator.

        Parameters:
        removeMult - a number signifying the multiplicity which which the current element should be removed. Negative values signify adding that element.
        Returns:
        the multiplicity of the element this method refers to before invoking this method.
        Throws:
        java.lang.UnsupportedOperationException - if removing multiplicity is not supported by this iterator. This is in particular true if the underlying MultiSet is immutable.
        java.lang.IllegalStateException - if the method Iterator.next() has not yet been called or if, after last invocation of Iterator.next() the element returned by this invocation has been removed from the underlying MultiSet invoking remove(), setMult(int) or removeMult(int) or a combination in an appropriate way.
        java.lang.IllegalArgumentException - if removeMult or resulting multiplicity is negative and if the abovementioned exceptions are not thrown.
        See Also:
        remove()