Revert "[NS D01] Remove candidates that don't satisfy the request."

This reverts commit a19115d482.

Reason for revert: The feature was punted out of R.

Change-Id: Ia91b3b3c55f735dae64ffa3194614a6f2631a087
This commit is contained in:
Chalard Jean
2020-02-20 08:41:38 +00:00
parent 1d9a206bca
commit d15ca10d6d

View File

@@ -20,7 +20,6 @@ import android.annotation.NonNull;
import android.annotation.Nullable; import android.annotation.Nullable;
import android.net.NetworkRequest; import android.net.NetworkRequest;
import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
/** /**
@@ -32,15 +31,15 @@ public class NetworkRanker {
/** /**
* Find the best network satisfying this request among the list of passed networks. * Find the best network satisfying this request among the list of passed networks.
*/ */
// Almost equivalent to Collections.max(nais), but allows returning null if no network
// satisfies the request.
@Nullable @Nullable
public NetworkAgentInfo getBestNetwork(@NonNull final NetworkRequest request, public NetworkAgentInfo getBestNetwork(@NonNull final NetworkRequest request,
@NonNull final Collection<NetworkAgentInfo> nais) { @NonNull final Collection<NetworkAgentInfo> nais) {
final ArrayList<NetworkAgentInfo> candidates = new ArrayList<>(nais);
candidates.removeIf(nai -> !nai.satisfies(request));
NetworkAgentInfo bestNetwork = null; NetworkAgentInfo bestNetwork = null;
int bestScore = Integer.MIN_VALUE; int bestScore = Integer.MIN_VALUE;
for (final NetworkAgentInfo nai : candidates) { for (final NetworkAgentInfo nai : nais) {
if (!nai.satisfies(request)) continue;
if (nai.getCurrentScore() > bestScore) { if (nai.getCurrentScore() > bestScore) {
bestNetwork = nai; bestNetwork = nai;
bestScore = nai.getCurrentScore(); bestScore = nai.getCurrentScore();