1
1
/*
2
- * Copyright (c) 2012, 2021 , Oracle and/or its affiliates. All rights reserved.
2
+ * Copyright (c) 2012, 2022 , Oracle and/or its affiliates. All rights reserved.
3
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
4
*
5
5
* This code is free software; you can redistribute it and/or modify it
25
25
26
26
package build .tools .cldrconverter ;
27
27
28
+ import java .io .IOException ;
29
+ import java .nio .file .Files ;
30
+ import java .nio .file .Path ;
28
31
import java .util .ArrayList ;
29
32
import java .util .Arrays ;
30
33
import java .util .EnumSet ;
34
37
import java .util .Map ;
35
38
import java .util .Objects ;
36
39
import java .util .Optional ;
40
+ import java .util .stream .Collectors ;
37
41
import java .util .stream .IntStream ;
38
42
39
43
class Bundle {
@@ -47,21 +51,21 @@ static enum Type {
47
51
FORMATDATA );
48
52
}
49
53
50
- private final static Map <String , Bundle > bundles = new HashMap <>();
54
+ private static final Map <String , Bundle > bundles = new HashMap <>();
51
55
52
- private final static String [] NUMBER_PATTERN_KEYS = {
56
+ private static final String [] NUMBER_PATTERN_KEYS = {
53
57
"NumberPatterns/decimal" ,
54
58
"NumberPatterns/currency" ,
55
59
"NumberPatterns/percent" ,
56
60
"NumberPatterns/accounting"
57
61
};
58
62
59
- private final static String [] COMPACT_NUMBER_PATTERN_KEYS = {
60
- "short.CompactNumberPatterns" ,
61
- "long.CompactNumberPatterns"
63
+ private static final String [] COMPACT_NUMBER_PATTERN_KEYS = {
64
+ "short.CompactNumberPatterns" ,
65
+ "long.CompactNumberPatterns"
62
66
};
63
67
64
- private final static String [] NUMBER_ELEMENT_KEYS = {
68
+ private static final String [] NUMBER_ELEMENT_KEYS = {
65
69
"NumberElements/decimal" ,
66
70
"NumberElements/group" ,
67
71
"NumberElements/list" ,
@@ -77,41 +81,45 @@ static enum Type {
77
81
"NumberElements/currencyGroup" ,
78
82
};
79
83
80
- private final static String [] TIME_PATTERN_KEYS = {
84
+ private static final String [] TIME_PATTERN_KEYS = {
81
85
"DateTimePatterns/full-time" ,
82
86
"DateTimePatterns/long-time" ,
83
87
"DateTimePatterns/medium-time" ,
84
88
"DateTimePatterns/short-time" ,
85
89
};
86
90
87
- private final static String [] DATE_PATTERN_KEYS = {
91
+ private static final String [] DATE_PATTERN_KEYS = {
88
92
"DateTimePatterns/full-date" ,
89
93
"DateTimePatterns/long-date" ,
90
94
"DateTimePatterns/medium-date" ,
91
95
"DateTimePatterns/short-date" ,
92
96
};
93
97
94
- private final static String [] DATETIME_PATTERN_KEYS = {
98
+ private static final String [] DATETIME_PATTERN_KEYS = {
95
99
"DateTimePatterns/full-dateTime" ,
96
100
"DateTimePatterns/long-dateTime" ,
97
101
"DateTimePatterns/medium-dateTime" ,
98
102
"DateTimePatterns/short-dateTime" ,
99
103
};
100
104
101
- private final static String [] ERA_KEYS = {
105
+ private static final String [] ERA_KEYS = {
102
106
"long.Eras" ,
103
107
"Eras" ,
104
108
"narrow.Eras"
105
109
};
106
110
111
+ // DateFormatItem prefix
112
+ static final String DATEFORMATITEM_KEY_PREFIX = "DateFormatItem." ;
113
+ static final String DATEFORMATITEM_INPUT_REGIONS_PREFIX = "DateFormatItemInputRegions." ;
114
+
107
115
// Keys for individual time zone names
108
- private final static String TZ_GEN_LONG_KEY = "timezone.displayname.generic.long" ;
109
- private final static String TZ_GEN_SHORT_KEY = "timezone.displayname.generic.short" ;
110
- private final static String TZ_STD_LONG_KEY = "timezone.displayname.standard.long" ;
111
- private final static String TZ_STD_SHORT_KEY = "timezone.displayname.standard.short" ;
112
- private final static String TZ_DST_LONG_KEY = "timezone.displayname.daylight.long" ;
113
- private final static String TZ_DST_SHORT_KEY = "timezone.displayname.daylight.short" ;
114
- private final static String [] ZONE_NAME_KEYS = {
116
+ private static final String TZ_GEN_LONG_KEY = "timezone.displayname.generic.long" ;
117
+ private static final String TZ_GEN_SHORT_KEY = "timezone.displayname.generic.short" ;
118
+ private static final String TZ_STD_LONG_KEY = "timezone.displayname.standard.long" ;
119
+ private static final String TZ_STD_SHORT_KEY = "timezone.displayname.standard.short" ;
120
+ private static final String TZ_DST_LONG_KEY = "timezone.displayname.daylight.long" ;
121
+ private static final String TZ_DST_SHORT_KEY = "timezone.displayname.daylight.short" ;
122
+ private static final String [] ZONE_NAME_KEYS = {
115
123
TZ_STD_LONG_KEY ,
116
124
TZ_STD_SHORT_KEY ,
117
125
TZ_DST_LONG_KEY ,
@@ -262,7 +270,7 @@ Map<String, Object> getTargetMap() throws Exception {
262
270
CLDRConverter .handleAliases (myMap );
263
271
264
272
// another hack: parentsMap is not used for date-time resources.
265
- if ("root" . equals ( id )) {
273
+ if (isRoot ( )) {
266
274
parentsMap = null ;
267
275
}
268
276
@@ -287,6 +295,14 @@ Map<String, Object> getTargetMap() throws Exception {
287
295
handleDateTimeFormatPatterns (TIME_PATTERN_KEYS , myMap , parentsMap , calendarType , "TimePatterns" );
288
296
handleDateTimeFormatPatterns (DATE_PATTERN_KEYS , myMap , parentsMap , calendarType , "DatePatterns" );
289
297
handleDateTimeFormatPatterns (DATETIME_PATTERN_KEYS , myMap , parentsMap , calendarType , "DateTimePatterns" );
298
+
299
+ // Skeleton
300
+ handleSkeletonPatterns (myMap , calendarType );
301
+ }
302
+
303
+ // Skeleton input regions
304
+ if (isRoot ()) {
305
+ skeletonInputRegions (myMap );
290
306
}
291
307
292
308
// First, weed out any empty timezone or metazone names from myMap.
@@ -647,8 +663,9 @@ private String toMetaZoneKey(String tzKey) {
647
663
private void convertDateTimePatternLetter (CalendarType calendarType , char cldrLetter , int count , StringBuilder sb ) {
648
664
switch (cldrLetter ) {
649
665
case 'u' :
650
- // Change cldr letter 'u' to 'y', as 'u' is interpreted as
651
- // "Extended year (numeric)" in CLDR/LDML,
666
+ case 'U' :
667
+ // Change cldr letter 'u'/'U' to 'y', as 'u' is interpreted as
668
+ // "Extended year (numeric)", and 'U' as "Cyclic year" in CLDR/LDML,
652
669
// which is not supported in SimpleDateFormat and
653
670
// j.t.f.DateTimeFormatter, so it is replaced with 'y'
654
671
// as the best approximation
@@ -742,6 +759,19 @@ private static boolean hasNulls(Object[] array) {
742
759
return false ;
743
760
}
744
761
762
+ private void handleSkeletonPatterns (Map <String , Object > myMap , CalendarType calendarType ) {
763
+ String calendarPrefix = calendarType .keyElementName ();
764
+ myMap .putAll (myMap .entrySet ().stream ()
765
+ .filter (e -> e .getKey ().startsWith (Bundle .DATEFORMATITEM_KEY_PREFIX ))
766
+ .collect (Collectors .toMap (
767
+ e -> calendarPrefix + e .getKey (),
768
+ e -> translateDateFormatLetters (calendarType ,
769
+ (String )e .getValue (),
770
+ this ::convertDateTimePatternLetter )
771
+ ))
772
+ );
773
+ }
774
+
745
775
@ FunctionalInterface
746
776
private interface ConvertDateTimeLetters {
747
777
void convert (CalendarType calendarType , char cldrLetter , int count , StringBuilder sb );
@@ -790,4 +820,14 @@ private String[] createNumberArray(Map<String, Object> myMap, Map<String, Object
790
820
}
791
821
return numArray ;
792
822
}
823
+
824
+ private static void skeletonInputRegions (Map <String , Object > myMap ) {
825
+ myMap .putAll (myMap .entrySet ().stream ()
826
+ .filter (e -> e .getKey ().startsWith (Bundle .DATEFORMATITEM_INPUT_REGIONS_PREFIX ))
827
+ .collect (Collectors .toMap (
828
+ e -> e .getKey (),
829
+ e -> ((String )e .getValue ()).trim ()
830
+ ))
831
+ );
832
+ }
793
833
}
0 commit comments