lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From uschind...@apache.org
Subject svn commit: r1374710 - /lucene/dev/branches/lucene3312/lucene/core/src/java/org/apache/lucene/util/FilterIterator.java
Date Sun, 19 Aug 2012 08:45:25 GMT
Author: uschindler
Date: Sun Aug 19 08:45:25 2012
New Revision: 1374710

URL: http://svn.apache.org/viewvc?rev=1374710&view=rev
Log:
LUCENE-3312: Small refctoring and final field

Modified:
    lucene/dev/branches/lucene3312/lucene/core/src/java/org/apache/lucene/util/FilterIterator.java

Modified: lucene/dev/branches/lucene3312/lucene/core/src/java/org/apache/lucene/util/FilterIterator.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene3312/lucene/core/src/java/org/apache/lucene/util/FilterIterator.java?rev=1374710&r1=1374709&r2=1374710&view=diff
==============================================================================
--- lucene/dev/branches/lucene3312/lucene/core/src/java/org/apache/lucene/util/FilterIterator.java
(original)
+++ lucene/dev/branches/lucene3312/lucene/core/src/java/org/apache/lucene/util/FilterIterator.java
Sun Aug 19 08:45:25 2012
@@ -22,41 +22,40 @@ import java.util.NoSuchElementException;
 
 public abstract class FilterIterator<T> implements Iterator<T> {
   
-  private Iterator<T> iterator;
+  private final Iterator<T> iterator;
   private T next = null;
   private boolean nextIsSet = false;
   
-  protected abstract boolean predicateFunction(T field);
+  protected abstract boolean predicateFunction(T object);
   
   public FilterIterator(Iterator<T> baseIterator) {
     this.iterator = baseIterator;
   }
   
-  public boolean hasNext() {
-    if (nextIsSet) {
-      return true;
-    } else {
-      return setNext();
-    }
+  public final boolean hasNext() {
+    return nextIsSet || setNext();
   }
   
-  public T next() {
-    if (!nextIsSet) {
-      if (!setNext()) {
-        throw new NoSuchElementException();
-      }
+  public final T next() {
+    if (!hasNext()) {
+      throw new NoSuchElementException();
+    }
+    assert nextIsSet;
+    try {
+      return next;
+    } finally {
+      nextIsSet = false;
+      next = null;
     }
-    nextIsSet = false;
-    return next;
   }
   
-  public void remove() {
+  public final void remove() {
     throw new UnsupportedOperationException();
   }
   
   private boolean setNext() {
     while (iterator.hasNext()) {
-      T object = iterator.next();
+      final T object = iterator.next();
       if (predicateFunction(object)) {
         next = object;
         nextIsSet = true;



Mime
View raw message