< prev index next >

src/java.base/share/classes/java/util/Locale.java

Print this page
rev 52979 : 8215281: Use String.isEmpty() when applicable in java.base
Reviewed-by: TBD

*** 1394,1408 **** * @see #getDisplayName * @see #toLanguageTag */ @Override public final String toString() { ! boolean l = (baseLocale.getLanguage().length() != 0); ! boolean s = (baseLocale.getScript().length() != 0); ! boolean r = (baseLocale.getRegion().length() != 0); ! boolean v = (baseLocale.getVariant().length() != 0); ! boolean e = (localeExtensions != null && localeExtensions.getID().length() != 0); StringBuilder result = new StringBuilder(baseLocale.getLanguage()); if (r || (l && (v || s || e))) { result.append('_') .append(baseLocale.getRegion()); // This may just append '_' --- 1394,1408 ---- * @see #getDisplayName * @see #toLanguageTag */ @Override public final String toString() { ! boolean l = !baseLocale.getLanguage().isEmpty(); ! boolean s = !baseLocale.getScript().isEmpty(); ! boolean r = !baseLocale.getRegion().isEmpty(); ! boolean v = !baseLocale.getVariant().isEmpty(); ! boolean e = localeExtensions != null && !localeExtensions.getID().isEmpty(); StringBuilder result = new StringBuilder(baseLocale.getLanguage()); if (r || (l && (v || s || e))) { result.append('_') .append(baseLocale.getRegion()); // This may just append '_'
*** 1502,1523 **** LanguageTag tag = LanguageTag.parseLocale(baseLocale, localeExtensions); StringBuilder buf = new StringBuilder(); String subtag = tag.getLanguage(); ! if (subtag.length() > 0) { buf.append(LanguageTag.canonicalizeLanguage(subtag)); } subtag = tag.getScript(); ! if (subtag.length() > 0) { buf.append(LanguageTag.SEP); buf.append(LanguageTag.canonicalizeScript(subtag)); } subtag = tag.getRegion(); ! if (subtag.length() > 0) { buf.append(LanguageTag.SEP); buf.append(LanguageTag.canonicalizeRegion(subtag)); } List<String>subtags = tag.getVariants(); --- 1502,1523 ---- LanguageTag tag = LanguageTag.parseLocale(baseLocale, localeExtensions); StringBuilder buf = new StringBuilder(); String subtag = tag.getLanguage(); ! if (!subtag.isEmpty()) { buf.append(LanguageTag.canonicalizeLanguage(subtag)); } subtag = tag.getScript(); ! if (!subtag.isEmpty()) { buf.append(LanguageTag.SEP); buf.append(LanguageTag.canonicalizeScript(subtag)); } subtag = tag.getRegion(); ! if (!subtag.isEmpty()) { buf.append(LanguageTag.SEP); buf.append(LanguageTag.canonicalizeRegion(subtag)); } List<String>subtags = tag.getVariants();
*** 1532,1542 **** buf.append(LanguageTag.SEP); buf.append(LanguageTag.canonicalizeExtension(s)); } subtag = tag.getPrivateuse(); ! if (subtag.length() > 0) { if (buf.length() > 0) { buf.append(LanguageTag.SEP); } buf.append(LanguageTag.PRIVATEUSE).append(LanguageTag.SEP); // preserve casing --- 1532,1542 ---- buf.append(LanguageTag.SEP); buf.append(LanguageTag.canonicalizeExtension(s)); } subtag = tag.getPrivateuse(); ! if (!subtag.isEmpty()) { if (buf.length() > 0) { buf.append(LanguageTag.SEP); } buf.append(LanguageTag.PRIVATEUSE).append(LanguageTag.SEP); // preserve casing
*** 1682,1692 **** LanguageTag tag = LanguageTag.parse(languageTag, null); InternalLocaleBuilder bldr = new InternalLocaleBuilder(); bldr.setLanguageTag(tag); BaseLocale base = bldr.getBaseLocale(); LocaleExtensions exts = bldr.getLocaleExtensions(); ! if (exts == null && base.getVariant().length() > 0) { exts = getCompatibilityExtensions(base.getLanguage(), base.getScript(), base.getRegion(), base.getVariant()); } return getInstance(base, exts); } --- 1682,1692 ---- LanguageTag tag = LanguageTag.parse(languageTag, null); InternalLocaleBuilder bldr = new InternalLocaleBuilder(); bldr.setLanguageTag(tag); BaseLocale base = bldr.getBaseLocale(); LocaleExtensions exts = bldr.getLocaleExtensions(); ! if (exts == null && !base.getVariant().isEmpty()) { exts = getCompatibilityExtensions(base.getLanguage(), base.getScript(), base.getRegion(), base.getVariant()); } return getInstance(base, exts); }
*** 1915,1925 **** * @param inLocale The locale for which to retrieve the display variant code. * @return The name of the display variant code appropriate to the given locale. * @exception NullPointerException if <code>inLocale</code> is <code>null</code> */ public String getDisplayVariant(Locale inLocale) { ! if (baseLocale.getVariant().length() == 0) return ""; LocaleResources lr = LocaleProviderAdapter .getResourceBundleBased() .getLocaleResources(inLocale); --- 1915,1925 ---- * @param inLocale The locale for which to retrieve the display variant code. * @return The name of the display variant code appropriate to the given locale. * @exception NullPointerException if <code>inLocale</code> is <code>null</code> */ public String getDisplayVariant(Locale inLocale) { ! if (baseLocale.getVariant().isEmpty()) return ""; LocaleResources lr = LocaleProviderAdapter .getResourceBundleBased() .getLocaleResources(inLocale);
*** 1996,2027 **** String listCompositionPattern = lr.getLocaleName("ListCompositionPattern"); // The display name consists of a main name, followed by qualifiers. // Typically, the format is "MainName (Qualifier, Qualifier)" but this // depends on what pattern is stored in the display locale. ! String mainName = null; ! String[] qualifierNames = null; // The main name is the language, or if there is no language, the script, // then if no script, the country. If there is no language/script/country // (an anomalous situation) then the display name is simply the variant's // display name. ! if (languageName.length() == 0 && scriptName.length() == 0 && countryName.length() == 0) { if (variantNames.length == 0) { return ""; } else { return formatList(variantNames, listCompositionPattern); } } ArrayList<String> names = new ArrayList<>(4); ! if (languageName.length() != 0) { names.add(languageName); } ! if (scriptName.length() != 0) { names.add(scriptName); } ! if (countryName.length() != 0) { names.add(countryName); } if (variantNames.length != 0) { names.addAll(Arrays.asList(variantNames)); } --- 1996,2027 ---- String listCompositionPattern = lr.getLocaleName("ListCompositionPattern"); // The display name consists of a main name, followed by qualifiers. // Typically, the format is "MainName (Qualifier, Qualifier)" but this // depends on what pattern is stored in the display locale. ! String mainName; ! String[] qualifierNames; // The main name is the language, or if there is no language, the script, // then if no script, the country. If there is no language/script/country // (an anomalous situation) then the display name is simply the variant's // display name. ! if (languageName.isEmpty() && scriptName.isEmpty() && countryName.isEmpty()) { if (variantNames.length == 0) { return ""; } else { return formatList(variantNames, listCompositionPattern); } } ArrayList<String> names = new ArrayList<>(4); ! if (!languageName.isEmpty()) { names.add(languageName); } ! if (!scriptName.isEmpty()) { names.add(scriptName); } ! if (!countryName.isEmpty()) { names.add(countryName); } if (variantNames.length != 0) { names.addAll(Arrays.asList(variantNames)); }
*** 2307,2317 **** String script = (String)fields.get("script", ""); String country = (String)fields.get("country", ""); String variant = (String)fields.get("variant", ""); String extStr = (String)fields.get("extensions", ""); baseLocale = BaseLocale.getInstance(convertOldISOCodes(language), script, country, variant); ! if (extStr.length() > 0) { try { InternalLocaleBuilder bldr = new InternalLocaleBuilder(); bldr.setExtensions(extStr); localeExtensions = bldr.getLocaleExtensions(); } catch (LocaleSyntaxException e) { --- 2307,2317 ---- String script = (String)fields.get("script", ""); String country = (String)fields.get("country", ""); String variant = (String)fields.get("variant", ""); String extStr = (String)fields.get("extensions", ""); baseLocale = BaseLocale.getInstance(convertOldISOCodes(language), script, country, variant); ! if (!extStr.isEmpty()) { try { InternalLocaleBuilder bldr = new InternalLocaleBuilder(); bldr.setExtensions(extStr); localeExtensions = bldr.getLocaleExtensions(); } catch (LocaleSyntaxException e) {
*** 2365,2381 **** String country, String variant) { LocaleExtensions extensions = null; // Special cases for backward compatibility support if (LocaleUtils.caseIgnoreMatch(language, "ja") ! && script.length() == 0 && LocaleUtils.caseIgnoreMatch(country, "jp") && "JP".equals(variant)) { // ja_JP_JP -> u-ca-japanese (calendar = japanese) extensions = LocaleExtensions.CALENDAR_JAPANESE; } else if (LocaleUtils.caseIgnoreMatch(language, "th") ! && script.length() == 0 && LocaleUtils.caseIgnoreMatch(country, "th") && "TH".equals(variant)) { // th_TH_TH -> u-nu-thai (numbersystem = thai) extensions = LocaleExtensions.NUMBER_THAI; } --- 2365,2381 ---- String country, String variant) { LocaleExtensions extensions = null; // Special cases for backward compatibility support if (LocaleUtils.caseIgnoreMatch(language, "ja") ! && script.isEmpty() && LocaleUtils.caseIgnoreMatch(country, "jp") && "JP".equals(variant)) { // ja_JP_JP -> u-ca-japanese (calendar = japanese) extensions = LocaleExtensions.CALENDAR_JAPANESE; } else if (LocaleUtils.caseIgnoreMatch(language, "th") ! && script.isEmpty() && LocaleUtils.caseIgnoreMatch(country, "th") && "TH".equals(variant)) { // th_TH_TH -> u-nu-thai (numbersystem = thai) extensions = LocaleExtensions.NUMBER_THAI; }
*** 2804,2814 **** * @return A Locale. */ public Locale build() { BaseLocale baseloc = localeBuilder.getBaseLocale(); LocaleExtensions extensions = localeBuilder.getLocaleExtensions(); ! if (extensions == null && baseloc.getVariant().length() > 0) { extensions = getCompatibilityExtensions(baseloc.getLanguage(), baseloc.getScript(), baseloc.getRegion(), baseloc.getVariant()); } return Locale.getInstance(baseloc, extensions); } --- 2804,2814 ---- * @return A Locale. */ public Locale build() { BaseLocale baseloc = localeBuilder.getBaseLocale(); LocaleExtensions extensions = localeBuilder.getLocaleExtensions(); ! if (extensions == null && !baseloc.getVariant().isEmpty()) { extensions = getCompatibilityExtensions(baseloc.getLanguage(), baseloc.getScript(), baseloc.getRegion(), baseloc.getVariant()); } return Locale.getInstance(baseloc, extensions); }
< prev index next >