Skip to content

Commit

Permalink
CLDR-18217 Refactor by removing Iterable interface from CLDRFile
Browse files Browse the repository at this point in the history
-Instead of Iterable interface, use new methods iterableDefault, iterableWithoutExtras

-Private boolean CLDRFile.DEFAULT_ITERABLE_INCLUDES_EXTRAS determines whether iterableDefault calls fullIterable or iterableWithoutExtras

-Call iterableWithoutExtras directly where tests would otherwise fail with DEFAULT_ITERABLE_INCLUDES_EXTRAS true

-Rename original iterator method to iteratorWithoutExtras

-Iterable and iterator are distinct: iterableWithoutExtras references iteratorWithoutExtras

-There is not yet any iteratorDefault (only iterableDefault)
  • Loading branch information
btangmu committed Jan 15, 2025
1 parent 3f2d877 commit 054eb6e
Show file tree
Hide file tree
Showing 128 changed files with 287 additions and 243 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ private Entry(CLDRFile f, String t) {
this.file = f;
this.title = t;

for (String s : f) {
for (String s : f.iterableDefault()) {
xpaths.add(s);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2604,7 +2604,7 @@ public static void handleBulkSubmit(
CLDRFile baseFile = stf.make(loc.getBaseName(), false);

Set<String> all = new TreeSet<>();
for (String x : cf) {
for (String x : cf.iterableDefault()) {
if (x.startsWith("//ldml/identity")) {
continue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public SurveyMenus(STFactory stFactory, PathHeader.Factory phf) {

CLDRFile b = stFactory.sm.getEnglishFile();
phf = PathHeader.getFactory(b);
for (String xp : b) {
for (String xp : b.iterableDefault()) {
phf.fromPath(xp);
}
for (String xp : b.getExtraPaths()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public static VettingViewerQueue getInstance() {
*/
private static int pathCount(CLDRFile f) {
int jj = 0;
for (@SuppressWarnings("unused") String s : f) {
for (@SuppressWarnings("unused") String s : f.iterableDefault()) {
jj++;
}
return jj;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ static Response handleGetLocaleErrors(String loc) {
resp.addAll(test.getPossibleProblems());

// add all non-path status
for (final String x : cldrFile) {
for (final String x : cldrFile.iterableDefault()) {
List<CheckStatus> result = new ArrayList<CheckStatus>();
test.check(x, result, cldrFile.getStringValue(x));
for (final CheckStatus s : result) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ private void searchPathsAndValues(WhatisResponse what) {
continue;
}
XpathResult r = null;
for (String xp : f) {
for (String xp : f.iterableDefault()) {
String str = f.getStringValue(xp);
what.pathsSearched++;
if (str.contains(q2)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public void TestBasicFactory() throws SQLException {
STFactory fac = getFactory();
CLDRFile mt = fac.make(locale, false);
BallotBox<User> box = fac.ballotBoxForLocale(locale);
mt.iterator();
mt.iteratorWithoutExtras();
final String somePath = "//ldml/localeDisplayNames/keys/key[@type=\"collation\"]";
box.getValues(somePath);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public void accept(PathOrder order, ValueVisitor visitor) {
Iterator<String> paths;
switch (order) {
case ARBITRARY:
paths = source.iterator();
paths = source.iteratorWithoutExtras();
break;

case NESTED_GROUPING:
Expand All @@ -42,11 +42,11 @@ public void accept(PathOrder order, ValueVisitor visitor) {
// visited
// consecutively. It also (like DTD ordering) greatly improves the performance when
// parsing paths because consecutive paths share common parent elements.
paths = source.iterator(null, Comparator.naturalOrder());
paths = source.iteratorWithoutExtras(null, Comparator.naturalOrder());
break;

case DTD:
paths = source.iterator(null, source.getComparator());
paths = source.iteratorWithoutExtras(null, source.getComparator());
break;

default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ private void showMinimalPairs(

SampleData getSamples(
CLDRFile cldr, int keywordCount, String prefix, Map<String, SampleData> data) {
for (String path : With.in(cldr.iterator(prefix, cldr.getComparator()))) {
for (String path : With.in(cldr.iteratorWithoutExtras(prefix, cldr.getComparator()))) {
if (!path.contains("@count")) {
continue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ public static void main(String[] args) throws IOException {
file.isNonInheriting() ? suppInfo : mainInfo;
final Item main = new TableItem(null);
DtdType dtdType = null;
for (Iterator<String> it = file.iterator("", file.getComparator()); it.hasNext(); ) {
for (Iterator<String> it = file.iteratorWithoutExtras("", file.getComparator());
it.hasNext(); ) {
final String xpath = it.next();
final String fullXpath = file.getFullXPath(xpath);
String value = file.getStringValue(xpath);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,8 @@ private Map<JSONSection, List<CldrItem>> mapPathsToSections(
// read paths in DTD order. The order is critical for JSON processing.
final CLDRFile.Status status = new CLDRFile.Status();
for (Iterator<String> it =
file.iterator("", DtdData.getInstance(fileDtdType).getDtdComparator(null));
file.iteratorWithoutExtras(
"", DtdData.getInstance(fileDtdType).getDtdComparator(null));
it.hasNext(); ) {
int cv = Level.UNDETERMINED.getLevel();
final String path = it.next();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,8 @@ else if (cp >= 0x0030 && cp <= 0x0039) // digits
+ "\"]/substitute";

for (Iterator<String> it =
char_fallbk.iterator(SearchLocation, char_fallbk.getComparator());
char_fallbk.iteratorWithoutExtras(
SearchLocation, char_fallbk.getComparator());
it.hasNext() && !SubFound; ) {
String path = it.next();
substituteString = char_fallbk.getStringValue(path);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public static Map<String, Map<String, String>> buildCustomData(
? "//ldml/numbers/decimalFormats[@numberSystem=\"latn\"]/decimalFormatLength"
: "//ldml/numbers/currencyFormats[@numberSystem=\"latn\"]/currencyFormatLength";

Iterator<String> it = resolvedCldrFile.iterator(prefix);
Iterator<String> it = resolvedCldrFile.iteratorWithoutExtras(prefix);

String styleString = style.toString().toLowerCase(Locale.ENGLISH);
while (it.hasNext()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public void TestCurrencyFormats() {
boolean isPOSIX = locale.indexOf("POSIX") >= 0;
logln("Testing: " + locale);
CLDRFile item = cldrFactory.make(locale, false);
for (String xpath : item) {
for (String xpath : item.iterableDefault()) {
NumericType type = NumericType.getNumericType(xpath);
if (type == NumericType.NOT_NUMERIC) continue;
String value = item.getStringValue(xpath);
Expand Down Expand Up @@ -186,7 +186,7 @@ public void TestCommonChildren() {
// Whenever two values for the same xpath are different, we remove from
// currentValues, and add to
// okValues
for (String xpath : item) {
for (String xpath : item.iterableDefault()) {
if (okValues.contains(xpath)) continue;
if (xpath.startsWith("//ldml/identity/")) continue; // skip identity elements
String v = item.getStringValue(xpath);
Expand Down Expand Up @@ -255,7 +255,7 @@ public void TestThatExemplarsContainAll() {
int count = 0;
localeMissing.clear();
file:
for (String xpath : plain) {
for (String xpath : plain.iterableDefault()) {
for (int i = 0; i < EXEMPLAR_SKIPS.length; ++i) {
if (xpath.indexOf(EXEMPLAR_SKIPS[i]) > 0) continue file; // skip some items.
}
Expand Down Expand Up @@ -512,7 +512,7 @@ public void TestDisplayNameCollisions() {
}
collisions.clear();

for (Iterator<String> it2 = item.iterator(); it2.hasNext(); ) {
for (Iterator<String> it2 = item.iteratorWithoutExtras(); it2.hasNext(); ) {
String xpath = it2.next();
NameType nameType = NameType.fromPath(xpath);
if (nameType == NameType.NONE) continue;
Expand Down Expand Up @@ -551,7 +551,7 @@ public void TestDisplayNameCollisions() {
*/
public static void checkAttributeValidity(
CLDRFile item, Map<String, Set<String>> badCodes, Set<String> xpathFailures) {
for (Iterator<String> it2 = item.iterator(); it2.hasNext(); ) {
for (Iterator<String> it2 = item.iteratorWithoutExtras(); it2.hasNext(); ) {
String xpath = it2.next();
XPathParts parts = XPathParts.getFrozenInstance(item.getFullXPath(xpath));
for (int i = 0; i < parts.size(); ++i) {
Expand Down Expand Up @@ -762,7 +762,7 @@ void getSupplementalData(
boolean SHOW = false;
Factory cldrFactory = Factory.make(CLDRPaths.MAIN_DIRECTORY, ".*");
CLDRFile supp = cldrFactory.make(CLDRFile.SUPPLEMENTAL_NAME, false);
for (Iterator<String> it = supp.iterator(); it.hasNext(); ) {
for (Iterator<String> it = supp.iteratorWithoutExtras(); it.hasNext(); ) {
String path = it.next();
try {
XPathParts parts = XPathParts.getFrozenInstance(supp.getFullXPath(path));
Expand Down Expand Up @@ -1360,7 +1360,7 @@ public void TestNarrowForms() {
// Walk through all the xpaths, adding to currentValues
// Whenever two values for the same xpath are different, we remove from currentValues,
// and add to okValues
for (Iterator<String> it2 = item.iterator(); it2.hasNext(); ) {
for (Iterator<String> it2 = item.iteratorWithoutExtras(); it2.hasNext(); ) {
String xpath = it2.next();
if (xpath.indexOf("[@type=\"narrow\"]") >= 0) {
String value = item.getStringValue(xpath);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ public static Map<Category, CasingType> getSamples(CLDRFile resolved) {
boolean isRoot = "root".equals(resolved.getLocaleID());
Set<String> missing = !DEBUG ? null : new TreeSet<>();

for (String path : resolved) {
for (String path : resolved.iterableDefault()) {
if (!isRoot) {
String locale2 = resolved.getSourceLocaleID(path, null);
if (locale2.equals("root") || locale2.equals("code-fallback")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,8 @@ public CheckCLDR handleSetCldrFileToCheck(

// load gregorian appendItems
for (Iterator<String> it =
resolved.iterator("//ldml/dates/calendars/calendar[@type=\"gregorian\"]");
resolved.iteratorWithoutExtras(
"//ldml/dates/calendars/calendar[@type=\"gregorian\"]");
it.hasNext(); ) {
String path = it.next();
String value = resolved.getWinningValue(path);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -855,7 +855,8 @@ public String getRegionException(String regionCode) {
// Pick up all instances in English where the exemplarCity and territory match
// and include them as exceptions.
exceptions = new HashMap<>();
for (Iterator<String> it = english.iterator(Type.ZONE.getPrefix()); it.hasNext(); ) {
for (Iterator<String> it = english.iteratorWithoutExtras(Type.ZONE.getPrefix());
it.hasNext(); ) {
String xpath = it.next();
if (!xpath.endsWith("/exemplarCity")) continue;
String value = english.getStringValue(xpath);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1686,7 +1686,7 @@ private static void addPrettyPaths(
boolean noaliases,
boolean filterDraft,
Collection<String> target) {
for (Iterator<String> pit = file.iterator(pathFilter); pit.hasNext(); ) {
for (Iterator<String> pit = file.iteratorWithoutExtras(pathFilter); pit.hasNext(); ) {
String path = pit.next();
addPrettyPath(file, pathHeaderFactory, noaliases, filterDraft, target, path);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,8 @@ private static void checkCoverage(String locale) {
CLDRPaths.COMMON_DIRECTORY + "supplemental-temp/coverageLevels2.xml");

CLDRFile cldrFile = testInfo.getCldrFactory().make(locale, true);
Set<String> paths = Builder.with(new TreeSet<String>()).addAll(cldrFile).get();
Set<String> paths =
Builder.with(new TreeSet<String>()).addAll(cldrFile.iterableDefault()).get();
PathHeader.Factory phf = PathHeader.getFactory();
Map<PathHeader, String> diff = new TreeMap<>();
Map<PathHeader, String> same = new TreeMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public static Map<String, Map<DateOrder, String>> getOrderingInfo(
Matcher typeMatcher = PatternCache.get("\\[@type=\"([^\"]*)\"]").matcher("");
int[] soFar = new int[50];
int lenSoFar = 0;
for (String path : resolved) {
for (String path : resolved.iterableDefault()) {
if (DateTimePatternType.STOCK_AVAILABLE_INTERVAL_PATTERNS.contains(
DateTimePatternType.fromPath(path))) {
if (path.contains("[@id=\"Ed\"]")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ private void addAvailableFormatsForFile(
// ...dateTimeFormats/availableFormats/dateFormatItem[@id="..."][@count="..."][@draft="..."]
// ...dateTimeFormats/availableFormats/dateFormatItem[@id="..."][@alt="variant"]
boolean isRoot = file.getLocaleID().equals("root");
for (Iterator<String> it = file.iterator(toppath); it.hasNext(); ) {
for (Iterator<String> it = file.iteratorWithoutExtras(toppath); it.hasNext(); ) {
String path = it.next();
int startIndex = path.indexOf(DATE_FORMAT_ITEM_ID_PREFIX);
if (startIndex < 0 || path.indexOf("[@alt=", startIndex) >= 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,8 @@ static class DeprecatedCodeFixer {
{
Factory cldrFactory = Factory.make(CLDRPaths.MAIN_DIRECTORY, ".*");
CLDRFile supp = cldrFactory.make(CLDRFile.SUPPLEMENTAL_NAME, false);
for (Iterator<String> it = supp.iterator("//supplementalData/metadata/alias/");
for (Iterator<String> it =
supp.iteratorWithoutExtras("//supplementalData/metadata/alias/");
it.hasNext(); ) {
String path = it.next();
XPathParts parts = XPathParts.getFrozenInstance(supp.getFullXPath(path));
Expand Down Expand Up @@ -374,7 +375,7 @@ static Collection<String> getOOData(Factory cldrFactory, String locale) {
System.out.println();
}
CLDRFile item = cldrFactory.make(locale, false);
for (String xpath : item) {
for (String xpath : item.iterableDefault()) {
if (!isGregorianPattern(xpath)) {
continue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ public Map<Long, PathHeader> getIdToPath(Factory factory) {
Map<Long, PathHeader> result = new HashMap<>();
CLDRFile english = factory.make("en", true);
PathHeader.Factory pathHeaders = PathHeader.getFactory(english);
for (String s : english) {
for (String s : english.iterableDefault()) {
long id = StringId.getId(s);
PathHeader pathHeader = pathHeaders.fromPath(s);
result.put(id, pathHeader);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ private static void checkPaths() {
locale + "\t-\t" + english.nameGetter().getNameFromIdentifier(locale));
DtdType dtdType = null;

for (Iterator<String> it = file.iterator(); it.hasNext(); ) {
for (Iterator<String> it = file.iteratorWithoutExtras(); it.hasNext(); ) {
String path = it.next();
if (path.endsWith("/alias")) {
continue;
Expand Down Expand Up @@ -341,7 +341,7 @@ private static void checkPaths() {
}

CLDRFile root = cldrFactory.make("root", true);
for (Iterator<String> it = root.iterator(); it.hasNext(); ) {
for (Iterator<String> it = root.iteratorWithoutExtras(); it.hasNext(); ) {
pathToLocale.removeAll(it.next());
}
if (showInfo)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ public static <T> String showDifference(

private static void testZones(CLDRFile metadata) {
String zoneList = null;
for (Iterator<String> it = metadata.iterator(); it.hasNext(); ) {
for (Iterator<String> it = metadata.iteratorWithoutExtras(); it.hasNext(); ) {
String key = it.next();
if (key.indexOf("\"$tzid\"") >= 0) {
zoneList = metadata.getStringValue(key);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ private void fillMetazoneData(
CLDRFile file,
Relation<String, DateRangeAndZone> mzoneToData,
Relation<String, DateRangeAndZone> zoneToDateRanges) {
for (String path : file) {
for (String path : file.iterableDefault()) {
if (path.contains("/usesMetazone")) {
/*
* Sample: <zone type="Asia/Yerevan"> <usesMetazone to="1991-09-23"
Expand Down Expand Up @@ -787,7 +787,7 @@ public static String format(long date) {
}

boolean fileHasMetazones(CLDRFile file) {
for (String path : file) {
for (String path : file.iterableDefault()) {
if (path.contains("usesMetazone")) return true;
}
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,8 @@ private static void checkAliases() {
CLDRFile en = cldrFactory.make("root", true);
Status status = new Status();
Matcher m = PatternCache.get("gregorian.*dayPeriods").matcher("");
for (Iterator<String> it = en.iterator(null, en.getComparator()); it.hasNext(); ) {
for (Iterator<String> it = en.iteratorWithoutExtras(null, en.getComparator());
it.hasNext(); ) {
String path = it.next();
if (!m.reset(path).find()) {
continue;
Expand Down Expand Up @@ -564,7 +565,7 @@ private static void checkDistinguishing() {
if (cldrFile.isNonInheriting()) {
continue;
}
for (Iterator<String> it2 = cldrFile.iterator(); it2.hasNext(); ) {
for (Iterator<String> it2 = cldrFile.iteratorWithoutExtras(); it2.hasNext(); ) {
String path = it2.next();
if (dtdType == null) {
dtdType = DtdType.fromPath(path);
Expand Down Expand Up @@ -607,7 +608,7 @@ private static void showEnglish() {
String requestedLocale = "en";
CLDRFile cldrFile = cldrFactory.make(requestedLocale, true);
CLDRFile.Status status = new CLDRFile.Status();
for (Iterator<String> it = cldrFile.iterator(); it.hasNext(); ) {
for (Iterator<String> it = cldrFile.iteratorWithoutExtras(); it.hasNext(); ) {
String requestedPath = it.next();
String localeWhereFound = cldrFile.getSourceLocaleID(requestedPath, status);
if (!localeWhereFound.equals(requestedLocale)
Expand Down Expand Up @@ -638,7 +639,8 @@ private static void checkPrivateUse() {
HashMap<String, Set<String>> foundItems = new HashMap<>();
TreeSet<String> problems = new TreeSet<>();
for (Iterator<String> it =
cldrFile.iterator("", new UTF16.StringComparator(true, false, 0));
cldrFile.iteratorWithoutExtras(
"", new UTF16.StringComparator(true, false, 0));
it.hasNext(); ) {
String requestedPath = it.next();
XPathParts parts = XPathParts.getFrozenInstance(requestedPath);
Expand Down Expand Up @@ -714,7 +716,8 @@ static void testPopulous() {
CLDRFile supp = cldrFactory.make("supplementalData", false);
CLDRFile temp = SimpleFactory.makeFile("supplemental");
temp.setNonInheriting(true);
for (Iterator<String> it = supp.iterator(null, supp.getComparator()); it.hasNext(); ) {
for (Iterator<String> it = supp.iteratorWithoutExtras(null, supp.getComparator());
it.hasNext(); ) {
String path = it.next();
String value = supp.getStringValue(path);
String fullPath = supp.getFullXPath(path);
Expand Down
Loading

0 comments on commit 054eb6e

Please sign in to comment.