Class ConcurrentReaderHashMap.HashIterator

java.lang.Object
org.codehaus.groovy.runtime.metaclass.ConcurrentReaderHashMap.HashIterator
All Implemented Interfaces:
Enumeration, Iterator
Direct Known Subclasses:
ConcurrentReaderHashMap.KeyIterator, ConcurrentReaderHashMap.ValueIterator
Enclosing class:
ConcurrentReaderHashMap

protected class ConcurrentReaderHashMap.HashIterator extends Object implements Iterator, Enumeration
Walks a snapshot of the bins from last to first. next() returns the current entry unless a subclass overrides returnValueOfNext(). One thread should own an instance. A concurrent removal may be skipped, and the iterator does not throw ConcurrentModificationException.
  • Field Details

    • tab

      protected final ConcurrentReaderHashMap.Entry[] tab
      Bins captured when this iterator was constructed.
    • index

      protected int index
      Next bin index to read. Counts down from the last bin.
    • entry

      Entry currently under consideration, or null when the next step must move to another bin.
    • currentKey

      protected Object currentKey
      Key of the entry hasNext() has already accepted. Null when no element is ready for next().
    • currentValue

      protected Object currentValue
      Value of the entry hasNext() has already accepted. Null when no element is ready for next().
    • lastReturned

      protected ConcurrentReaderHashMap.Entry lastReturned
      Entry most recently returned by next(). Null before the first successful call and again after remove().
  • Constructor Details

    • HashIterator

      protected HashIterator()
      Constructs a new HashIterator over a snapshot of the table.
  • Method Details

    • hasMoreElements

      public boolean hasMoreElements()
      Returns whether there are more elements (Enumeration interface).
      Specified by:
      hasMoreElements in interface Enumeration
      Returns:
      true if there are more elements, false otherwise
    • nextElement

      public Object nextElement()
      Returns the next element (Enumeration interface).
      Specified by:
      nextElement in interface Enumeration
      Returns:
      the next element
      Throws:
      NoSuchElementException - if there are no more elements
    • hasNext

      public boolean hasNext()
      Returns whether there are more elements to iterate over.
      Specified by:
      hasNext in interface Iterator
      Returns:
      true if there are more elements, false otherwise
    • returnValueOfNext

      protected Object returnValueOfNext()
      Returns the value of the next element. This method can be overridden by subclasses to return different values (e.g., just the key or just the value instead of the whole entry).
      Returns:
      the value to return for the next element
    • next

      public Object next()
      Returns the next element in the iteration.
      Specified by:
      next in interface Iterator
      Returns:
      the next element
      Throws:
      NoSuchElementException - if there are no more elements
    • remove

      public void remove()
      Removes the last returned element from the map.
      Specified by:
      remove in interface Iterator
      Throws:
      IllegalStateException - if next() has not been called or remove() has already been called after the last next() call