LocaleExtensions(Map<CaseInsensitiveChar, String> extensions,
Set<CaseInsensitiveString> uattributes,
Map<CaseInsensitiveString, String> ukeywords) {
boolean hasExtension = !LocaleUtils.isEmpty(extensions);
boolean hasUAttributes = !LocaleUtils.isEmpty(uattributes);
boolean hasUKeywords = !LocaleUtils.isEmpty(ukeywords);
if (!hasExtension && !hasUAttributes && !hasUKeywords) {
id = "";
extensionMap = Collections.emptyMap();
return;
}
// Build extension map
SortedMap< Character, Extension > map = new TreeMap< >();
if (hasExtension) {
for (Entry< CaseInsensitiveChar, String > ext : extensions.entrySet()) {
char key = LocaleUtils.toLower(ext.getKey().value());
String value = ext.getValue();
if (LanguageTag.isPrivateusePrefixChar(key)) {
// we need to exclude special variant in privuateuse, e.g. "x-abc-lvariant-DEF"
value = InternalLocaleBuilder.removePrivateuseVariant(value);
if (value == null) {
continue;
}
}
map.put(key, new Extension(key, LocaleUtils.toLowerString(value)));
}
}
if (hasUAttributes || hasUKeywords) {
SortedSet< String > uaset = null;
SortedMap< String, String > ukmap = null;
if (hasUAttributes) {
uaset = new TreeSet< >();
for (CaseInsensitiveString cis : uattributes) {
uaset.add(LocaleUtils.toLowerString(cis.value()));
}
}
if (hasUKeywords) {
ukmap = new TreeMap< >();
for (Entry< CaseInsensitiveString, String > kwd : ukeywords.entrySet()) {
String key = LocaleUtils.toLowerString(kwd.getKey().value());
String type = LocaleUtils.toLowerString(kwd.getValue());
ukmap.put(key, type);
}
}
UnicodeLocaleExtension ule = new UnicodeLocaleExtension(uaset, ukmap);
map.put(UnicodeLocaleExtension.SINGLETON, ule);
}
if (map.isEmpty()) {
// this could happen when only privuateuse with special variant
id = "";
extensionMap = Collections.emptyMap();
} else {
id = toID(map);
extensionMap = map;
}
}
|