Skip to content

Commit

Permalink
CLDR-17442 Fix coverage to handle beaufort (unicode-org#3560)
Browse files Browse the repository at this point in the history
  • Loading branch information
macchiati authored Mar 10, 2024
1 parent d045611 commit b828ffb
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@
import java.util.Map.Entry;
import java.util.Objects;
import java.util.Set;
import java.util.SortedSet;
import java.util.TreeMap;
import java.util.TreeSet;
import java.util.concurrent.ConcurrentHashMap;
Expand Down Expand Up @@ -837,7 +836,7 @@ public static String formatDate(Date date) {
}
}

public static class CoverageLevelInfo implements Comparable<CoverageLevelInfo> {
public static class CoverageLevelInfo {
public final String match;
public final Level value;
public final Pattern inLanguage;
Expand Down Expand Up @@ -870,15 +869,6 @@ private Set<String> toSet(String source) {
return Collections.unmodifiableSet(result);
}

@Override
public int compareTo(CoverageLevelInfo o) {
if (value == o.value) {
return match.compareTo(o.match);
} else {
return value.compareTo(o.value);
}
}

public static void fixEU(Collection<CoverageLevelInfo> targets, SupplementalDataInfo info) {
Set<String> euCountries = info.getContained("EU");
for (CoverageLevelInfo item : targets) {
Expand Down Expand Up @@ -1313,7 +1303,7 @@ private void makeStuffSafe() {
bcp47KeyToAliasToSubtype = CldrUtility.protectCollection(bcp47KeyToAliasToSubtype);

CoverageLevelInfo.fixEU(coverageLevels, this);
coverageLevels = Collections.unmodifiableSortedSet(coverageLevels);
coverageLevels = CldrUtility.protectCollection(coverageLevels);

measurementData = CldrUtility.protectCollection(measurementData);

Expand Down Expand Up @@ -2486,7 +2476,7 @@ public int parseIntegerOrNull(String attributeValue) {
private Map<String, String> likelySubtags = new TreeMap<>();
private Map<String, String> likelyOrigins = new TreeMap<>();
// make public temporarily until we resolve.
private SortedSet<CoverageLevelInfo> coverageLevels = new TreeSet<>();
private Set<CoverageLevelInfo> coverageLevels = new LinkedHashSet<>();
private Map<ParentLocaleComponent, Map<String, String>> parentLocales = new HashMap<>();

{ // Prefill, since we know we will need these
Expand Down Expand Up @@ -2776,7 +2766,7 @@ public NumberingSystemType getNumberingSystemType(String numberingSystem) {
return numberingSystems.get(numberingSystem).type;
}

public SortedSet<CoverageLevelInfo> getCoverageLevelInfo() {
public Set<CoverageLevelInfo> getCoverageLevelInfo() {
return coverageLevels;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,9 @@ public void testExtraPaths() {
final CLDRFile cldrFile = fullCldrFactory.make(locale, true);
Set<String> sorted2 = new TreeSet<>(cldrFile.getExtraPaths());
for (String path : sorted2) {
if (path.contains("speed-beaufort")) {
continue; // special case
}
if (path.contains("/gender")
|| path.contains("@gender")
|| path.contains("@case")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,4 +156,28 @@ public void showDiff(String title, Set<CoreItems> all, Set<CoreItems> coreCovera
errln("\t" + title + ": " + diff);
}
}

public void testBeaufort() {
// locale, path, expected coverage
String[][] tests = {
{
"am",
"//ldml/units/unitLength[@type=\"long\"]/unit[@type=\"speed-beaufort\"]/displayName",
"comprehensive"
},
{
"de",
"//ldml/units/unitLength[@type=\"long\"]/unit[@type=\"speed-beaufort\"]/displayName",
"modern"
},
};
for (String[] test : tests) {
String locale = test[0];
String path = test[1];
Level expected = Level.fromString(test[2]);
CoverageLevel2 coverageLevel = CoverageLevel2.getInstance(sdi, locale);
Level actual = coverageLevel.getLevel(path);
assertEquals(String.format("locale:%s, path:%s", locale, path), expected, actual);
}
}
}

0 comments on commit b828ffb

Please sign in to comment.