![JAR search and dependency download from the Maven repository](/logo.png)
com.nytimes.android.external.cache3.AbstractSequentialIterator Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of cache3 Show documentation
Show all versions of cache3 Show documentation
Store3 is built with RxJava2
package com.nytimes.android.external.cache3;
import java.util.NoSuchElementException;
import javax.annotation.Nullable;
public abstract class AbstractSequentialIterator extends UnmodifiableIterator {
@Nullable
private T nextOrNull;
/**
* Creates a new iterator with the given first element, or, if {@code
* firstOrNull} is null, creates a new empty iterator.
*/
protected AbstractSequentialIterator( T firstOrNull) {
this.nextOrNull = firstOrNull;
}
/**
* Returns the element that follows {@code previous}, or returns {@code null}
* if no elements remain. This method is invoked during each call to
* {@link #next()} in order to compute the result of a future call to
* {@code next()}.
*/
@Nullable
protected abstract T computeNext(T previous);
@Override
public final boolean hasNext() {
return nextOrNull != null;
}
@Nullable
@Override
public final T next() {
if (!hasNext()) {
throw new NoSuchElementException();
}
try {
return nextOrNull;
} finally {
nextOrNull = computeNext(nextOrNull);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy