Class AbstractWordList.WordListIterator

java.lang.Object
org.passay.dictionary.AbstractWordList.WordListIterator
All Implemented Interfaces:
Iterator<String>
Enclosing class:
AbstractWordList

private class AbstractWordList.WordListIterator extends Object implements Iterator<String>
An iterator over the WordList.

The iteration order can be either sequential, i.e. incrementing an index from 0 to WordList.size() - 1, or following a sequence of medians, i.e. the global median, followed by the median of the left half, the median of the right half, the median of the left half of the left half, etc. (recursively). The sequence of medians enables the creation of a well-balanced search tree from a sorted word list.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected int
    Index of next word in the iterator sequence.
    protected final boolean
    Specifies whether to use medians or sequential order.
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    WordListIterator(boolean useMedians)
    Constructs a word list iterator.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
     
     
    void
     
    (package private) int
    toMedianIndex(int i, int size)
    Returns the i-th element in the sequence of median indices of the given size.

    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 Details

    • medians

      protected final boolean medians
      Specifies whether to use medians or sequential order.
    • index

      protected int index
      Index of next word in the iterator sequence.
  • Constructor Details

    • WordListIterator

      protected WordListIterator(boolean useMedians)
      Constructs a word list iterator.
      Parameters:
      useMedians - specifies whether to iterate in medians order or sequential order
  • Method Details

    • hasNext

      public boolean hasNext()
      Specified by:
      hasNext in interface Iterator<String>
    • remove

      public void remove()
      Specified by:
      remove in interface Iterator<String>
    • next

      public String next()
      Specified by:
      next in interface Iterator<String>
    • toMedianIndex

      int toMedianIndex(int i, int size)
      Returns the i-th element in the sequence of median indices of the given size.
      Parameters:
      i - the index within the median sequence of the element to return
      size - the size of the sequence
      Returns:
      the i-th element in the median indices sequence