ICU-9965 Don't skip availableFormats items from non-root locales if conflict only due to basePattern (J)

X-SVN-Rev: 33359
This commit is contained in:
Peter Edberg 2013-03-04 11:09:41 +00:00
parent 28932c056e
commit 3451781673
2 changed files with 24 additions and 9 deletions

View File

@ -233,6 +233,7 @@ public class DateTimePatternGenerator implements Freezable<DateTimePatternGenera
// fall through
}
boolean override = true;
while (availFormatsBundle != null) {
for (int i = 0; i < availFormatsBundle.getSize(); i++) {
String formatKey = availFormatsBundle.get(i).getKey();
@ -242,7 +243,7 @@ public class DateTimePatternGenerator implements Freezable<DateTimePatternGenera
// Add pattern with its associated skeleton. Override any duplicate derived from std patterns,
// but not a previous availableFormats entry:
String formatValue = availFormatsBundle.get(i).getString();
result.addPatternWithSkeleton(formatValue, formatKey, true, returnInfo);
result.addPatternWithSkeleton(formatValue, formatKey, override, returnInfo);
}
}
@ -255,6 +256,9 @@ public class DateTimePatternGenerator implements Freezable<DateTimePatternGenera
} catch (MissingResourceException e) {
availFormatsBundle = null;
}
if (availFormatsBundle != null && pbundle.getULocale().getBaseName().equals("root")) {
override = false;
}
}
// assume it is always big endian (ok for CLDR right now)
@ -527,14 +531,25 @@ public class DateTimePatternGenerator implements Freezable<DateTimePatternGenera
matcher = new DateTimeMatcher().set(skeletonToUse, fp, false);
}
String basePattern = matcher.getBasePattern();
// We only care about base conflicts - and replacing the pattern associated with a base - if:
// 1. the conflicting previous base pattern did *not* have an explicit skeleton; in that case the previous
// base + pattern combination was derived from either (a) a canonical item, (b) a standard format, or
// (c) a pattern specified programmatically with a previous call to addPattern (which would only happen
// if we are getting here from a subsequent call to addPattern).
// 2. a skeleton is specified for the current pattern, but override=false; in that case we are checking
// availableFormats items from root, which should not override any previous entry with the same base.
PatternWithSkeletonFlag previousPatternWithSameBase = basePattern_pattern.get(basePattern);
if (previousPatternWithSameBase != null) {
if (previousPatternWithSameBase != null && (!previousPatternWithSameBase.skeletonWasSpecified || (skeletonToUse != null && !override))) {
returnInfo.status = PatternInfo.BASE_CONFLICT;
returnInfo.conflictingPattern = previousPatternWithSameBase.pattern;
if (!override || (skeletonToUse != null && previousPatternWithSameBase.skeletonWasSpecified)) {
if (!override) {
return this;
}
}
// The only time we get here with override=true and skeletonToUse!=null is when adding availableFormats
// items from CLDR data. In that case, we don't want an item from a parent locale to replace an item with
// same skeleton from the specified locale, so skip the current item if skeletonWasSpecified is true for
// the previously-specified conflicting item.
PatternWithSkeletonFlag previousValue = skeleton2pattern.get(matcher);
if (previousValue != null) {
returnInfo.status = PatternInfo.CONFLICT;

View File

@ -361,14 +361,14 @@ public class DateTimeGeneratorTest extends TestFmwk {
new String[] {"Md", "1/13"},
new String[] {"MMMd", "1\u670813\u65E5"},
new String[] {"MMMMd", "1\u670813\u65E5"},
new String[] {"yQQQ", "1999/1Q"}, // *** expected result should be "1999Q1" with current data, changed test temporarily to match current result, needs investigation
new String[] {"yQQQ", "1999/1Q"}, // now current data produces y/QQQ => 1999/1Q
new String[] {"hhmm", "\u5348\u5F8C11:58"},
new String[] {"HHmm", "23:58"},
new String[] {"jjmm", "23:58"},
new String[] {"mmss", "58:59"},
new String[] {"yyyyMMMM", "1999\u5E741\u6708"}, // (new item for testing 6872<-5702)
new String[] {"MMMEd", "1\u670813\u65E5\u6C34"},
new String[] {"Ed", "13\u65E5\u6C34"},
new String[] {"MMMEd", "1\u670813\u65E5(\u6C34)"},
new String[] {"Ed", "13\u65E5(\u6C34)"},
new String[] {"jmmssSSS", "23:58:59.123"},
new ULocale("ja@calendar=japanese"), // (new locale for testing ticket 6872<-5702)
new String[] {"yM", "\u5E73\u621011/1"},
@ -384,8 +384,8 @@ public class DateTimeGeneratorTest extends TestFmwk {
new String[] {"jjmm", "23:58"},
new String[] {"mmss", "58:59"},
new String[] {"yyyyMMMM", "\u5E73\u621011\u5E741\u6708"},
new String[] {"MMMEd", "1\u670813\u65E5\u6C34"}, // different than ICU4C's correct result, ICU4J code bug? #9952
new String[] {"Ed", "13\u65E5\u6C34"},
new String[] {"MMMEd", "1\u670813\u65E5(\u6C34)"},
new String[] {"Ed", "13\u65E5(\u6C34)"},
new String[] {"jmmssSSS", "23:58:59.123"},
new ULocale("zh_Hans_CN"),
new String[] {"yM", "1999/1"},
@ -426,7 +426,7 @@ public class DateTimeGeneratorTest extends TestFmwk {
new String[] {"yMMM", "\u042F\u043D\u0432. 1999"},
new String[] {"yMd", "13.01.1999"},
new String[] {"yMMMd", "13 \u044F\u043D\u0432. 1999 \u0433."},
new String[] {"Md", "13.1"},
new String[] {"Md", "13.01"},
new String[] {"MMMd", "13 \u044F\u043D\u0432."},
new String[] {"MMMMd", "13 \u044F\u043D\u0432\u0430\u0440\u044F"},
new String[] {"yQQQ", "1-\u0439 \u043A\u0432. 1999 \u0433."},