List of usage examples for java.util Locale hasExtensions
public boolean hasExtensions()
From source file:org.primeframework.mvc.control.form.LocaleSelect.java
/** * Adds the countries Map and then calls super. *///w w w .j a v a2 s.c om @Override protected Map<String, Object> makeParameters() { LinkedHashMap<String, String> locales = new LinkedHashMap<>(); String preferred = (String) attributes.get("preferredLocales"); if (preferred != null) { String[] parts = preferred.split(","); for (String part : parts) { Locale locale = LocaleUtils.toLocale(part); locales.put(locale.toString(), locale.getDisplayName(locale)); } } boolean includeCountries = attributes.containsKey("includeCountries") ? (Boolean) attributes.get("includeCountries") : true; List<Locale> allLocales = new ArrayList<>(); Collections.addAll(allLocales, Locale.getAvailableLocales()); allLocales.removeIf((locale) -> locale.getLanguage().isEmpty() || locale.hasExtensions() || !locale.getScript().isEmpty() || !locale.getVariant().isEmpty() || (!includeCountries && !locale.getCountry().isEmpty())); allLocales.sort((one, two) -> one.getDisplayName(locale).compareTo(two.getDisplayName(locale))); for (Locale locale : allLocales) { if (!locales.containsKey(locale.getCountry())) { locales.put(locale.toString(), locale.getDisplayName(this.locale)); } } attributes.put("items", locales); return super.makeParameters(); }