code: public Locale getFirstMatchingLocale(List<Locale> locales, List<Locale> available) {
  
          Iterator<Locale> i;
          // first try a precise match
          i = locales.iterator();
          while (i.hasNext()) {
              Locale locale = i.next();
              if (available.contains(locale)) {
                  // precise match
                  return locale;
              }
          }
  
          // now try a match only with language and country
          i = locales.iterator();
          while (i.hasNext()) {
              Locale locale = i.next();
              if (locale.getVariant().length() > 0) {
                  // the locale has a variant, try to match without the variant
                  locale = new Locale(locale.getLanguage(), locale.getCountry(), "");
                  if (available.contains(locale)) {
                      // match
                      return locale;
                  }
              }
          }
  
          // finally try a match only with language
          i = locales.iterator();
          while (i.hasNext()) {
              Locale locale = i.next();
              if (locale.getCountry().length() > 0) {
                  // the locale has a country, try to match without the country
                  locale = new Locale(locale.getLanguage(), "", "");
                  if (available.contains(locale)) {
                      // match
                      return locale;
                  }
              }
          }
  
          // no match
          return null;
      }
docs: Returns the first matching locale (eventually simplified) from the available locales.<p>
  
  In case no match is found, code <code>null</code> is returned.<p>
  
  @param locales must be an ascending sorted list of locales in order of preference
  @param available the available locales to find a match in
  
  @return the first precise or simplified match, or <code>null</code> in case no match is found