mirror of https://github.com/apache/lucene.git
LUCENE-3312: Small refctoring and final field
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/branches/lucene3312@1374710 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
36014af614
commit
ca1059f194
|
@ -22,41 +22,40 @@ import java.util.NoSuchElementException;
|
||||||
|
|
||||||
public abstract class FilterIterator<T> implements Iterator<T> {
|
public abstract class FilterIterator<T> implements Iterator<T> {
|
||||||
|
|
||||||
private Iterator<T> iterator;
|
private final Iterator<T> iterator;
|
||||||
private T next = null;
|
private T next = null;
|
||||||
private boolean nextIsSet = false;
|
private boolean nextIsSet = false;
|
||||||
|
|
||||||
protected abstract boolean predicateFunction(T field);
|
protected abstract boolean predicateFunction(T object);
|
||||||
|
|
||||||
public FilterIterator(Iterator<T> baseIterator) {
|
public FilterIterator(Iterator<T> baseIterator) {
|
||||||
this.iterator = baseIterator;
|
this.iterator = baseIterator;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasNext() {
|
public final boolean hasNext() {
|
||||||
if (nextIsSet) {
|
return nextIsSet || setNext();
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
return setNext();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public T next() {
|
public final T next() {
|
||||||
if (!nextIsSet) {
|
if (!hasNext()) {
|
||||||
if (!setNext()) {
|
|
||||||
throw new NoSuchElementException();
|
throw new NoSuchElementException();
|
||||||
}
|
}
|
||||||
}
|
assert nextIsSet;
|
||||||
nextIsSet = false;
|
try {
|
||||||
return next;
|
return next;
|
||||||
|
} finally {
|
||||||
|
nextIsSet = false;
|
||||||
|
next = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void remove() {
|
public final void remove() {
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean setNext() {
|
private boolean setNext() {
|
||||||
while (iterator.hasNext()) {
|
while (iterator.hasNext()) {
|
||||||
T object = iterator.next();
|
final T object = iterator.next();
|
||||||
if (predicateFunction(object)) {
|
if (predicateFunction(object)) {
|
||||||
next = object;
|
next = object;
|
||||||
nextIsSet = true;
|
nextIsSet = true;
|
||||||
|
|
Loading…
Reference in New Issue