Class AbstractMultiSet.MultiSetIteratorImpl<T>
- java.lang.Object
-
- eu.simuline.util.AbstractMultiSet.MultiSetIteratorImpl<T>
-
- Type Parameters:
T- the class of the elements of the underlying multi-set.
- All Implemented Interfaces:
MultiSetIterator<T>,Iterator<T>
- Enclosing class:
- AbstractMultiSet<MAP extends Map<T,MultiSet.Multiplicity>,T>
protected static class AbstractMultiSet.MultiSetIteratorImpl<T> extends Object implements MultiSetIterator<T>
A canonical implementation ofMultiSetIteratordefining also the methods modifying the underlyingMultiSet, namelyremove(),setMult(int)andremoveMult(int).
-
-
Field Summary
Fields Modifier and Type Field Description private Iterator<Map.Entry<T,MultiSet.Multiplicity>>entrySetIterAn iterator on the entries of the mapAbstractMultiSet.obj2multassociating each element of the underlyingMultiSetwith its multiplicity.private Map.Entry<T,MultiSet.Multiplicity>lastThe element returned last by invokingnext()in the iteratorentrySetIterornullifnext()has not yet been invoked or the element returned by the last invocation ofnext()has been removed in the meantime invoking a method of this iterator (instance).
-
Constructor Summary
Constructors Constructor Description MultiSetIteratorImpl(MultiSet<T> multiSet)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intgetMult()Returns the current multiplicity of the element last read bynext(), provided that element was not removed in the meantime.MultiSet.MultiplicitygetMultObj()booleanhasNext()Tnext()Returns the next element in the iteration and, as a side effect, setslastwith the mapping of that element to its current multiplicity.voidremove()intremoveMult(int mult)Removes from the underlyingMultiSetthe last element returned by invocation ofIterator.next()with multiplicity given byremoveMult, provided that element was not removed in the meantime and this method is supported by this iterator.intsetMult(int mult)Endows the element of the underlyingMultiSetreturned by the last invocation ofIterator.next()with multiplicity given bysetMult, provided that element was not removed in the meantime and this method is supported by this iterator.-
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
-
entrySetIter
private final Iterator<Map.Entry<T,MultiSet.Multiplicity>> entrySetIter
An iterator on the entries of the mapAbstractMultiSet.obj2multassociating each element of the underlyingMultiSetwith its multiplicity.
-
last
private Map.Entry<T,MultiSet.Multiplicity> last
The element returned last by invokingnext()in the iteratorentrySetIterornullifnext()has not yet been invoked or the element returned by the last invocation ofnext()has been removed in the meantime invoking a method of this iterator (instance).
-
-
Method Detail
-
next
public final T next()
Returns the next element in the iteration and, as a side effect, setslastwith the mapping of that element to its current multiplicity.
-
remove
public final void remove()
Removes from the underlyingMultiSetthe last element returned bynext(), provided that element was not removed in the meantime and this method is supported by this iterator. As a side effect, setslasttonullindicating that this element has been removed.- Specified by:
removein interfaceIterator<T>- Specified by:
removein interfaceMultiSetIterator<T>- Throws:
UnsupportedOperationException- this implementation does not throw the exception but the iterator of an immutable multi set of course do.
-
getMult
public final int getMult()
Returns the current multiplicity of the element last read bynext(), provided that element was not removed in the meantime.- Specified by:
getMultin interfaceMultiSetIterator<T>- Returns:
- the multiplicity of the element this method refers to. This is a positive integer.
-
getMultObj
public final MultiSet.Multiplicity getMultObj()
- Specified by:
getMultObjin interfaceMultiSetIterator<T>
-
setMult
public final int setMult(int mult)
Description copied from interface:MultiSetIteratorEndows the element of the underlyingMultiSetreturned by the last invocation ofIterator.next()with multiplicity given bysetMult, 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 withMultiSet. After this, neitherMultiSetIterator.setMult(int)norMultiSetIterator.removeMult(int)norMultiSetIterator.remove()norMultiSetIterator.getMult()may be invoked before next invocation ofIterator.next().The behavior of this iterator is unspecified if the underlying
MultiSetis modified while the iteration is in progress in any way other than by calling methods of an iterator.- Specified by:
setMultin interfaceMultiSetIterator<T>- Parameters:
mult- a non-negative number signifying the new multiplicity of the element read last byIterator.next().- Returns:
- the multiplicity of the element this method refers to before invoking this method.
- Throws:
UnsupportedOperationException- this implementation does not throw the exception but the iterator of an immutable multi set of course do.
-
removeMult
public final int removeMult(int mult)
Description copied from interface:MultiSetIteratorRemoves from the underlyingMultiSetthe last element returned by invocation ofIterator.next()with multiplicity given byremoveMult, provided that element was not removed in the meantime and this method is supported by this iterator.If
removeMultis the multiplicity of that element, invoking this method removes that element from the set associated withMultiSet. After this, neitherMultiSetIterator.setMult(int)norMultiSetIterator.remove()norMultiSetIterator.remove()norMultiSetIterator.getMult()may be invoked before next invocation ofIterator.next().The behavior of this iterator is unspecified if the underlying
MultiSetis modified while the iteration is in progress in any way other than by calling methods of an iterator.- Specified by:
removeMultin interfaceMultiSetIterator<T>- Parameters:
mult- 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:
UnsupportedOperationException- this implementation does not throw the exception but the iterator of an immutable multi set of course do.- See Also:
MultiSetIterator.remove()
-
-