Skip to content

Commit

Permalink
Replace Guava collection factory methods with native JDK APIs (#47)
Browse files Browse the repository at this point in the history
* Replace Lists.newArrayList() with new ArrayList<>() in RetryerBuilder
* Replace Sets.newHashSet() w/new HashSet<>() in AttemptTimeLimitersTest
* Replace Lists.newArrayList(waitStrategies) to the more verbose
  new ArrayList<>(Arrays.asList(waitStrategies)) because of the null
  check below. For now just wanted to keep existing behavior as-is so
  this was one way using only native JDK API.

Closes #42
  • Loading branch information
sleberknight authored Jan 22, 2021
1 parent 92da33b commit 1b076f7
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
3 changes: 1 addition & 2 deletions src/main/java/org/kiwiproject/retry/RetryerBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
package org.kiwiproject.retry;

import com.google.common.base.Preconditions;
import com.google.common.collect.Lists;

import javax.annotation.Nonnull;
import java.util.ArrayList;
Expand All @@ -34,7 +33,7 @@ public class RetryerBuilder {
private StopStrategy stopStrategy;
private WaitStrategy waitStrategy;
private BlockStrategy blockStrategy;
private final List<Predicate<Attempt<?>>> retryPredicates = Lists.newArrayList();
private final List<Predicate<Attempt<?>>> retryPredicates = new ArrayList<>();
private final List<RetryListener> listeners = new ArrayList<>();

private RetryerBuilder() {
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/org/kiwiproject/retry/WaitStrategies.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@
package org.kiwiproject.retry;

import com.google.common.base.Preconditions;
import com.google.common.collect.Lists;

import javax.annotation.Nonnull;
import javax.annotation.concurrent.Immutable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Random;
import java.util.concurrent.TimeUnit;
Expand Down Expand Up @@ -226,7 +227,7 @@ public static <T extends Throwable> WaitStrategy exceptionWait(@Nonnull Class<T>
*/
public static WaitStrategy join(WaitStrategy... waitStrategies) {
Preconditions.checkState(waitStrategies.length > 0, "Must have at least one wait strategy");
List<WaitStrategy> waitStrategyList = Lists.newArrayList(waitStrategies);
List<WaitStrategy> waitStrategyList = new ArrayList<>(Arrays.asList(waitStrategies));
Preconditions.checkState(!waitStrategyList.contains(null), "Cannot have a null wait strategy");
return new CompositeWaitStrategy(waitStrategyList);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@

import static org.assertj.core.api.Assertions.assertThat;

import com.google.common.collect.Sets;
import org.junit.jupiter.api.Test;

import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.Callable;
import java.util.concurrent.TimeUnit;
Expand All @@ -30,7 +30,7 @@ class AttemptTimeLimitersTest {

@Test
void testFixedTimeLimitWithNoExecutorReusesThreads() throws Exception {
Set<Long> threadsUsed = Collections.synchronizedSet(Sets.newHashSet());
Set<Long> threadsUsed = Collections.synchronizedSet(new HashSet<>());
Callable<Void> callable = () -> {
threadsUsed.add(Thread.currentThread().getId());
return null;
Expand Down

0 comments on commit 1b076f7

Please sign in to comment.