// Path: src/main/java/com/github/phantomthief/failover/util/RandomListUtils.java
// @Nullable
// public static <T> T getRandom(List<T> source) {
//     if (source == null || source.isEmpty()) {
//         return null;
//     }
//     return source.get(ThreadLocalRandom.current().nextInt(source.size()));
// }


import static com.github.phantomthief.failover.util.RandomListUtils.getRandom;
import static com.google.common.base.Preconditions.checkNotNull;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.RandomAccess;
import java.util.concurrent.ConcurrentHashMap;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.github.phantomthief.util.ThrowableConsumer;
import com.github.phantomthief.util.ThrowableFunction;
        int minValue = Integer.MAX_VALUE;
        for (T obj : candidates) {
            int c = concurrency.getOrDefault(obj, 0);
            if (c < minValue) {
                minValue = c;
                idlest.clear();
                idlest.add(obj);
            } else if (c == minValue) {
                idlest.add(obj);
            }
        }
        T result = getRandom(idlest);
        assert result != null;
        return result;
    }

    /**
     * Try to find a node with 0 concurrency by pure random.
     * It is assuming that concurrency is very low for most cases.
     * This method will optimize performance significantly on large candidates collection,
     * because it is no need to build a large ListMultimap of TreeMap.
     */
    @Nullable
    private T selectIdlestFast(List<T> candidates) {
        if (candidates.isEmpty()) {
            throw new NoSuchElementException("candidates list is empty");
        } else if (candidates.size() == 1) {
            return candidates.get(0);
        }
        for (int i = 0; i < OPTIMIZE_RANDOM_TRIES; ++i) {
// Path: src/main/java/com/github/phantomthief/failover/util/RandomListUtils.java
// @Nullable
// public static <T> T getRandom(List<T> source) {
//     if (source == null || source.isEmpty()) {
//         return null;
//     }
//     return source.get(ThreadLocalRandom.current().nextInt(source.size()));
// }


// Path: src/main/java/com/github/phantomthief/failover/util/ConcurrencyAware.java
import static com.github.phantomthief.failover.util.RandomListUtils.getRandom;
import static com.google.common.base.Preconditions.checkNotNull;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.RandomAccess;
import java.util.concurrent.ConcurrentHashMap;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.github.phantomthief.util.ThrowableConsumer;
import com.github.phantomthief.util.ThrowableFunction;

        int minValue = Integer.MAX_VALUE;
        for (T obj : candidates) {
            int c = concurrency.getOrDefault(obj, 0);
            if (c < minValue) {
                minValue = c;
                idlest.clear();
                idlest.add(obj);
            } else if (c == minValue) {
                idlest.add(obj);
            }
        }
        T result = getRandom(idlest);
        assert result != null;
        return result;
    }

    /**
     * Try to find a node with 0 concurrency by pure random.
     * It is assuming that concurrency is very low for most cases.
     * This method will optimize performance significantly on large candidates collection,
     * because it is no need to build a large ListMultimap of TreeMap.
     */
    @Nullable
    private T selectIdlestFast(List<T> candidates) {
        if (candidates.isEmpty()) {
            throw new NoSuchElementException("candidates list is empty");
        } else if (candidates.size() == 1) {
            return candidates.get(0);
        }
        for (int i = 0; i < OPTIMIZE_RANDOM_TRIES; ++i) {
            T result = getRandom(candidates);