code: public Locale getBestMatchingLocale(Locale requestedLocale, List<Locale> defaults, List<Locale> available) {
  
          if ((available == null) || available.isEmpty()) {
              // no locales are available at all
              return null;
          }
  
          // the requested locale is the match we want to find most
          if (available.contains(requestedLocale)) {
              // check if the requested locale is directly available
              return requestedLocale;
          }
          if (requestedLocale.getVariant().length() > 0) {
              // locale has a variant like "en_EN_whatever", try only with language and country
              Locale check = new Locale(requestedLocale.getLanguage(), requestedLocale.getCountry(), "");
              if (available.contains(check)) {
                  return check;
              }
          }
          if (requestedLocale.getCountry().length() > 0) {
              // locale has a country like "en_EN", try only with language
              Locale check = new Locale(requestedLocale.getLanguage(), "", "");
              if (available.contains(check)) {
                  return check;
              }
          }
  
          // available locales do not match the requested locale
          if ((defaults == null) || defaults.isEmpty()) {
              // if we have no default locales we are out of luck
              return null;
          }
  
          // no match found for the requested locale, return the first match from the default locales
          return getFirstMatchingLocale(defaults, available);
      }
docs: Tries to find the given requested locale (eventually simplified) in the collection of available locales,
  if the requested locale is not found it will return the first match from the given list of default locales.<p>
  
  @param requestedLocale the requested locale, if this (or a simplified version of it) is available it will be returned
  @param defaults a list of default locales to use in case the requested locale is not available
  @param available the available locales to find a match in
  
  @return the best matching locale name or null if no name matches