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 2011/05/25 11:37:35 UTC
svn commit: r1127454 -
/incubator/jena/Jena2/ARQ/trunk/src/org/openjena/atlas/iterator/IteratorSlotted.java
Author: andy
Date: Wed May 25 09:37:35 2011
New Revision: 1127454
URL: http://svn.apache.org/viewvc?rev=1127454&view=rev
Log: (empty)
Modified:
incubator/jena/Jena2/ARQ/trunk/src/org/openjena/atlas/iterator/IteratorSlotted.java
Modified: incubator/jena/Jena2/ARQ/trunk/src/org/openjena/atlas/iterator/IteratorSlotted.java
URL: http://svn.apache.org/viewvc/incubator/jena/Jena2/ARQ/trunk/src/org/openjena/atlas/iterator/IteratorSlotted.java?rev=1127454&r1=1127453&r2=1127454&view=diff
==============================================================================
--- incubator/jena/Jena2/ARQ/trunk/src/org/openjena/atlas/iterator/IteratorSlotted.java (original)
+++ incubator/jena/Jena2/ARQ/trunk/src/org/openjena/atlas/iterator/IteratorSlotted.java Wed May 25 09:37:35 2011
@@ -14,10 +14,14 @@ import com.hp.hpl.jena.sparql.util.Utils
/** An Iterator with a one slot lookahead. */
abstract class IteratorSlotted<T> implements Iterator<T>
{
- // Could move in the async abort part of QueryIterator
+ // Could move in the async abort.
private boolean finished = false ;
- private T slot = null ;
+ private boolean slotIsSet = false ;
+ private T NULL = null ;
+ private T slot = NULL ;
+ private boolean slotIsSet() { return slot != NULL ; }
+
protected IteratorSlotted() { }
// -------- The contract with the subclasses
@@ -29,7 +33,7 @@ abstract class IteratorSlotted<T> implem
/** Can return true here then null from moveToNext() to indicate end. */
protected abstract boolean hasMore() ;
- // altter add a flag to say if null is a legal value.
+ // alter add a flag to say if null is a legal value.
/** Close the iterator. */
protected void closeIterator() { }
@@ -44,8 +48,8 @@ abstract class IteratorSlotted<T> implem
{
if ( finished )
return false ;
- if ( slot != null )
- return false ;
+ if ( slotIsSet() )
+ return true ;
boolean r = hasMore() ;
if ( ! r )
@@ -55,7 +59,9 @@ abstract class IteratorSlotted<T> implem
}
slot = moveToNext() ;
- if ( slot == null )
+ slotIsSet = true ;
+
+ if ( ! slotIsSet() )
{
close() ;
return false ;
@@ -70,16 +76,17 @@ abstract class IteratorSlotted<T> implem
if ( ! hasNext() ) throw new NoSuchElementException(Utils.className(this)) ;
T obj = slot ;
- slot = moveToNext() ;
+ slot = null ;
return obj ;
}
-
+
+ /** Look at the next element - returns null when there is no element */
public final T peek()
{
+ hasNext() ;
return slot ;
}
-
//@Override
public final void remove()
{
@@ -91,6 +98,8 @@ abstract class IteratorSlotted<T> implem
if ( finished )
return ;
closeIterator() ;
+ slotIsSet = false ;
+ slot = NULL ;
finished = true ;
}
}