Skip to content

Commit

Permalink
Use the Java-8 Comparator interface more consistently.
Browse files Browse the repository at this point in the history
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=188765177
  • Loading branch information
blickly committed Mar 12, 2018
1 parent 4ea1570 commit a153104
Showing 1 changed file with 6 additions and 7 deletions.
Expand Up @@ -17,10 +17,10 @@

import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkState;
import static java.util.Comparator.comparing;

import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
import com.google.common.collect.Ordering;
import com.google.javascript.jscomp.AbstractCompiler;
import com.google.javascript.jscomp.CompilerPass;
import com.google.javascript.jscomp.DiagnosticType;
Expand Down Expand Up @@ -425,12 +425,11 @@ enum TypingLevel {
NO_JSDOC,
}

static final Ordering<String> SHORT_TO_LONG =
// TODO(b/28382956): Take better advantage of Java8 comparing() to simplify this
Ordering.natural().onResultOf(name -> name.replaceAll("[^.]", "").length());
static final Comparator<String> SHORT_TO_LONG =
comparing(name -> name.replaceAll("[^.]", "").length());

static final Comparator<PotentialDeclaration> DECLARATIONS_FIRST =
Comparator.comparing(
comparing(
decl -> {
JSDocInfo jsdoc = decl.getJsDoc();
if (jsdoc == null) {
Expand Down Expand Up @@ -467,8 +466,8 @@ void simplifyAll() {
removeDuplicateDeclarations();

// Simplify all names in the top-level scope.
List<String> seenNames =
SHORT_TO_LONG.immutableSortedCopy(currentFile.getDeclarations().keySet());
Iterable<String> seenNames =
currentFile.getDeclarations().keySet().stream().sorted(SHORT_TO_LONG)::iterator;

for (String name : seenNames) {
for (PotentialDeclaration decl : currentFile.getDeclarations().get(name)) {
Expand Down

0 comments on commit a153104

Please sign in to comment.