code: private List<Match> matchesImpl(List<Entry> desiredLocales, int threshold) {
      int bestDistance = MAX_DISTANCE;
  
      // TreeMap is used to maintain the original ordering captured in the
      // supportedLocales list. Even though we sort the values before returning,
      // the stable sort order would change due to passing through a hashing function.
      Map<String, Match> result = new TreeMap<>();
      for (Entry desired : desiredLocales) {
        List<String> exact = exactMatch.get(desired.locale);
        if (exact != null) {
          updateMatch(result, exact.get(0), 0);
        }
        
        for (Entry supported : supportedLocales) {
          int distance = DISTANCE_TABLE.distance(desired.locale, supported.locale, threshold);
          if (distance < bestDistance) {
            updateMatch(result, supported.bundleId, distance);
          }
        }
      }
      
      // Stable sort, so an earlier match with equal distance will come first.
      return result.values().stream()
          .sorted((a, b) -> Integer.compare(a.distance, b.distance))
          .collect(Collectors.toList());
    }
docs: Return all matches and their distances, if they exceed the given threshold.
  If no match exceeds the threshold this returns an empty list.
  Exact matches have distance of 0. Each distinct bundleId should appear at
  most once in the results, even if their meaning is equivalent, e.g. "en" and
  "en-US" are distinct but mean the same, and both will appear in the results.