Skip to content

Commit

Permalink
Replace JSR 305 annotations
Browse files Browse the repository at this point in the history
* Replace Nonnull and Nullable with equivalents from Checker
* Replace Immutable with equivalent from error prone

Closes #172
  • Loading branch information
sleberknight committed Apr 27, 2023
1 parent b2825f1 commit fb47fe4
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 45 deletions.
14 changes: 7 additions & 7 deletions src/main/java/org/kiwiproject/retry/AttemptTimeLimiters.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
import com.google.common.base.Preconditions;
import com.google.common.util.concurrent.SimpleTimeLimiter;
import com.google.common.util.concurrent.TimeLimiter;
import com.google.errorprone.annotations.Immutable;
import org.checkerframework.checker.nullness.qual.NonNull;

import javax.annotation.Nonnull;
import javax.annotation.concurrent.Immutable;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
Expand Down Expand Up @@ -57,7 +57,7 @@ public static AttemptTimeLimiter noTimeLimit() {
* @param timeUnit of the 'duration' arg
* @return an {@link AttemptTimeLimiter} with a fixed time limit for each attempt
*/
public static AttemptTimeLimiter fixedTimeLimit(long duration, @Nonnull TimeUnit timeUnit) {
public static AttemptTimeLimiter fixedTimeLimit(long duration, @NonNull TimeUnit timeUnit) {
Preconditions.checkNotNull(timeUnit);
return new FixedAttemptTimeLimit(duration, timeUnit);
}
Expand All @@ -69,7 +69,7 @@ public static AttemptTimeLimiter fixedTimeLimit(long duration, @Nonnull TimeUnit
* @return an {@link AttemptTimeLimiter} with a fixed time limit for each attempt
*/
public static AttemptTimeLimiter fixedTimeLimit(
long duration, @Nonnull TimeUnit timeUnit, @Nonnull ExecutorService executorService) {
long duration, @NonNull TimeUnit timeUnit, @NonNull ExecutorService executorService) {
Preconditions.checkNotNull(timeUnit);
return new FixedAttemptTimeLimit(duration, timeUnit, executorService);
}
Expand All @@ -96,15 +96,15 @@ private static final class FixedAttemptTimeLimit implements AttemptTimeLimiter {
private final long duration;
private final TimeUnit timeUnit;

FixedAttemptTimeLimit(long duration, @Nonnull TimeUnit timeUnit) {
FixedAttemptTimeLimit(long duration, @NonNull TimeUnit timeUnit) {
this(duration, timeUnit, defaultExecutorService);
}

FixedAttemptTimeLimit(long duration, @Nonnull TimeUnit timeUnit, @Nonnull ExecutorService executorService) {
FixedAttemptTimeLimit(long duration, @NonNull TimeUnit timeUnit, @NonNull ExecutorService executorService) {
this(SimpleTimeLimiter.create(executorService), duration, timeUnit);
}

private FixedAttemptTimeLimit(@Nonnull TimeLimiter timeLimiter, long duration, @Nonnull TimeUnit timeUnit) {
private FixedAttemptTimeLimit(@NonNull TimeLimiter timeLimiter, long duration, @NonNull TimeUnit timeUnit) {
Preconditions.checkNotNull(timeLimiter);
Preconditions.checkNotNull(timeUnit);
this.timeLimiter = timeLimiter;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/kiwiproject/retry/BlockStrategies.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

package org.kiwiproject.retry;

import javax.annotation.concurrent.Immutable;
import com.google.errorprone.annotations.Immutable;

/**
* Factory class for {@link BlockStrategy} instances.
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/org/kiwiproject/retry/RetryException.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
import static com.google.common.base.Preconditions.checkState;
import static java.util.Objects.nonNull;

import javax.annotation.Nonnull;
import javax.annotation.concurrent.Immutable;
import com.google.errorprone.annotations.Immutable;
import org.checkerframework.checker.nullness.qual.NonNull;

/**
* An exception indicating that none of the attempts of the {@link Retryer}
Expand All @@ -40,7 +40,7 @@ public final class RetryException extends Exception {
*
* @param attempt what happened the last time we failed
*/
RetryException(@Nonnull Attempt<?> attempt) {
RetryException(@NonNull Attempt<?> attempt) {
this(errorMessageFor(attempt), attempt);
}

Expand Down
15 changes: 8 additions & 7 deletions src/main/java/org/kiwiproject/retry/Retryer.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
import static org.kiwiproject.retry.Attempt.newExceptionAttempt;
import static org.kiwiproject.retry.Attempt.newResultAttempt;

import javax.annotation.Nonnull;
import org.checkerframework.checker.nullness.qual.NonNull;

import java.util.Collection;
import java.util.List;
import java.util.concurrent.Callable;
Expand Down Expand Up @@ -58,12 +59,12 @@ public final class Retryer {
* regard to the StopStrategy).
* @param listeners collection of retry listeners
*/
Retryer(@Nonnull AttemptTimeLimiter attemptTimeLimiter,
@Nonnull StopStrategy stopStrategy,
@Nonnull WaitStrategy waitStrategy,
@Nonnull BlockStrategy blockStrategy,
@Nonnull List<Predicate<Attempt<?>>> retryPredicates,
@Nonnull Collection<RetryListener> listeners) {
Retryer(@NonNull AttemptTimeLimiter attemptTimeLimiter,
@NonNull StopStrategy stopStrategy,
@NonNull WaitStrategy waitStrategy,
@NonNull BlockStrategy blockStrategy,
@NonNull List<Predicate<Attempt<?>>> retryPredicates,
@NonNull Collection<RetryListener> listeners) {

checkNotNull(attemptTimeLimiter, "timeLimiter may not be null");
checkNotNull(stopStrategy, "stopStrategy may not be null");
Expand Down
19 changes: 10 additions & 9 deletions src/main/java/org/kiwiproject/retry/RetryerBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@

import com.google.common.base.Preconditions;

import javax.annotation.Nonnull;
import org.checkerframework.checker.nullness.qual.NonNull;

import java.util.ArrayList;
import java.util.List;
import java.util.function.Predicate;
Expand Down Expand Up @@ -49,7 +50,7 @@ public static RetryerBuilder newBuilder() {
* @param listener Listener to add
* @return <code>this</code>
*/
public RetryerBuilder withRetryListener(@Nonnull RetryListener listener) {
public RetryerBuilder withRetryListener(@NonNull RetryListener listener) {
Preconditions.checkNotNull(listener, "listener may not be null");
listeners.add(listener);
return this;
Expand All @@ -63,7 +64,7 @@ public RetryerBuilder withRetryListener(@Nonnull RetryListener listener) {
* @return <code>this</code>
* @throws IllegalStateException if a wait strategy has already been set.
*/
public RetryerBuilder withWaitStrategy(@Nonnull WaitStrategy waitStrategy) {
public RetryerBuilder withWaitStrategy(@NonNull WaitStrategy waitStrategy) {
Preconditions.checkNotNull(waitStrategy, "waitStrategy may not be null");
Preconditions.checkState(this.waitStrategy == null,
"a wait strategy has already been set: %s", this.waitStrategy);
Expand All @@ -79,7 +80,7 @@ public RetryerBuilder withWaitStrategy(@Nonnull WaitStrategy waitStrategy) {
* @return <code>this</code>
* @throws IllegalStateException if a stop strategy has already been set.
*/
public RetryerBuilder withStopStrategy(@Nonnull StopStrategy stopStrategy) {
public RetryerBuilder withStopStrategy(@NonNull StopStrategy stopStrategy) {
Preconditions.checkNotNull(stopStrategy, "stopStrategy may not be null");
Preconditions.checkState(this.stopStrategy == null, "a stop strategy has already been set: %s", this.stopStrategy);
this.stopStrategy = stopStrategy;
Expand All @@ -93,7 +94,7 @@ public RetryerBuilder withStopStrategy(@Nonnull StopStrategy stopStrategy) {
* @return <code>this</code>
* @throws IllegalStateException if a block strategy has already been set.
*/
public RetryerBuilder withBlockStrategy(@Nonnull BlockStrategy blockStrategy) {
public RetryerBuilder withBlockStrategy(@NonNull BlockStrategy blockStrategy) {
Preconditions.checkNotNull(blockStrategy, "blockStrategy may not be null");
Preconditions.checkState(this.blockStrategy == null,
"a block strategy has already been set: %s", this.blockStrategy);
Expand All @@ -108,7 +109,7 @@ public RetryerBuilder withBlockStrategy(@Nonnull BlockStrategy blockStrategy) {
* @param attemptTimeLimiter to apply to each attempt
* @return <code>this</code>
*/
public RetryerBuilder withAttemptTimeLimiter(@Nonnull AttemptTimeLimiter attemptTimeLimiter) {
public RetryerBuilder withAttemptTimeLimiter(@NonNull AttemptTimeLimiter attemptTimeLimiter) {
Preconditions.checkNotNull(attemptTimeLimiter);
this.attemptTimeLimiter = attemptTimeLimiter;
return this;
Expand Down Expand Up @@ -143,7 +144,7 @@ public RetryerBuilder retryIfRuntimeException() {
* @param exceptionClass the type of the exception which should cause the retryer to retry
* @return <code>this</code>
*/
public RetryerBuilder retryIfExceptionOfType(@Nonnull Class<? extends Exception> exceptionClass) {
public RetryerBuilder retryIfExceptionOfType(@NonNull Class<? extends Exception> exceptionClass) {
Preconditions.checkNotNull(exceptionClass, "exceptionClass may not be null");
retryPredicates.add(new ExceptionClassPredicate(exceptionClass));
return this;
Expand All @@ -156,7 +157,7 @@ public RetryerBuilder retryIfExceptionOfType(@Nonnull Class<? extends Exception>
* @param exceptionPredicate the predicate which causes a retry if satisfied
* @return <code>this</code>
*/
public RetryerBuilder retryIfException(@Nonnull Predicate<Exception> exceptionPredicate) {
public RetryerBuilder retryIfException(@NonNull Predicate<Exception> exceptionPredicate) {
Preconditions.checkNotNull(exceptionPredicate, "exceptionPredicate may not be null");
retryPredicates.add(new ExceptionPredicate(exceptionPredicate));
return this;
Expand All @@ -170,7 +171,7 @@ public RetryerBuilder retryIfException(@Nonnull Predicate<Exception> exceptionPr
* to retry if the predicate is satisfied
* @return <code>this</code>
*/
public <T> RetryerBuilder retryIfResult(@Nonnull Predicate<T> resultPredicate) {
public <T> RetryerBuilder retryIfResult(@NonNull Predicate<T> resultPredicate) {
Preconditions.checkNotNull(resultPredicate, "resultPredicate may not be null");
retryPredicates.add(new ResultPredicate<>(resultPredicate));
return this;
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/org/kiwiproject/retry/StopStrategies.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@

import com.google.common.base.Preconditions;

import javax.annotation.Nonnull;
import javax.annotation.concurrent.Immutable;
import com.google.errorprone.annotations.Immutable;
import org.checkerframework.checker.nullness.qual.NonNull;
import java.util.concurrent.TimeUnit;

/**
Expand Down Expand Up @@ -65,7 +65,7 @@ public static StopStrategy stopAfterAttempt(int attemptNumber) {
* @param timeUnit the unit of the duration
* @return a stop strategy which stops after {@code duration} time in the given {@code timeUnit}
*/
public static StopStrategy stopAfterDelay(long duration, @Nonnull TimeUnit timeUnit) {
public static StopStrategy stopAfterDelay(long duration, @NonNull TimeUnit timeUnit) {
Preconditions.checkNotNull(timeUnit, "The time unit may not be null");
return new StopAfterDelayStrategy(timeUnit.toMillis(duration));
}
Expand Down
31 changes: 16 additions & 15 deletions src/main/java/org/kiwiproject/retry/WaitStrategies.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@

import com.google.common.base.Preconditions;

import javax.annotation.Nonnull;
import javax.annotation.concurrent.Immutable;
import com.google.errorprone.annotations.Immutable;
import org.checkerframework.checker.nullness.qual.NonNull;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
Expand Down Expand Up @@ -57,7 +58,7 @@ public static WaitStrategy noWait() {
* @return a wait strategy that sleeps a fixed amount of time
* @throws IllegalArgumentException if the sleep time is &lt; 0
*/
public static WaitStrategy fixedWait(long sleepTime, @Nonnull TimeUnit timeUnit) {
public static WaitStrategy fixedWait(long sleepTime, @NonNull TimeUnit timeUnit) {
Preconditions.checkNotNull(timeUnit, "The time unit may not be null");
return new FixedWaitStrategy(timeUnit.toMillis(sleepTime));
}
Expand All @@ -70,7 +71,7 @@ public static WaitStrategy fixedWait(long sleepTime, @Nonnull TimeUnit timeUnit)
* @return a wait strategy with a random wait time
* @throws IllegalStateException if the maximum sleep time is &lt;= 0.
*/
public static WaitStrategy randomWait(long maximumTime, @Nonnull TimeUnit timeUnit) {
public static WaitStrategy randomWait(long maximumTime, @NonNull TimeUnit timeUnit) {
Preconditions.checkNotNull(timeUnit, "The time unit may not be null");
return new RandomWaitStrategy(0L, timeUnit.toMillis(maximumTime));
}
Expand All @@ -87,9 +88,9 @@ public static WaitStrategy randomWait(long maximumTime, @Nonnull TimeUnit timeUn
* maximum sleep time is less than (or equals to) the minimum.
*/
public static WaitStrategy randomWait(long minimumTime,
@Nonnull TimeUnit minimumTimeUnit,
@NonNull TimeUnit minimumTimeUnit,
long maximumTime,
@Nonnull TimeUnit maximumTimeUnit) {
@NonNull TimeUnit maximumTimeUnit) {
Preconditions.checkNotNull(minimumTimeUnit, "The minimum time unit may not be null");
Preconditions.checkNotNull(maximumTimeUnit, MAX_TIME_UNIT_MUST_BE_NON_NULL);
return new RandomWaitStrategy(minimumTimeUnit.toMillis(minimumTime),
Expand All @@ -108,9 +109,9 @@ public static WaitStrategy randomWait(long minimumTime,
* @return a wait strategy that incrementally sleeps an additional fixed time after each failed attempt
*/
public static WaitStrategy incrementingWait(long initialSleepTime,
@Nonnull TimeUnit initialSleepTimeUnit,
@NonNull TimeUnit initialSleepTimeUnit,
long increment,
@Nonnull TimeUnit incrementTimeUnit) {
@NonNull TimeUnit incrementTimeUnit) {
Preconditions.checkNotNull(initialSleepTimeUnit, "The initial sleep time unit may not be null");
Preconditions.checkNotNull(incrementTimeUnit, "The increment time unit may not be null");
return new IncrementingWaitStrategy(initialSleepTimeUnit.toMillis(initialSleepTime),
Expand All @@ -136,7 +137,7 @@ public static WaitStrategy exponentialWait() {
* @return a wait strategy that increments with each failed attempt using exponential backoff
*/
public static WaitStrategy exponentialWait(long maximumTime,
@Nonnull TimeUnit maximumTimeUnit) {
@NonNull TimeUnit maximumTimeUnit) {
Preconditions.checkNotNull(maximumTimeUnit, MAX_TIME_UNIT_MUST_BE_NON_NULL);
return new ExponentialWaitStrategy(1, maximumTimeUnit.toMillis(maximumTime));
}
Expand All @@ -154,7 +155,7 @@ public static WaitStrategy exponentialWait(long maximumTime,
*/
public static WaitStrategy exponentialWait(long multiplier,
long maximumTime,
@Nonnull TimeUnit maximumTimeUnit) {
@NonNull TimeUnit maximumTimeUnit) {
Preconditions.checkNotNull(maximumTimeUnit, MAX_TIME_UNIT_MUST_BE_NON_NULL);
return new ExponentialWaitStrategy(multiplier, maximumTimeUnit.toMillis(maximumTime));
}
Expand All @@ -178,7 +179,7 @@ public static WaitStrategy fibonacciWait() {
* @return a wait strategy that increments with each failed attempt using a Fibonacci sequence
*/
public static WaitStrategy fibonacciWait(long maximumTime,
@Nonnull TimeUnit maximumTimeUnit) {
@NonNull TimeUnit maximumTimeUnit) {
Preconditions.checkNotNull(maximumTimeUnit, MAX_TIME_UNIT_MUST_BE_NON_NULL);
return new FibonacciWaitStrategy(1, maximumTimeUnit.toMillis(maximumTime));
}
Expand All @@ -196,7 +197,7 @@ public static WaitStrategy fibonacciWait(long maximumTime,
*/
public static WaitStrategy fibonacciWait(long multiplier,
long maximumTime,
@Nonnull TimeUnit maximumTimeUnit) {
@NonNull TimeUnit maximumTimeUnit) {
Preconditions.checkNotNull(maximumTimeUnit, MAX_TIME_UNIT_MUST_BE_NON_NULL);
return new FibonacciWaitStrategy(multiplier, maximumTimeUnit.toMillis(maximumTime));
}
Expand All @@ -211,8 +212,8 @@ public static WaitStrategy fibonacciWait(long multiplier,
* @param <T> The type of exception
* @return a wait strategy calculated from the failed attempt
*/
public static <T extends Exception> WaitStrategy exceptionWait(@Nonnull Class<T> exceptionClass,
@Nonnull Function<T, Long> function) {
public static <T extends Exception> WaitStrategy exceptionWait(@NonNull Class<T> exceptionClass,
@NonNull Function<T, Long> function) {
Preconditions.checkNotNull(exceptionClass, "exceptionClass may not be null");
Preconditions.checkNotNull(function, "function may not be null");
return new ExceptionWaitStrategy<>(exceptionClass, function);
Expand Down Expand Up @@ -396,7 +397,7 @@ private static final class ExceptionWaitStrategy<T extends Exception> implements
private final Class<T> exceptionClass;
private final Function<T, Long> function;

ExceptionWaitStrategy(@Nonnull Class<T> exceptionClass, @Nonnull Function<T, Long> function) {
ExceptionWaitStrategy(@NonNull Class<T> exceptionClass, @NonNull Function<T, Long> function) {
this.exceptionClass = exceptionClass;
this.function = function;
}
Expand Down

0 comments on commit fb47fe4

Please sign in to comment.