You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jena.apache.org by an...@apache.org on 2015/06/30 11:41:46 UTC
jena git commit: JENA-966: backport LazyIterator changes
Repository: jena
Updated Branches:
refs/heads/jena2 cba80269f -> 21b5e602e
JENA-966: backport LazyIterator changes
Project: http://git-wip-us.apache.org/repos/asf/jena/repo
Commit: http://git-wip-us.apache.org/repos/asf/jena/commit/21b5e602
Tree: http://git-wip-us.apache.org/repos/asf/jena/tree/21b5e602
Diff: http://git-wip-us.apache.org/repos/asf/jena/diff/21b5e602
Branch: refs/heads/jena2
Commit: 21b5e602e7411735ba22a716f84b136cdb709169
Parents: cba8026
Author: Andy Seaborne <an...@apache.org>
Authored: Tue Jun 30 10:41:39 2015 +0100
Committer: Andy Seaborne <an...@apache.org>
Committed: Tue Jun 30 10:41:39 2015 +0100
----------------------------------------------------------------------
.../hp/hpl/jena/util/iterator/LazyIterator.java | 65 ++++----------------
1 file changed, 13 insertions(+), 52 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/jena/blob/21b5e602/jena-core/src/main/java/com/hp/hpl/jena/util/iterator/LazyIterator.java
----------------------------------------------------------------------
diff --git a/jena-core/src/main/java/com/hp/hpl/jena/util/iterator/LazyIterator.java b/jena-core/src/main/java/com/hp/hpl/jena/util/iterator/LazyIterator.java
index b6c168b..a69d960 100644
--- a/jena-core/src/main/java/com/hp/hpl/jena/util/iterator/LazyIterator.java
+++ b/jena-core/src/main/java/com/hp/hpl/jena/util/iterator/LazyIterator.java
@@ -18,22 +18,20 @@
package com.hp.hpl.jena.util.iterator;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Set;
-
/** An ExtendedIterator that is created lazily.
* This is useful when constructing an iterator is expensive and
* you'd prefer to delay doing it until certain it's actually needed.
* For example, if you have <code>iterator1.andThen(iterator2)</code>
* you could implement iterator2 as a LazyIterator.
* The sequence to be defined is defined by the subclass's definition
- * of create(). That is called exactly once on the first attempt
- * to interact with the LazyIterator.
+ * of {@link #create()}. That is called exactly once on the first attempt
+ * to iterate (i.e. use one of the <code>hasNext</code>, <code>next</code>,
+ * <code>remove</code>, <code>removeNext</code> operations,
+ * maybe indirectly via <code>toList</code>).
*/
-abstract public class LazyIterator<T> implements ExtendedIterator<T> {
+abstract public class LazyIterator<T> extends NiceIterator<T> {
- private ExtendedIterator<T> it=null;
+ private ExtendedIterator<T> it = null;
/** An ExtendedIterator that is created lazily.
* This constructor has very low overhead - the real work is
@@ -60,51 +58,14 @@ abstract public class LazyIterator<T> implements ExtendedIterator<T> {
it.remove();
}
- @Override
- public ExtendedIterator<T> filterKeep(Filter<T> f) {
- lazy();
- return it.filterKeep(f);
- }
-
- @Override
- public ExtendedIterator<T> filterDrop(Filter<T> f) {
- lazy();
- return it.filterDrop(f);
- }
-
- @Override
- public <U> ExtendedIterator<U> mapWith(Map1<T,U> map1) {
- lazy();
- return it.mapWith(map1);
- }
-
- @Override
+ // removeNext() is implemented with next() and remove() so lazy is called.
+
+ @Override
public void close() {
- lazy();
- it.close();
-
- }
-
- @Override
- public T removeNext() {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public <X extends T> ExtendedIterator<T> andThen( Iterator<X> other ) {
- return NiceIterator.andThen(this, other);
- }
-
- @Override
- public List<T> toList() {
- return NiceIterator.asList(this);
- }
-
- @Override
- public Set<T> toSet() {
- return NiceIterator.asSet(this);
- }
-
+ if ( it != null )
+ it.close() ;
+ }
+
private void lazy() {
if (it == null)
it = create();