Skip to content

Commit

Permalink
GH-4359 remove iteration interface 2 (#4672)
Browse files Browse the repository at this point in the history
  • Loading branch information
hmottestad authored Jul 23, 2023
2 parents 16792d1 + 0ea048f commit d9d5b19
Show file tree
Hide file tree
Showing 354 changed files with 1,569 additions and 1,943 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* Instances of this class is not safe to be accessed from multiple threads at the same time.
*/
@Deprecated(since = "4.1.0")
public abstract class AbstractCloseableIteration<E, X extends Exception> implements CloseableIteration<E, X> {
public abstract class AbstractCloseableIteration<E> implements CloseableIteration<E> {

/*-----------*
* Variables *
Expand Down Expand Up @@ -46,7 +46,7 @@ public final boolean isClosed() {
* Calls {@link #handleClose()} upon first call and makes sure the resource closures are only executed once.
*/
@Override
public final void close() throws X {
public final void close() {
if (!closed) {
closed = true;
handleClose();
Expand All @@ -59,6 +59,6 @@ public final void close() throws X {
*
* @throws X
*/
protected void handleClose() throws X {
protected void handleClose() {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@

package org.eclipse.rdf4j.common.iteration;

import java.util.Iterator;
import java.util.stream.Stream;

/**
* An {@link Iteration} that can be closed to free resources that it is holding. CloseableIterations automatically free
* their resources when exhausted. If not read until exhaustion or if you want to make sure the iteration is properly
* closed, any code using the iterator should be placed in a try-with-resources block, closing the iteration
* automatically, e.g.:
* An {@link CloseableIteration} that can be closed to free resources that it is holding. CloseableIterations
* automatically free their resources when exhausted. If not read until exhaustion or if you want to make sure the
* iteration is properly closed, any code using the iterator should be placed in a try-with-resources block, closing the
* iteration automatically, e.g.:
*
* <pre>
*
Expand All @@ -29,13 +30,13 @@
* }
* </pre>
*
* @deprecated In the future this interface will stop extending {@link Iteration} and instead declare the same interface
* methods directly. The interface will also stop requiring implementations to automatically close when
* exhausted, instead making this an optional feature and requiring the user to always call close. This
* @deprecated In the future this interface will stop extending {@link CloseableIteration} and instead declare the same
* interface methods directly. The interface will also stop requiring implementations to automatically close
* when exhausted, instead making this an optional feature and requiring the user to always call close. This
* interface may also be removed.
*/
@Deprecated(since = "4.1.0")
public interface CloseableIteration<E, X extends Exception> extends Iteration<E, X>, AutoCloseable {
public interface CloseableIteration<E> extends Iterator<E>, AutoCloseable {

/**
* Convert the results to a Java 8 Stream.
Expand All @@ -51,6 +52,6 @@ default Stream<E> stream() {
* invoking this method has no effect.
*/
@Override
void close() throws X;
void close();

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
/**
* A {@link Spliterator} implementation that wraps a {@link CloseableIteration}.
*/
class CloseableIterationSpliterator<T, E extends Exception> extends Spliterators.AbstractSpliterator<T> {
class CloseableIterationSpliterator<T> extends Spliterators.AbstractSpliterator<T> {

private final CloseableIteration<T, E> iteration;
private final CloseableIteration<T> iteration;

/**
* Creates a {@link Spliterator} implementation that wraps the supplied {@link CloseableIteration}. It handles
Expand All @@ -30,7 +30,7 @@ class CloseableIterationSpliterator<T, E extends Exception> extends Spliterators
*
* @param iteration the iteration to wrap
*/
public CloseableIterationSpliterator(CloseableIteration<T, E> iteration) {
public CloseableIterationSpliterator(CloseableIteration<T> iteration) {
super(Long.MAX_VALUE, Spliterator.IMMUTABLE | Spliterator.NONNULL);
this.iteration = iteration;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* An Iteration that can convert an {@link Iterator} to a {@link CloseableIteration}.
*/
@Deprecated(since = "4.1.0")
public class CloseableIteratorIteration<E, X extends Exception> extends AbstractCloseableIteration<E, X> {
public class CloseableIteratorIteration<E> extends AbstractCloseableIteration<E> {

private Iterator<? extends E> iter;

Expand All @@ -46,7 +46,7 @@ protected boolean hasIterator() {
}

@Override
public boolean hasNext() throws X {
public boolean hasNext() {
if (isClosed()) {
return false;
}
Expand All @@ -59,7 +59,7 @@ public boolean hasNext() throws X {
}

@Override
public E next() throws X {
public E next() {
if (isClosed()) {
throw new NoSuchElementException("Iteration has been closed");
}
Expand All @@ -68,7 +68,7 @@ public E next() throws X {
}

@Override
public void remove() throws X {
public void remove() {
if (isClosed()) {
throw new IllegalStateException("Iteration has been closed");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* over objects of type <var>T</var> (the target type).
*/
@Deprecated(since = "4.1.0")
public abstract class ConvertingIteration<S, T, X extends Exception> extends AbstractCloseableIteration<T, X> {
public abstract class ConvertingIteration<S, T> extends AbstractCloseableIteration<T> {

/*-----------*
* Variables *
Expand All @@ -28,7 +28,7 @@ public abstract class ConvertingIteration<S, T, X extends Exception> extends Abs
/**
* The source type iteration.
*/
private final Iteration<? extends S, ? extends X> iter;
private final CloseableIteration<? extends S> iter;

/*--------------*
* Constructors *
Expand All @@ -39,7 +39,7 @@ public abstract class ConvertingIteration<S, T, X extends Exception> extends Abs
*
* @param iter The source type iteration for this <var>ConvertingIteration</var>, must not be <var>null</var>.
*/
protected ConvertingIteration(Iteration<? extends S, ? extends X> iter) {
protected ConvertingIteration(CloseableIteration<? extends S> iter) {
this.iter = Objects.requireNonNull(iter, "The iterator was null");
}

Expand All @@ -50,16 +50,16 @@ protected ConvertingIteration(Iteration<? extends S, ? extends X> iter) {
/**
* Converts a source type object to a target type object.
*/
protected abstract T convert(S sourceObject) throws X;
protected abstract T convert(S sourceObject);

/**
* Checks whether the source type iteration contains more elements.
*
* @return <var>true</var> if the source type iteration contains more elements, <var>false</var> otherwise.
* @throws X
*
*/
@Override
public boolean hasNext() throws X {
public boolean hasNext() {
if (isClosed()) {
return false;
}
Expand All @@ -73,12 +73,12 @@ public boolean hasNext() throws X {
/**
* Returns the next element from the source type iteration.
*
* @throws X
*
* @throws java.util.NoSuchElementException If all elements have been returned.
* @throws IllegalStateException If the iteration has been closed.
*/
@Override
public T next() throws X {
public T next() {
if (isClosed()) {
throw new NoSuchElementException("The iteration has been closed.");
}
Expand All @@ -94,7 +94,7 @@ public T next() throws X {
* {@link #next}.
*/
@Override
public void remove() throws X {
public void remove() {
if (isClosed()) {
throw new IllegalStateException("The iteration has been closed.");
}
Expand All @@ -105,11 +105,11 @@ public void remove() throws X {
* Closes this iteration as well as the wrapped iteration if it is a {@link CloseableIteration}.
*/
@Override
protected void handleClose() throws X {
protected void handleClose() {
try {
super.handleClose();
} finally {
Iterations.closeCloseable(iter);
iter.close();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@
* <var>createIteration</var> method, which is called once when the iteration is first needed.
*/
@Deprecated(since = "4.1.0")
public abstract class DelayedIteration<E, X extends Exception> extends AbstractCloseableIteration<E, X> {
public abstract class DelayedIteration<E> extends AbstractCloseableIteration<E> {

/*-----------*
* Variables *
*-----------*/

private Iteration<? extends E, ? extends X> iter;
private CloseableIteration<? extends E> iter;

/*--------------*
* Constructors *
Expand All @@ -47,17 +47,17 @@ protected DelayedIteration() {
* Creates the iteration that should be iterated over. This method is called only once, when the iteration is first
* needed.
*/
protected abstract Iteration<? extends E, ? extends X> createIteration() throws X;
protected abstract CloseableIteration<? extends E> createIteration();

/**
* Calls the <var>hasNext</var> method of the underlying iteration.
*/
@Override
public boolean hasNext() throws X {
public boolean hasNext() {
if (isClosed()) {
return false;
}
Iteration<? extends E, ? extends X> resultIter = iter;
CloseableIteration<? extends E> resultIter = iter;
if (resultIter == null) {
// Underlying iterator has not yet been initialized
resultIter = iter;
Expand All @@ -73,11 +73,11 @@ public boolean hasNext() throws X {
* Calls the <var>next</var> method of the underlying iteration.
*/
@Override
public E next() throws X {
public E next() {
if (isClosed()) {
throw new NoSuchElementException("Iteration has been closed");
}
Iteration<? extends E, ? extends X> resultIter = iter;
CloseableIteration<? extends E> resultIter = iter;
if (resultIter == null) {
// Underlying iterator has not yet been initialized
resultIter = iter;
Expand All @@ -93,11 +93,11 @@ public E next() throws X {
* Calls the <var>remove</var> method of the underlying iteration.
*/
@Override
public void remove() throws X {
public void remove() {
if (isClosed()) {
throw new IllegalStateException("The iteration has been closed.");
}
Iteration<? extends E, ? extends X> resultIter = iter;
CloseableIteration<? extends E> resultIter = iter;
if (resultIter == null) {
throw new IllegalStateException("Underlying iteration was null");
}
Expand All @@ -110,13 +110,12 @@ public void remove() throws X {
* {@link CloseableIteration}.
*/
@Override
protected void handleClose() throws X {
protected void handleClose() {
try {
super.handleClose();
} finally {
Iteration<? extends E, ? extends X> toClose = iter;
if (toClose != null) {
Iterations.closeCloseable(toClose);
if (iter != null) {
iter.close();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* An Iteration that filters any duplicate elements from an underlying iterator.
*/
@Deprecated(since = "4.1.0")
public class DistinctIteration<E, X extends Exception> extends FilterIteration<E, X> {
public class DistinctIteration<E> extends FilterIteration<E> {

/*-----------*
* Variables *
Expand All @@ -39,13 +39,13 @@ public class DistinctIteration<E, X extends Exception> extends FilterIteration<E
*
* @param iter The underlying iterator.
*/
public DistinctIteration(Iteration<? extends E, ? extends X> iter) {
public DistinctIteration(CloseableIteration<? extends E> iter) {
super(iter);

excludeSet = makeSet();
}

public DistinctIteration(Iteration<? extends E, ? extends X> iter, Supplier<Set<E>> setMaker) {
public DistinctIteration(CloseableIteration<? extends E> iter, Supplier<Set<E>> setMaker) {
super(iter);
excludeSet = setMaker.get();
}
Expand All @@ -58,7 +58,7 @@ public DistinctIteration(Iteration<? extends E, ? extends X> iter, Supplier<Set<
* Returns <var>true</var> if the specified object hasn't been seen before.
*/
@Override
protected boolean accept(E object) throws X {
protected boolean accept(E object) {
if (inExcludeSet(object)) {
// object has already been returned
return false;
Expand All @@ -79,7 +79,7 @@ private boolean inExcludeSet(E object) {
/**
* @param object to put into the set
*/
protected boolean add(E object) throws X {
protected boolean add(E object) {
return excludeSet.add(object);
}

Expand Down
Loading

0 comments on commit d9d5b19

Please sign in to comment.