code: private ULocale getBestMatchInternal(ULocale languageCode, OutputDouble outputWeight) {
          languageCode = canonicalize(languageCode);
          final ULocale maximized = addLikelySubtags(languageCode);
          if (DEBUG) {
              System.out.println("\ngetBestMatchInternal: " + languageCode + ";\t" + maximized);
          }
          double bestWeight = 0;
          ULocale bestTableMatch = null;
          String baseLanguage = maximized.getLanguage();
          Set<R3<ULocale, ULocale, Double>> searchTable = desiredLanguageToPossibleLocalesToMaxLocaleToData.get(baseLanguage);
          if (searchTable != null) { // we preprocessed the table so as to filter by lanugage
              if (DEBUG) System.out.println("\tSearching: " + searchTable);
              for (final R3<ULocale, ULocale, Double> tableKeyValue : searchTable) {
                  ULocale tableKey = tableKeyValue.get0();
                  ULocale maxLocale = tableKeyValue.get1();
                  Double matchedWeight = tableKeyValue.get2();
                  final double match = match(languageCode, maximized, tableKey, maxLocale);
                  if (DEBUG) {
                      System.out.println("\t" + tableKeyValue + ";\t" + match + "\n");
                  }
                  final double weight = match * matchedWeight;
                  if (weight > bestWeight) {
                      bestWeight = weight;
                      bestTableMatch = tableKey;
                      if (weight > 0.999d) { // bail on good enough match.
                          break;
                      }
                  }
              }
          }
          if (bestWeight < threshold) {
              bestTableMatch = defaultLanguage;
          }
          if (outputWeight != null) {
              outputWeight.value = bestWeight; // only return the weight when needed
          }
          return bestTableMatch;
      }
docs: Get the best match for an individual language code.
  
  @param languageCode
  @return best matching language code and weight (as per
  {@link #match(ULocale, ULocale)})