Skip to content

Commit d937915

Browse files
authored
Replace BiFunction with BinaryOperator (#1374)
1 parent f4bc1cb commit d937915

File tree

3 files changed

+18
-18
lines changed

3 files changed

+18
-18
lines changed

driver-core/src/main/com/mongodb/internal/async/function/RetryState.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
import com.mongodb.lang.Nullable;
2323

2424
import java.util.Optional;
25-
import java.util.function.BiFunction;
2625
import java.util.function.BiPredicate;
26+
import java.util.function.BinaryOperator;
2727
import java.util.function.Supplier;
2828

2929
import static com.mongodb.assertions.Assertions.assertFalse;
@@ -110,9 +110,9 @@ public RetryState() {
110110
* </ul>
111111
* The exception thrown represents the failed result of the associated retryable activity,
112112
* i.e., the caller must not do any more attempts.
113-
* @see #advanceOrThrow(Throwable, BiFunction, BiPredicate)
113+
* @see #advanceOrThrow(Throwable, BinaryOperator, BiPredicate)
114114
*/
115-
void advanceOrThrow(final RuntimeException attemptException, final BiFunction<Throwable, Throwable, Throwable> exceptionTransformer,
115+
void advanceOrThrow(final RuntimeException attemptException, final BinaryOperator<Throwable> exceptionTransformer,
116116
final BiPredicate<RetryState, Throwable> retryPredicate) throws RuntimeException {
117117
try {
118118
doAdvanceOrThrow(attemptException, exceptionTransformer, retryPredicate, true);
@@ -127,9 +127,9 @@ void advanceOrThrow(final RuntimeException attemptException, final BiFunction<Th
127127
* This method is intended to be used by code that generally handles all {@link Throwable} types explicitly,
128128
* which is usually asynchronous code.
129129
*
130-
* @see #advanceOrThrow(RuntimeException, BiFunction, BiPredicate)
130+
* @see #advanceOrThrow(RuntimeException, BinaryOperator, BiPredicate)
131131
*/
132-
void advanceOrThrow(final Throwable attemptException, final BiFunction<Throwable, Throwable, Throwable> exceptionTransformer,
132+
void advanceOrThrow(final Throwable attemptException, final BinaryOperator<Throwable> exceptionTransformer,
133133
final BiPredicate<RetryState, Throwable> retryPredicate) throws Throwable {
134134
doAdvanceOrThrow(attemptException, exceptionTransformer, retryPredicate, false);
135135
}
@@ -140,7 +140,7 @@ void advanceOrThrow(final Throwable attemptException, final BiFunction<Throwable
140140
* as {@link RetryState} does not have any source of {@link Exception}s.
141141
*/
142142
private void doAdvanceOrThrow(final Throwable attemptException,
143-
final BiFunction<Throwable, Throwable, Throwable> exceptionTransformer,
143+
final BinaryOperator<Throwable> exceptionTransformer,
144144
final BiPredicate<RetryState, Throwable> retryPredicate,
145145
final boolean onlyRuntimeExceptions) throws Throwable {
146146
assertTrue(attempt() < attempts);
@@ -166,10 +166,10 @@ private void doAdvanceOrThrow(final Throwable attemptException,
166166
}
167167

168168
/**
169-
* @param onlyRuntimeExceptions See {@link #doAdvanceOrThrow(Throwable, BiFunction, BiPredicate, boolean)}.
169+
* @param onlyRuntimeExceptions See {@link #doAdvanceOrThrow(Throwable, BinaryOperator, BiPredicate, boolean)}.
170170
*/
171171
private static Throwable transformException(@Nullable final Throwable previouslyChosenException, final Throwable attemptException,
172-
final boolean onlyRuntimeExceptions, final BiFunction<Throwable, Throwable, Throwable> exceptionTransformer) {
172+
final boolean onlyRuntimeExceptions, final BinaryOperator<Throwable> exceptionTransformer) {
173173
if (onlyRuntimeExceptions && previouslyChosenException != null) {
174174
assertTrue(isRuntime(previouslyChosenException));
175175
}
@@ -194,7 +194,7 @@ private static Throwable transformException(@Nullable final Throwable previously
194194

195195
/**
196196
* @param readOnlyRetryState Must not be mutated by this method.
197-
* @param onlyRuntimeExceptions See {@link #doAdvanceOrThrow(Throwable, BiFunction, BiPredicate, boolean)}.
197+
* @param onlyRuntimeExceptions See {@link #doAdvanceOrThrow(Throwable, BinaryOperator, BiPredicate, boolean)}.
198198
*/
199199
private boolean shouldRetry(final RetryState readOnlyRetryState, final Throwable attemptException, final Throwable newlyChosenException,
200200
final boolean onlyRuntimeExceptions, final BiPredicate<RetryState, Throwable> retryPredicate) {
@@ -227,7 +227,7 @@ private static boolean isRuntime(@Nullable final Throwable exception) {
227227
* by the caller to complete the ongoing attempt.
228228
* <p>
229229
* If this method is called from
230-
* {@linkplain RetryingSyncSupplier#RetryingSyncSupplier(RetryState, BiFunction, BiPredicate, Supplier)
230+
* {@linkplain RetryingSyncSupplier#RetryingSyncSupplier(RetryState, BinaryOperator, BiPredicate, Supplier)
231231
* retry predicate / failed result transformer}, the behavior is unspecified.
232232
*
233233
* @param predicate {@code true} iff retrying needs to be broken.
@@ -265,7 +265,7 @@ public void breakAndThrowIfRetryAnd(final Supplier<Boolean> predicate) throws Ru
265265
* but instead of throwing an exception, it relays it to the {@code callback}.
266266
* <p>
267267
* If this method is called from
268-
* {@linkplain RetryingAsyncCallbackSupplier#RetryingAsyncCallbackSupplier(RetryState, BiFunction, BiPredicate, com.mongodb.internal.async.function.AsyncCallbackSupplier)
268+
* {@linkplain RetryingAsyncCallbackSupplier#RetryingAsyncCallbackSupplier(RetryState, BinaryOperator, BiPredicate, AsyncCallbackSupplier)
269269
* retry predicate / failed result transformer}, the behavior is unspecified.
270270
*
271271
* @return {@code true} iff the {@code callback} was completed, which happens in the same situations in which

driver-core/src/main/com/mongodb/internal/async/function/RetryingAsyncCallbackSupplier.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
import com.mongodb.lang.NonNull;
2121
import com.mongodb.lang.Nullable;
2222

23-
import java.util.function.BiFunction;
2423
import java.util.function.BiPredicate;
24+
import java.util.function.BinaryOperator;
2525
import java.util.function.Supplier;
2626

2727
/**
@@ -41,7 +41,7 @@
4141
public final class RetryingAsyncCallbackSupplier<R> implements AsyncCallbackSupplier<R> {
4242
private final RetryState state;
4343
private final BiPredicate<RetryState, Throwable> retryPredicate;
44-
private final BiFunction<Throwable, Throwable, Throwable> failedResultTransformer;
44+
private final BinaryOperator<Throwable> failedResultTransformer;
4545
private final AsyncCallbackSupplier<R> asyncFunction;
4646

4747
/**
@@ -75,7 +75,7 @@ public final class RetryingAsyncCallbackSupplier<R> implements AsyncCallbackSupp
7575
*/
7676
public RetryingAsyncCallbackSupplier(
7777
final RetryState state,
78-
final BiFunction<Throwable, Throwable, Throwable> failedResultTransformer,
78+
final BinaryOperator<Throwable> failedResultTransformer,
7979
final BiPredicate<RetryState, Throwable> retryPredicate,
8080
final AsyncCallbackSupplier<R> asyncFunction) {
8181
this.state = state;

driver-core/src/main/com/mongodb/internal/async/function/RetryingSyncSupplier.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717

1818
import com.mongodb.annotations.NotThreadSafe;
1919

20-
import java.util.function.BiFunction;
2120
import java.util.function.BiPredicate;
21+
import java.util.function.BinaryOperator;
2222
import java.util.function.Supplier;
2323

2424
/**
@@ -37,11 +37,11 @@
3737
public final class RetryingSyncSupplier<R> implements Supplier<R> {
3838
private final RetryState state;
3939
private final BiPredicate<RetryState, Throwable> retryPredicate;
40-
private final BiFunction<Throwable, Throwable, Throwable> failedResultTransformer;
40+
private final BinaryOperator<Throwable> failedResultTransformer;
4141
private final Supplier<R> syncFunction;
4242

4343
/**
44-
* See {@link RetryingAsyncCallbackSupplier#RetryingAsyncCallbackSupplier(RetryState, BiFunction, BiPredicate, AsyncCallbackSupplier)}
44+
* See {@link RetryingAsyncCallbackSupplier#RetryingAsyncCallbackSupplier(RetryState, BinaryOperator, BiPredicate, AsyncCallbackSupplier)}
4545
* for the documentation of the parameters.
4646
*
4747
* @param failedResultTransformer Even though the {@code failedResultTransformer} accepts {@link Throwable},
@@ -51,7 +51,7 @@ public final class RetryingSyncSupplier<R> implements Supplier<R> {
5151
*/
5252
public RetryingSyncSupplier(
5353
final RetryState state,
54-
final BiFunction<Throwable, Throwable, Throwable> failedResultTransformer,
54+
final BinaryOperator<Throwable> failedResultTransformer,
5555
final BiPredicate<RetryState, Throwable> retryPredicate,
5656
final Supplier<R> syncFunction) {
5757
this.state = state;

0 commit comments

Comments
 (0)