Class PrefixedKeysIterator

  • All Implemented Interfaces:
    java.util.Iterator<java.lang.String>

    final class PrefixedKeysIterator
    extends java.lang.Object
    implements java.util.Iterator<java.lang.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 java.lang.String delimiter
      Stores the prefix delimiter.
      private java.util.Iterator<java.lang.String> iterator
      Stores the wrapped iterator.
      private java.lang.String nextElement
      Stores the next element in the iteration.
      private boolean nextElementSet
      A flag whether the next element has been calculated.
      private java.lang.String prefix
      Stores the prefix.
    • Constructor Summary

      Constructors 
      Constructor Description
      PrefixedKeysIterator​(java.util.Iterator<java.lang.String> wrappedIterator, java.lang.String keyPrefix)
      Creates a new instance of PrefixedKeysIterator and sets the wrapped iterator and the prefix for the accepted keys.
      PrefixedKeysIterator​(java.util.Iterator<java.lang.String> wrappedIterator, java.lang.String keyPrefix, java.lang.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

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean hasNext()
      Returns a flag whether there are more elements in the iteration.
      java.lang.String next()
      Returns the next element in the iteration.
      void remove()
      Removes from the underlying collection of the base iterator the last element returned by this iterator.
      private boolean setNextElement()
      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 Detail

      • iterator

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

        private final java.lang.String prefix
        Stores the prefix.
      • delimiter

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

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

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

      • PrefixedKeysIterator

        public PrefixedKeysIterator​(java.util.Iterator<java.lang.String> wrappedIterator,
                                    java.lang.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​(java.util.Iterator<java.lang.String> wrappedIterator,
                                    java.lang.String keyPrefix,
                                    java.lang.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 Detail

      • hasNext

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

        public java.lang.String next()
        Returns the next element in the iteration. This is the next key that matches the specified prefix.
        Specified by:
        next in interface java.util.Iterator<java.lang.String>
        Returns:
        the next element in the iteration
        Throws:
        java.util.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 java.util.Iterator<java.lang.String>
        Throws:
        java.lang.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