Class PrefixedKeysIterator
java.lang.Object
org.apache.commons.configuration2.PrefixedKeysIterator
* 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 -
Constructor Summary
ConstructorsConstructorDescriptionPrefixedKeysIterator
(Iterator<String> wrappedIterator, String keyPrefix) Creates a new instance ofPrefixedKeysIterator
and sets the wrapped iterator and the prefix for the accepted keys.PrefixedKeysIterator
(Iterator<String> wrappedIterator, String keyPrefix, String prefixDelimiter) Creates a new instance ofPrefixedKeysIterator
and sets the wrapped iterator and the prefix as well as the delimiter for the preix for the accepted keys. -
Method Summary
Modifier and TypeMethodDescriptionboolean
hasNext()
Returns a flag whether there are more elements in the iteration.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
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
Stores the wrapped iterator. -
prefix
Stores the prefix. -
delimiter
Stores the prefix delimiter. Default delimiter is "." -
nextElement
Stores the next element in the iteration. -
nextElementSet
private boolean nextElementSetA flag whether the next element has been calculated.
-
-
Constructor Details
-
PrefixedKeysIterator
Creates a new instance ofPrefixedKeysIterator
and sets the wrapped iterator and the prefix for the accepted keys.- Parameters:
wrappedIterator
- the wrapped iteratorkeyPrefix
- the prefix of the allowed keys
-
PrefixedKeysIterator
public PrefixedKeysIterator(Iterator<String> wrappedIterator, String keyPrefix, String prefixDelimiter) Creates a new instance ofPrefixedKeysIterator
and sets the wrapped iterator and the prefix as well as the delimiter for the preix for the accepted keys.- Parameters:
wrappedIterator
- the wrapped iteratorkeyPrefix
- the prefix of the allowed keysprefixDelimiter
- the prefix delimiter- Since:
- 2.10.0
-
-
Method Details
-
hasNext
public boolean hasNext()Returns a flag whether there are more elements in the iteration. -
next
Returns the next element in the iteration. This is the next key that matches the specified prefix.- Specified by:
next
in interfaceIterator<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 ifnext()
was called, but not afterhasNext()
, because thehasNext()
call changes the base iterator.- Specified by:
remove
in interfaceIterator<String>
- Throws:
IllegalStateException
- ifhasNext()
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
-