< prev index next >
src/java.base/share/classes/java/time/format/DateTimeFormatterBuilder.java
Print this page
rev 57289 : [mq]: 8235238
@@ -111,10 +111,11 @@
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Objects;
+import java.util.Optional;
import java.util.Set;
import java.util.TimeZone;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
@@ -4121,11 +4122,12 @@
if (textStyle == TextStyle.NARROW) {
return super.getTree(context);
}
Locale locale = context.getLocale();
boolean isCaseSensitive = context.isCaseSensitive();
- Set<String> regionIds = ZoneRulesProvider.getAvailableZoneIds();
+ Set<String> regionIds = new HashSet<>(ZoneRulesProvider.getAvailableZoneIds());
+ Set<String> nonRegionIds = new HashSet<>(64);
int regionIdsSize = regionIds.size();
Map<Locale, Entry<Integer, SoftReference<PrefixTree>>> cached =
isCaseSensitive ? cachedTree : cachedTreeCI;
@@ -4137,26 +4139,48 @@
(tree = entry.getValue().get()) == null)) {
tree = PrefixTree.newTree(context);
zoneStrings = TimeZoneNameUtility.getZoneStrings(locale);
for (String[] names : zoneStrings) {
String zid = names[0];
- if (!regionIds.contains(zid)) {
+ if (!regionIds.remove(zid)) {
+ nonRegionIds.add(zid);
continue;
}
tree.add(zid, zid); // don't convert zid -> metazone
zid = ZoneName.toZid(zid, locale);
int i = textStyle == TextStyle.FULL ? 1 : 2;
for (; i < names.length; i += 2) {
tree.add(names[i], zid);
}
}
+
+ // add names for provider's custom ids
+ final PrefixTree t = tree;
+ regionIds.stream()
+ .filter(zid -> !zid.startsWith("Etc") && !zid.startsWith("GMT"))
+ .forEach(cid -> {
+ String[] cidNames = TimeZoneNameUtility.retrieveDisplayNames(cid, locale);
+ int i = textStyle == TextStyle.FULL ? 1 : 2;
+ for (; i < cidNames.length; i += 2) {
+ if (cidNames[i] != null && !cidNames[i].isEmpty()) {
+ t.add(cidNames[i], cid);
+ }
+ }
+ // generic name
+ String gName = TimeZoneNameUtility.retrieveGenericDisplayName(
+ cid, textStyle == TextStyle.FULL ? TimeZone.LONG : TimeZone.SHORT, locale);
+ if (gName != null) {
+ t.add(gName, cid);
+ }
+ });
+
// if we have a set of preferred zones, need a copy and
// add the preferred zones again to overwrite
if (preferredZones != null) {
for (String[] names : zoneStrings) {
String zid = names[0];
- if (!preferredZones.contains(zid) || !regionIds.contains(zid)) {
+ if (!preferredZones.contains(zid) || nonRegionIds.contains(zid)) {
continue;
}
int i = textStyle == TextStyle.FULL ? 1 : 2;
for (; i < names.length; i += 2) {
tree.add(names[i], zid);
< prev index next >