Package org.springframework.data.util
Interface CloseableIterator<T>
- Type Parameters:
T
-
- All Superinterfaces:
AutoCloseable
,Closeable
,Iterator<T>
A
CloseableIterator
serves as a bridging data structure for the underlying data store specific results that
can be wrapped in a Java 8 java.util.stream.Stream
. This allows implementations to clean up any
resources they need to keep open to iterate over elements.- Since:
- 1.10
- Author:
- Thomas Darimont, Mark Paluch
-
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
default Spliterator<T>
Create aSpliterator
over the elements provided by thisIterator
.stream()
Return a sequentialStream
with thisIterator
as its source.Methods inherited from interface java.util.Iterator
forEachRemaining, hasNext, next, remove
-
Method Details
-
close
void close()- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
-
spliterator
Create aSpliterator
over the elements provided by thisIterator
. Implementations should document characteristic values reported by the spliterator. Such characteristic values are not required to be reported if the spliterator reportsSpliterator.SIZED
and this collection contains no elements.The default implementation should be overridden by subclasses that can return a more efficient spliterator. To preserve expected laziness behavior for the
stream()
method, spliterators should either have the characteristic ofIMMUTABLE
orCONCURRENT
, or be late-binding.The default implementation does not report a size.
- Returns:
- a
Spliterator
over the elements in thisIterator
. - Since:
- 2.4
-
stream
Return a sequentialStream
with thisIterator
as its source. The resulting stream callsclose()
whenclosed
. The resultingStream
must be closed after use, it can be declared as a resource in atry
-with-resources statement.This method should be overridden when the
spliterator()
method cannot return a spliterator that isIMMUTABLE
,CONCURRENT
, or late-binding. (Seespliterator()
for details.)- Returns:
- a sequential
Stream
over the elements in thisIterator
. - Since:
- 2.4
-