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/02/12 12:55:23 UTC
jena git commit: Tidy comments and formatting of code.
Repository: jena
Updated Branches:
refs/heads/master 3199dd102 -> e0e8dba47
Tidy comments and formatting of code.
Project: http://git-wip-us.apache.org/repos/asf/jena/repo
Commit: http://git-wip-us.apache.org/repos/asf/jena/commit/e0e8dba4
Tree: http://git-wip-us.apache.org/repos/asf/jena/tree/e0e8dba4
Diff: http://git-wip-us.apache.org/repos/asf/jena/diff/e0e8dba4
Branch: refs/heads/master
Commit: e0e8dba47ec92a7fb2be38a277685b706d0f4f80
Parents: 3199dd1
Author: Andy Seaborne <an...@apache.org>
Authored: Thu Feb 12 11:50:44 2015 +0000
Committer: Andy Seaborne <an...@apache.org>
Committed: Thu Feb 12 11:50:44 2015 +0000
----------------------------------------------------------------------
.../jena/atlas/iterator/IteratorWithBuffer.java | 117 +++++++++----------
.../atlas/iterator/IteratorWithHistory.java | 61 +++++-----
.../jena/atlas/iterator/PushbackIterator.java | 37 +++---
3 files changed, 103 insertions(+), 112 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/jena/blob/e0e8dba4/jena-arq/src/main/java/org/apache/jena/atlas/iterator/IteratorWithBuffer.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/atlas/iterator/IteratorWithBuffer.java b/jena-arq/src/main/java/org/apache/jena/atlas/iterator/IteratorWithBuffer.java
index 5397002..7af9ac8 100644
--- a/jena-arq/src/main/java/org/apache/jena/atlas/iterator/IteratorWithBuffer.java
+++ b/jena-arq/src/main/java/org/apache/jena/atlas/iterator/IteratorWithBuffer.java
@@ -16,126 +16,117 @@
* limitations under the License.
*/
-package org.apache.jena.atlas.iterator;
+package org.apache.jena.atlas.iterator ;
import java.util.ArrayList ;
import java.util.Iterator ;
import java.util.List ;
import java.util.NoSuchElementException ;
-/** Iterator that delays output by N slots so you can react to the output before it's yielded.
- * See also PeekIterator (which predates this code).
- * See also IteratorWithHistory for an iterator that remembers what it has yielded.
+/**
+ * Iterator that delays output by N slots so you can react to the output before
+ * it's yielded. See also {@link PeekIterator} (which predates this code). See also
+ * {@link IteratorWithHistory} for an iterator that remembers what it has yielded.
*
- * @see org.apache.jena.atlas.iterator.PeekIterator
- * @see org.apache.jena.atlas.iterator.PushbackIterator
+ * @see PeekIterator
+ * @see PushbackIterator
* @see IteratorWithHistory
*/
-public class IteratorWithBuffer<T> implements Iterator<T>
-{
- private List<T> lookahead ;
+public class IteratorWithBuffer<T> implements Iterator<T> {
+ private List<T> lookahead ;
private Iterator<T> iter ;
- private int capacity ;
- private boolean innerHasEnded = false ;
-
- public IteratorWithBuffer(Iterator<T> iter, int N)
- {
+ private int capacity ;
+ private boolean innerHasEnded = false ;
+
+ public IteratorWithBuffer(Iterator<T> iter, int N) {
if ( N < 0 )
throw new IllegalArgumentException("Buffering size < 0") ;
this.iter = iter ;
this.lookahead = new ArrayList<>(N) ;
this.capacity = N ;
// Fill the lookahead.
- for ( int i = 0 ; i < N ; i++ )
- {
- if ( ! iter.hasNext() )
- {
+ for ( int i = 0 ; i < N ; i++ ) {
+ if ( !iter.hasNext() ) {
atEndInner() ;
break ;
}
T nextItem = iter.next() ;
- //System.out.println("Fill: "+nextItem) ;
+ // System.out.println("Fill: "+nextItem) ;
lookahead.add(nextItem) ;
}
}
@Override
- public boolean hasNext()
- {
+ public boolean hasNext() {
return lookahead.size() > 0 ;
}
@Override
- public T next()
- {
+ public T next() {
if ( !hasNext() )
throw new NoSuchElementException(this.getClass().getName()) ;
- if ( ! iter.hasNext() )
+ if ( !iter.hasNext() )
atEndInner() ;
-
+
T item = lookahead.remove(0) ;
- //System.out.println("remove: "+item) ;
- if ( iter.hasNext() )
- {
+ // System.out.println("remove: "+item) ;
+ if ( iter.hasNext() ) {
// Should not throw NoSuchElementException.
T nextItem = iter.next() ;
- //System.out.println("add : "+nextItem) ;
+ // System.out.println("add : "+nextItem) ;
lookahead.add(nextItem) ;
}
return item ;
}
@Override
- public void remove()
- { throw new UnsupportedOperationException("remove") ; }
+ public void remove() {
+ throw new UnsupportedOperationException("remove") ;
+ }
- /** Look at elements that will be returned by a subsequnet call of .next().
- * The next element is index 0, then index 1 etc. This operation is valid immediately
- * after the constructor returns.
- * Returns null for no such element (underlying iterator didn't yeild enough elements).
- * Throws IndexOutOfBoundsException if an attempt i smade to go beyond
- * the buffering window.
+ /**
+ * Look at elements that will be returned by a subsequnet call of .next().
+ * The next element is index 0, then index 1 etc. This operation is valid
+ * immediately after the constructor returns. Returns null for no such
+ * element (underlying iterator didn't yeild enough elements). Throws
+ * IndexOutOfBoundsException if an attempt i smade to go beyond the
+ * buffering window.
*/
- public T peek(int idx)
- {
+ public T peek(int idx) {
if ( idx < 0 || idx >= capacity )
- throw new IndexOutOfBoundsException("Index: "+idx) ;
+ throw new IndexOutOfBoundsException("Index: " + idx) ;
if ( idx >= lookahead.size() )
return null ;
- return lookahead.get(idx) ;
+ return lookahead.get(idx) ;
}
-
+
/**
- * Return the current size of the lookahead. This can be used to tell the difference between
- * an iterator returning null and an iterator that is just short.
+ * Return the current size of the lookahead. This can be used to tell the
+ * difference between an iterator returning null and an iterator that is
+ * just short.
*/
- public int currentSize()
- {
+ public int currentSize() {
return lookahead.size() ;
}
-
- /** Set the element to be returned by a subsequent .next().
- * Use with care.
- * The original element to be returned at this position is lost.
+
+ /**
+ * Set the element to be returned by a subsequent .next(). Use with care.
+ * The original element to be returned at this position is lost.
*/
- public void set(int idx, T item)
- {
- lookahead.set(idx, item) ;
+ public void set(int idx, T item) {
+ lookahead.set(idx, item) ;
}
-
+
/** Called when the underlying iterator ends */
- private void atEndInner()
- {
- if (! innerHasEnded )
- {
+ private void atEndInner() {
+ if ( !innerHasEnded ) {
innerHasEnded = true ;
endReachedInner() ;
}
}
-
-
- /** Called, once, at the end of the wrapped iterator.*/
- protected void endReachedInner() { }
-
+
+ /** Called, once, at the end of the wrapped iterator. */
+ protected void endReachedInner() {}
+
}
http://git-wip-us.apache.org/repos/asf/jena/blob/e0e8dba4/jena-arq/src/main/java/org/apache/jena/atlas/iterator/IteratorWithHistory.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/atlas/iterator/IteratorWithHistory.java b/jena-arq/src/main/java/org/apache/jena/atlas/iterator/IteratorWithHistory.java
index 60c519d..b5b800a 100644
--- a/jena-arq/src/main/java/org/apache/jena/atlas/iterator/IteratorWithHistory.java
+++ b/jena-arq/src/main/java/org/apache/jena/atlas/iterator/IteratorWithHistory.java
@@ -24,10 +24,10 @@ import java.util.List ;
import java.util.NoSuchElementException ;
/** Remembers the last N yields.
- * See also IteratorWithBuffer, for an iterator that looks ahead to what it wil yield.
+ * See also {@link IteratorWithBuffer}, for an iterator that looks ahead to what it will yield.
* @see IteratorWithBuffer
- * @see org.apache.jena.atlas.iterator.PeekIterator
- * @see org.apache.jena.atlas.iterator.PushbackIterator
+ * @see PeekIterator
+ * @see PushbackIterator
*/
public class IteratorWithHistory<T> implements Iterator<T>
{
@@ -36,32 +36,33 @@ public class IteratorWithHistory<T> implements Iterator<T>
private int capacity ;
private boolean hasEnded = false ;
- public IteratorWithHistory(Iterator<T> iter, int N)
- {
+ public IteratorWithHistory(Iterator<T> iter, int N) {
this.iter = iter ;
this.history = new ArrayList<>(N) ;
this.capacity = N ;
}
@Override
- public boolean hasNext()
- {
+ public boolean hasNext() {
boolean b = iter.hasNext() ;
- if ( !b )
+ if ( !b )
atEnd() ;
return b ;
}
@Override
- public T next()
- {
+ public T next() {
T item = null ;
- try { item = iter.next() ; }
- catch (NoSuchElementException ex) { atEnd() ; }
+ try {
+ item = iter.next() ;
+ }
+ catch (NoSuchElementException ex) {
+ atEnd() ;
+ }
// Shuffle up, add at bottom.
if ( history.size() >= capacity )
- history.remove(history.size()-1) ;
- history.add(0,item) ;
+ history.remove(history.size() - 1) ;
+ history.add(0, item) ;
return item ;
}
@@ -69,35 +70,35 @@ public class IteratorWithHistory<T> implements Iterator<T>
public void remove()
{ throw new UnsupportedOperationException("remove") ; }
- /** return the previous i'th element returned by next(). 0 means last call of next.
- * History is retained after the end of iteration.
+ /**
+ * return the previous i'th element returned by next(). 0 means last call of
+ * next. History is retained after the end of iteration.
*
- * @return Element or null for no such element (that is for haven't yielded that many elements).
- * @throws IndexOutOfBoundsException if index is negative.
+ * @return Element or null for no such element (that is for haven't yielded
+ * that many elements).
+ * @throws IndexOutOfBoundsException
+ * if index is negative.
*/
- public T getPrevious(int idx)
- {
+ public T getPrevious(int idx) {
if ( idx >= capacity || idx < 0 )
- throw new IndexOutOfBoundsException("Index: "+idx) ;
+ throw new IndexOutOfBoundsException("Index: " + idx) ;
if ( idx >= history.size() )
return null ;
return history.get(idx) ;
}
/**
- * Return the current size of the histiory. This can be used to tell the difference between
- * an iterator returning null and an iterator that is just short.
+ * Return the current size of the histiory. This can be used to tell the
+ * difference between an iterator returning null and an iterator that is
+ * just short.
*/
- public int currentSize()
- {
+ public int currentSize() {
return history.size() ;
}
-
+
/** Called when the underlying iterator ends */
- protected void atEnd()
- {
- if (! hasEnded )
- {
+ protected void atEnd() {
+ if ( !hasEnded ) {
hasEnded = true ;
endReached() ;
}
http://git-wip-us.apache.org/repos/asf/jena/blob/e0e8dba4/jena-arq/src/main/java/org/apache/jena/atlas/iterator/PushbackIterator.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/atlas/iterator/PushbackIterator.java b/jena-arq/src/main/java/org/apache/jena/atlas/iterator/PushbackIterator.java
index 343df8c..355c563 100644
--- a/jena-arq/src/main/java/org/apache/jena/atlas/iterator/PushbackIterator.java
+++ b/jena-arq/src/main/java/org/apache/jena/atlas/iterator/PushbackIterator.java
@@ -16,46 +16,45 @@
* limitations under the License.
*/
-package org.apache.jena.atlas.iterator;
+package org.apache.jena.atlas.iterator ;
import java.util.ArrayDeque ;
import java.util.Deque ;
import java.util.Iterator ;
-public class PushbackIterator<T> implements Iterator<T>
-{
- private Deque<T> items = new ArrayDeque<>() ;
+/** An iterator where you can push items backinto the iterator, to be yielded (LIFO) next time.
+ * @see PeekIterator
+ */
+public class PushbackIterator<T> implements Iterator<T> {
+ private Deque<T> items = new ArrayDeque<>() ;
private Iterator<T> iter ;
- public PushbackIterator(Iterator <T> iter)
- {
- if ( iter == null ) throw new IllegalArgumentException("Wrapped iterator can't be null") ;
+ public PushbackIterator(Iterator<T> iter) {
+ if ( iter == null )
+ throw new IllegalArgumentException("Wrapped iterator can't be null") ;
this.iter = iter ;
}
-
- public void pushback(T item)
- {
+
+ public void pushback(T item) {
items.push(item) ;
}
-
+
@Override
- public boolean hasNext()
- {
- if ( !items.isEmpty() ) return true ;
+ public boolean hasNext() {
+ if ( !items.isEmpty() )
+ return true ;
return iter.hasNext() ;
}
@Override
- public T next()
- {
- if ( !items.isEmpty() )
+ public T next() {
+ if ( !items.isEmpty() )
return items.pop() ;
return iter.next() ;
}
@Override
- public void remove()
- {
+ public void remove() {
// Need to track if last next() was from the stack or not.
throw new UnsupportedOperationException() ;
}