Class SequencedHashMap.OrderedIterator

  • All Implemented Interfaces:
    java.util.Iterator
    Enclosing class:
    SequencedHashMap

    private class SequencedHashMap.OrderedIterator
    extends java.lang.Object
    implements java.util.Iterator
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private long expectedModCount
      Holds the expected modification count.
      private SequencedHashMap.Entry pos
      Holds the "current" position in the iterator.
      private int returnType
      Holds the type that should be returned from the iterator.
    • Constructor Summary

      Constructors 
      Constructor Description
      OrderedIterator​(int returnType)
      Construct an iterator over the sequenced elements in the order in which they were added.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean hasNext()
      Returns whether there is any additional elements in the iterator to be returned.
      java.lang.Object next()
      Returns the next element from the iterator.
      void remove()
      Removes the last element returned from the next() method from the sequenced map.
      • 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

      • returnType

        private int returnType
        Holds the type that should be returned from the iterator. The value should be either SequencedHashMap.KEY, SequencedHashMap.VALUE, or SequencedHashMap.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 by SequencedHashMap.REMOVED_MASK is set), the current position has been removed. If positive, remove can still be called.
      • pos

        private SequencedHashMap.Entry 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 expectedModCount
        Holds the expected modification count. If the actual modification count of the map differs from this value, then a concurrent modification has occurred.
    • Method Detail

      • hasNext

        public boolean hasNext()
        Returns whether there is any additional elements in the iterator to be returned.
        Specified by:
        hasNext in interface java.util.Iterator
        Returns:
        true if there are more elements left to be returned from the iterator; false otherwise.
      • next

        public java.lang.Object next()
        Returns the next element from the iterator.
        Specified by:
        next in interface java.util.Iterator
        Returns:
        the next element from the iterator.
        Throws:
        java.util.NoSuchElementException - if there are no more elements in the iterator.
        java.util.ConcurrentModificationException - if a modification occurs in the underlying map.
      • remove

        public void remove()
        Removes the last element returned from the next() method from the sequenced map.
        Specified by:
        remove in interface java.util.Iterator
        Throws:
        java.lang.IllegalStateException - if there isn't a "last element" to be removed. That is, if next() has never been called, or if remove() was already called on the element.
        java.util.ConcurrentModificationException - if a modification occurs in the underlying map.