Package org.apache.commons.collections
Class SequencedHashMap.OrderedIterator
java.lang.Object
org.apache.commons.collections.SequencedHashMap.OrderedIterator
- All Implemented Interfaces:
Iterator
- Enclosing class:
SequencedHashMap
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate longHolds the expected modification count.private SequencedHashMap.EntryHolds the "current" position in the iterator.private intHolds the type that should be returned from the iterator. -
Constructor Summary
ConstructorsConstructorDescriptionOrderedIterator(int returnType) Construct an iterator over the sequenced elements in the order in which they were added. -
Method Summary
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.util.Iterator
forEachRemaining
-
Field Details
-
returnType
private int returnTypeHolds the type that should be returned from the iterator. The value should be eitherSequencedHashMap.KEY,SequencedHashMap.VALUE, orSequencedHashMap.ENTRY. To save a tiny bit of memory, this field is also used as a marker for when remove has been called on the current object to prevent a second remove on the same element. Essentially, if this value is negative (i.e. the bit specified bySequencedHashMap.REMOVED_MASKis set), the current position has been removed. If positive, remove can still be called. -
pos
Holds the "current" position in the iterator. When pos.next is the sentinel, we've reached the end of the list. -
expectedModCount
private transient long expectedModCountHolds the expected modification count. If the actual modification count of the map differs from this value, then a concurrent modification has occurred.
-
-
Constructor Details
-
OrderedIterator
public OrderedIterator(int returnType) Construct an iterator over the sequenced elements in the order in which they were added. Thenext()method returns the type specified byreturnTypewhich must be eitherSequencedHashMap.KEY,SequencedHashMap.VALUE, orSequencedHashMap.ENTRY.
-
-
Method Details
-
hasNext
public boolean hasNext()Returns whether there is any additional elements in the iterator to be returned. -
next
Returns the next element from the iterator.- Specified by:
nextin interfaceIterator- Returns:
- the next element from the iterator.
- Throws:
NoSuchElementException- if there are no more elements in the iterator.ConcurrentModificationException- if a modification occurs in the underlying map.
-
remove
public void remove()Removes the last element returned from thenext()method from the sequenced map.- Specified by:
removein interfaceIterator- Throws:
IllegalStateException- if there isn't a "last element" to be removed. That is, ifnext()has never been called, or ifremove()was already called on the element.ConcurrentModificationException- if a modification occurs in the underlying map.
-