Class PrefixedKeysIterator

java.lang.Object
org.apache.commons.configuration2.PrefixedKeysIterator
All Implemented Interfaces:
Iterator<String>

final class PrefixedKeysIterator extends Object implements Iterator<String>
* A specialized iterator implementation used by AbstractConfiguration to return an iteration over all keys starting with a specified prefix.

This class is basically a stripped-down version of the FilterIterator class of Commons Collections

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private final String
    Stores the prefix delimiter.
    private final Iterator<String>
    Stores the wrapped iterator.
    private String
    Stores the next element in the iteration.
    private boolean
    A flag whether the next element has been calculated.
    private final String
    Stores the prefix.
  • Constructor Summary

    Constructors
    Constructor
    Description
    PrefixedKeysIterator(Iterator<String> wrappedIterator, String keyPrefix)
    Creates a new instance of PrefixedKeysIterator and sets the wrapped iterator and the prefix for the accepted keys.
    PrefixedKeysIterator(Iterator<String> wrappedIterator, String keyPrefix, String prefixDelimiter)
    Creates a new instance of PrefixedKeysIterator and sets the wrapped iterator and the prefix as well as the delimiter for the preix for the accepted keys.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    Returns a flag whether there are more elements in the iteration.
    Returns the next element in the iteration.
    void
    Removes from the underlying collection of the base iterator the last element returned by this iterator.
    private boolean
    Determines the next element in the iteration.

    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

    • iterator

      private final Iterator<String> iterator
      Stores the wrapped iterator.
    • prefix

      private final String prefix
      Stores the prefix.
    • delimiter

      private final String delimiter
      Stores the prefix delimiter. Default delimiter is "."
    • nextElement

      private String nextElement
      Stores the next element in the iteration.
    • nextElementSet

      private boolean nextElementSet
      A flag whether the next element has been calculated.
  • Constructor Details

    • PrefixedKeysIterator

      public PrefixedKeysIterator(Iterator<String> wrappedIterator, String keyPrefix)
      Creates a new instance of PrefixedKeysIterator and sets the wrapped iterator and the prefix for the accepted keys.
      Parameters:
      wrappedIterator - the wrapped iterator
      keyPrefix - the prefix of the allowed keys
    • PrefixedKeysIterator

      public PrefixedKeysIterator(Iterator<String> wrappedIterator, String keyPrefix, String prefixDelimiter)
      Creates a new instance of PrefixedKeysIterator and sets the wrapped iterator and the prefix as well as the delimiter for the preix for the accepted keys.
      Parameters:
      wrappedIterator - the wrapped iterator
      keyPrefix - the prefix of the allowed keys
      prefixDelimiter - the prefix delimiter
      Since:
      2.10.0
  • Method Details

    • hasNext

      public boolean hasNext()
      Returns a flag whether there are more elements in the iteration.
      Specified by:
      hasNext in interface Iterator<String>
      Returns:
      a flag if there is a next element
    • next

      public String next()
      Returns the next element in the iteration. This is the next key that matches the specified prefix.
      Specified by:
      next in interface Iterator<String>
      Returns:
      the next element in the iteration
      Throws:
      NoSuchElementException - if there is no next element
    • remove

      public void remove()
      Removes from the underlying collection of the base iterator the last element returned by this iterator. This method can only be called if next() was called, but not after hasNext(), because the hasNext() call changes the base iterator.
      Specified by:
      remove in interface Iterator<String>
      Throws:
      IllegalStateException - if hasNext() has already been called.
    • setNextElement

      private boolean setNextElement()
      Determines the next element in the iteration. The return value indicates whether such an element can be found.
      Returns:
      a flag whether a next element exists