Interface Enumerator<T>
- Type Parameters:
T- Element type
- All Superinterfaces:
AutoCloseable
- All Known Implementing Classes:
CartesianProductEnumerator,CsvEnumerator,DelegatingEnumerator,GeodeSimpleEnumerator,JsonEnumerator,KafkaMessageEnumerator,MemoryEnumerator,OsQuery,SplunkConnectionImpl.SplunkResultEnumerator,TransformedEnumerator
Analogous to LINQ's System.Collections.Enumerator. Unlike LINQ, if the
underlying collection has been modified it is only optional that an
implementation of the Enumerator interface detects it and throws a
ConcurrentModificationException.
-
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Closes this enumerable and releases resources.current()Gets the current element in the collection.booleanmoveNext()Advances the enumerator to the next element of the collection.voidreset()Sets the enumerator to its initial position, which is before the first element in the collection.
-
Method Details
-
current
T current()Gets the current element in the collection.After an enumerator is created or after the
reset()method is called, themoveNext()method must be called to advance the enumerator to the first element of the collection before reading the value of thecurrentproperty; otherwise,currentis undefined.This method also throws
NoSuchElementExceptionif the last call tomoveNextreturnedfalse, which indicates the end of the collection.This method does not move the position of the enumerator, and consecutive calls to
currentreturn the same object until eithermoveNextorresetis called.An enumerator remains valid as long as the collection remains unchanged. If changes are made to the collection, such as adding, modifying, or deleting elements, the enumerator is irrecoverably invalidated. The next call to
moveNextorresetmay, at the discretion of the implementation, throw aConcurrentModificationException. If the collection is modified betweenmoveNextandcurrent,currentreturns the element that it is set to, even if the enumerator is already invalidated.- Returns:
- Current element
- Throws:
ConcurrentModificationException- if collection has been modifiedNoSuchElementException- ifmoveToNexthas not been called, has not been called since the most recent call toreset, or returned false
-
moveNext
boolean moveNext()Advances the enumerator to the next element of the collection.After an enumerator is created or after the
resetmethod is called, an enumerator is positioned before the first element of the collection, and the first call to themoveNextmethod moves the enumerator over the first element of the collection.If
moveNextpasses the end of the collection, the enumerator is positioned after the last element in the collection andmoveNextreturnsfalse. When the enumerator is at this position, subsequent calls tomoveNextalso returnfalseuntil#resetis called.An enumerator remains valid as long as the collection remains unchanged. If changes are made to the collection, such as adding, modifying, or deleting elements, the enumerator is irrecoverably invalidated. The next call to
moveNextorreset()may, at the discretion of the implementation, throw aConcurrentModificationException.- Returns:
trueif the enumerator was successfully advanced to the next element;falseif the enumerator has passed the end of the collection
-
reset
void reset()Sets the enumerator to its initial position, which is before the first element in the collection.An enumerator remains valid as long as the collection remains unchanged. If changes are made to the collection, such as adding, modifying, or deleting elements, the enumerator is irrecoverably invalidated. The next call to
moveNext()orresetmay, at the discretion of the implementation, throw aConcurrentModificationException.This method is optional; it may throw
UnsupportedOperationException.Notes to Implementers
All calls to Reset must result in the same state for the enumerator. The preferred implementation is to move the enumerator to the beginning of the collection, before the first element. This invalidates the enumerator if the collection has been modified since the enumerator was created, which is consistent with
moveNext()andcurrent(). -
close
void close()Closes this enumerable and releases resources.This method is idempotent. Calling it multiple times has the same effect as calling it once.
- Specified by:
closein interfaceAutoCloseable
-