Small simplification to creation of prefixReplacements ImmutableSet
In addition to being slightly simpler, this also avoids unnecessary copying
from ImmutableSortedSet to ImmutableSet
package com.google.javascript.jscomp.deps;
-import static com.google.common.collect.ImmutableSortedSet.toImmutableSortedSet;
+import static com.google.common.collect.ImmutableSet.toImmutableSet;
import static java.util.stream.Collectors.joining;
import com.google.auto.value.AutoValue;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
-import com.google.common.collect.ImmutableSortedSet;
import com.google.javascript.jscomp.CheckLevel;
import com.google.javascript.jscomp.DiagnosticType;
import com.google.javascript.jscomp.ErrorHandler;
@@ -90,17 +89,16 @@ public class BrowserWithTransformedPrefixesModuleResolver extends ModuleResolver
PathEscaper pathEscaper,
ImmutableMap<String, String> prefixReplacements) {
super(modulePaths, moduleRootPaths, errorHandler, pathEscaper);
- ImmutableSortedSet<PrefixReplacement> p =
+ this.prefixReplacements =
prefixReplacements.entrySet().stream()
.map(entry -> PrefixReplacement.of(entry.getKey(), entry.getValue()))
- .collect(
- toImmutableSortedSet(
+ .sorted(
// Sort by length in descending order to prefixes are applied most specific to
// least specific.
Comparator.<PrefixReplacement>comparingInt(r -> r.prefix().length())
.reversed()
- .thenComparing(PrefixReplacement::prefix)));
- this.prefixReplacements = ImmutableSet.copyOf(p);
+ .thenComparing(PrefixReplacement::prefix))
+ .collect(toImmutableSet());
this.expectedPrefixes =
this.prefixReplacements.stream()
.map(PrefixReplacement::prefix)
