Skip to content

Commit c824a64

Browse files
author
Thomas Darimont
committed
DATACMNS-650 - Introduced CloseableIterator abstraction as a foundation for streaming of results.
A CloseableIterator abstracts the underlying result with support for releasing the associated resources via close() which can be transparently be used with TRW in Java 7 since Closeable implements AutoCloseable from Java 7 upwards. Original pull request: #116.
1 parent 6a556e4 commit c824a64

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Copyright 2015 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.springframework.data.util;
17+
18+
import java.io.Closeable;
19+
import java.util.Iterator;
20+
21+
/**
22+
* A {@link CloseableIterator} serves as a bridging data structure for the underlying data store specific results that
23+
* can be wrapped in a Java 8 {@link java.util.stream.Stream}.
24+
* <p>
25+
* For convenient usage in an advanced for-loop we the {@code iterator()} method should return {@literal this}.
26+
*
27+
* @author Thomas Darimont
28+
* @param <T>
29+
* @since 1.10
30+
*/
31+
public interface CloseableIterator<T> extends Iterator<T>, Closeable, Iterable<T> {
32+
33+
/**
34+
* Closes this iterator, freeing any resources created.
35+
*/
36+
@Override
37+
void close();
38+
39+
}

0 commit comments

Comments
 (0)