Merge branch 'stable-3.1'

* stable-3.1:
  Bazel: Remove unused java_library import
  Bump Bazel version to 2.0.0
  Upgrade bazlets to latest stable-2.16 to build with 2.16.15 API
  Upgrade bazlets to latest stable-2.16 to build with 2.16.14 API
  Upgrade gitiles-servlet to 0.2-7.1
  Upgrade bazlets to latest stable-2.16 to build with 2.16.13 API
  Upgrade bazlets to latest stable-2.16
  Upgrade bazlets to latest stable-2.15 to build with 2.15.18 API
  Bazel: Migrate workspace status script to python
  Upgrade bazlets to latest stable-2.15
  Upgrade bazlets to latest stable-2.14
  Upgrade bazlets to latest stable-2.16
  Upgrade bazlets to latest stable-2.15
  Upgrade bazlets to latest stable-2.14
  Bump Bazel version to 1.1.0
  Replace bazel-genfiles with bazel-bin in documentation

Change-Id: I646b195ea8623873470589656ff2656329cdf03b
diff --git a/src/main/java/com/googlesource/gerrit/plugins/gitiles/FilteredRepository.java b/src/main/java/com/googlesource/gerrit/plugins/gitiles/FilteredRepository.java
index 58f2b0f..7c761fa 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/gitiles/FilteredRepository.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/gitiles/FilteredRepository.java
@@ -14,8 +14,9 @@
 
 package com.googlesource.gerrit.plugins.gitiles;
 
+import static java.util.stream.Collectors.toMap;
+
 import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.Maps;
 import com.google.gerrit.entities.Project;
 import com.google.gerrit.extensions.restapi.AuthException;
@@ -31,6 +32,7 @@
 import com.google.inject.Inject;
 import com.google.inject.Provider;
 import java.io.IOException;
+import java.util.Collection;
 import java.util.List;
 import java.util.Map;
 import org.eclipse.jgit.attributes.AttributesNodeProvider;
@@ -204,7 +206,10 @@
         return null;
       }
       try {
-        return perm.filter(ImmutableMap.of(name, ref), git, RefFilterOptions.defaults()).get(name);
+        return perm.filter(ImmutableList.of(ref), git, RefFilterOptions.defaults()).stream()
+            .filter(r -> r.getName().equals(name))
+            .findAny()
+            .orElse(null);
       } catch (PermissionBackendException e) {
         throw new IOException(e);
       }
@@ -212,7 +217,7 @@
 
     @Override
     public Map<String, Ref> getRefs(String prefix) throws IOException {
-      Map<String, Ref> refs;
+      Collection<Ref> refs;
       try {
         refs =
             perm.filter(
@@ -220,12 +225,8 @@
       } catch (PermissionBackendException e) {
         throw new IOException(e);
       }
-      Map<String, Ref> result = Maps.newHashMapWithExpectedSize(refs.size());
-      for (Ref ref : refs.values()) {
-        // VisibleRefFilter adds the prefix to the keys, re-strip it.
-        result.put(ref.getName().substring(prefix.length()), ref);
-      }
-      return refs;
+      // VisibleRefFilter adds the prefix to the keys, re-strip it.
+      return refs.stream().collect(toMap(r -> r.getName().substring(prefix.length()), r -> r));
     }
 
     @Override