From d937915ae1d6c32c15cc37d7b62485b1690a2bfa Mon Sep 17 00:00:00 2001 From: Valentin Kovalenko Date: Mon, 29 Apr 2024 23:28:51 -0600 Subject: [PATCH] Replace `BiFunction` with `BinaryOperator` (#1374) --- .../internal/async/function/RetryState.java | 22 +++++++++---------- .../RetryingAsyncCallbackSupplier.java | 6 ++--- .../async/function/RetryingSyncSupplier.java | 8 +++---- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/driver-core/src/main/com/mongodb/internal/async/function/RetryState.java b/driver-core/src/main/com/mongodb/internal/async/function/RetryState.java index c418fcc5f0e..ba4da185d79 100644 --- a/driver-core/src/main/com/mongodb/internal/async/function/RetryState.java +++ b/driver-core/src/main/com/mongodb/internal/async/function/RetryState.java @@ -22,8 +22,8 @@ import com.mongodb.lang.Nullable; import java.util.Optional; -import java.util.function.BiFunction; import java.util.function.BiPredicate; +import java.util.function.BinaryOperator; import java.util.function.Supplier; import static com.mongodb.assertions.Assertions.assertFalse; @@ -110,9 +110,9 @@ public RetryState() { * * The exception thrown represents the failed result of the associated retryable activity, * i.e., the caller must not do any more attempts. - * @see #advanceOrThrow(Throwable, BiFunction, BiPredicate) + * @see #advanceOrThrow(Throwable, BinaryOperator, BiPredicate) */ - void advanceOrThrow(final RuntimeException attemptException, final BiFunction exceptionTransformer, + void advanceOrThrow(final RuntimeException attemptException, final BinaryOperator exceptionTransformer, final BiPredicate retryPredicate) throws RuntimeException { try { doAdvanceOrThrow(attemptException, exceptionTransformer, retryPredicate, true); @@ -127,9 +127,9 @@ void advanceOrThrow(final RuntimeException attemptException, final BiFunction exceptionTransformer, + void advanceOrThrow(final Throwable attemptException, final BinaryOperator exceptionTransformer, final BiPredicate retryPredicate) throws Throwable { doAdvanceOrThrow(attemptException, exceptionTransformer, retryPredicate, false); } @@ -140,7 +140,7 @@ void advanceOrThrow(final Throwable attemptException, final BiFunction exceptionTransformer, + final BinaryOperator exceptionTransformer, final BiPredicate retryPredicate, final boolean onlyRuntimeExceptions) throws Throwable { assertTrue(attempt() < attempts); @@ -166,10 +166,10 @@ private void doAdvanceOrThrow(final Throwable attemptException, } /** - * @param onlyRuntimeExceptions See {@link #doAdvanceOrThrow(Throwable, BiFunction, BiPredicate, boolean)}. + * @param onlyRuntimeExceptions See {@link #doAdvanceOrThrow(Throwable, BinaryOperator, BiPredicate, boolean)}. */ private static Throwable transformException(@Nullable final Throwable previouslyChosenException, final Throwable attemptException, - final boolean onlyRuntimeExceptions, final BiFunction exceptionTransformer) { + final boolean onlyRuntimeExceptions, final BinaryOperator exceptionTransformer) { if (onlyRuntimeExceptions && previouslyChosenException != null) { assertTrue(isRuntime(previouslyChosenException)); } @@ -194,7 +194,7 @@ private static Throwable transformException(@Nullable final Throwable previously /** * @param readOnlyRetryState Must not be mutated by this method. - * @param onlyRuntimeExceptions See {@link #doAdvanceOrThrow(Throwable, BiFunction, BiPredicate, boolean)}. + * @param onlyRuntimeExceptions See {@link #doAdvanceOrThrow(Throwable, BinaryOperator, BiPredicate, boolean)}. */ private boolean shouldRetry(final RetryState readOnlyRetryState, final Throwable attemptException, final Throwable newlyChosenException, final boolean onlyRuntimeExceptions, final BiPredicate retryPredicate) { @@ -227,7 +227,7 @@ private static boolean isRuntime(@Nullable final Throwable exception) { * by the caller to complete the ongoing attempt. *

* If this method is called from - * {@linkplain RetryingSyncSupplier#RetryingSyncSupplier(RetryState, BiFunction, BiPredicate, Supplier) + * {@linkplain RetryingSyncSupplier#RetryingSyncSupplier(RetryState, BinaryOperator, BiPredicate, Supplier) * retry predicate / failed result transformer}, the behavior is unspecified. * * @param predicate {@code true} iff retrying needs to be broken. @@ -265,7 +265,7 @@ public void breakAndThrowIfRetryAnd(final Supplier predicate) throws Ru * but instead of throwing an exception, it relays it to the {@code callback}. *

* If this method is called from - * {@linkplain RetryingAsyncCallbackSupplier#RetryingAsyncCallbackSupplier(RetryState, BiFunction, BiPredicate, com.mongodb.internal.async.function.AsyncCallbackSupplier) + * {@linkplain RetryingAsyncCallbackSupplier#RetryingAsyncCallbackSupplier(RetryState, BinaryOperator, BiPredicate, AsyncCallbackSupplier) * retry predicate / failed result transformer}, the behavior is unspecified. * * @return {@code true} iff the {@code callback} was completed, which happens in the same situations in which diff --git a/driver-core/src/main/com/mongodb/internal/async/function/RetryingAsyncCallbackSupplier.java b/driver-core/src/main/com/mongodb/internal/async/function/RetryingAsyncCallbackSupplier.java index 92233a072be..e0f3d8c7457 100644 --- a/driver-core/src/main/com/mongodb/internal/async/function/RetryingAsyncCallbackSupplier.java +++ b/driver-core/src/main/com/mongodb/internal/async/function/RetryingAsyncCallbackSupplier.java @@ -20,8 +20,8 @@ import com.mongodb.lang.NonNull; import com.mongodb.lang.Nullable; -import java.util.function.BiFunction; import java.util.function.BiPredicate; +import java.util.function.BinaryOperator; import java.util.function.Supplier; /** @@ -41,7 +41,7 @@ public final class RetryingAsyncCallbackSupplier implements AsyncCallbackSupplier { private final RetryState state; private final BiPredicate retryPredicate; - private final BiFunction failedResultTransformer; + private final BinaryOperator failedResultTransformer; private final AsyncCallbackSupplier asyncFunction; /** @@ -75,7 +75,7 @@ public final class RetryingAsyncCallbackSupplier implements AsyncCallbackSupp */ public RetryingAsyncCallbackSupplier( final RetryState state, - final BiFunction failedResultTransformer, + final BinaryOperator failedResultTransformer, final BiPredicate retryPredicate, final AsyncCallbackSupplier asyncFunction) { this.state = state; diff --git a/driver-core/src/main/com/mongodb/internal/async/function/RetryingSyncSupplier.java b/driver-core/src/main/com/mongodb/internal/async/function/RetryingSyncSupplier.java index 53814c3a864..315197f0da9 100644 --- a/driver-core/src/main/com/mongodb/internal/async/function/RetryingSyncSupplier.java +++ b/driver-core/src/main/com/mongodb/internal/async/function/RetryingSyncSupplier.java @@ -17,8 +17,8 @@ import com.mongodb.annotations.NotThreadSafe; -import java.util.function.BiFunction; import java.util.function.BiPredicate; +import java.util.function.BinaryOperator; import java.util.function.Supplier; /** @@ -37,11 +37,11 @@ public final class RetryingSyncSupplier implements Supplier { private final RetryState state; private final BiPredicate retryPredicate; - private final BiFunction failedResultTransformer; + private final BinaryOperator failedResultTransformer; private final Supplier syncFunction; /** - * See {@link RetryingAsyncCallbackSupplier#RetryingAsyncCallbackSupplier(RetryState, BiFunction, BiPredicate, AsyncCallbackSupplier)} + * See {@link RetryingAsyncCallbackSupplier#RetryingAsyncCallbackSupplier(RetryState, BinaryOperator, BiPredicate, AsyncCallbackSupplier)} * for the documentation of the parameters. * * @param failedResultTransformer Even though the {@code failedResultTransformer} accepts {@link Throwable}, @@ -51,7 +51,7 @@ public final class RetryingSyncSupplier implements Supplier { */ public RetryingSyncSupplier( final RetryState state, - final BiFunction failedResultTransformer, + final BinaryOperator failedResultTransformer, final BiPredicate retryPredicate, final Supplier syncFunction) { this.state = state;