From 666d7192aaec51de04b55d967dc1ba3dfa0edc07 Mon Sep 17 00:00:00 2001 From: Helena Aytenfisu Date: Mon, 12 Aug 2024 21:19:13 -0400 Subject: [PATCH] CLDR-7401 Style, formatting fixes --- .../unicode/cldr/test/ExampleGenerator.java | 102 +++++++++++------- .../cldr/unittest/TestExampleGenerator.java | 61 +++++------ 2 files changed, 94 insertions(+), 69 deletions(-) diff --git a/tools/cldr-code/src/main/java/org/unicode/cldr/test/ExampleGenerator.java b/tools/cldr-code/src/main/java/org/unicode/cldr/test/ExampleGenerator.java index b600a438a95..12f2cc2343b 100644 --- a/tools/cldr-code/src/main/java/org/unicode/cldr/test/ExampleGenerator.java +++ b/tools/cldr-code/src/main/java/org/unicode/cldr/test/ExampleGenerator.java @@ -276,26 +276,51 @@ public void setCachingEnabled(boolean enabled) { /* For each calendar type, maps the closest two eras to 2025 * defined in that calendar to their corresponding start/end date. - * Dates are adjusted to be 2 days after official era start date and + * Dates are adjusted to be 2 days after official era start date and * 2 days before era end date to avoid time zone issues. - * TODO: include methods for calendarData in supplementalDataInfo API + * TODO: include methods for calendarData in supplementalDataInfo API * to extract this data directly from supplementaldata.xml - */ - public static final Map> CALENDAR_ERAS = new HashMap>() {{ // month 0-indexed. start/end days adjusted by +/- 2, respectively - put("gregorian", List.of(new GregorianCalendar(0, 11, 29).getTime(), new GregorianCalendar(1, 0, 03).getTime())); - put("japanese", List.of(new GregorianCalendar(1989, 0, 10).getTime(), new GregorianCalendar(2019, 4, 3).getTime())); - put("islamic", List.of(new GregorianCalendar(622, 6, 17).getTime())); - put("chinese", List.of(new GregorianCalendar(-2636, 0, 03).getTime())); - put("hebrew", List.of(new GregorianCalendar(-3760, 9, 9).getTime())); - put("buddhist", List.of(new GregorianCalendar(-542, 0, 03).getTime())); - put("coptic", List.of(new GregorianCalendar(284, 07, 26).getTime(), new GregorianCalendar(284, 07, 31).getTime())); - put("persian", List.of(new GregorianCalendar(622, 0, 03).getTime())); - put("dangi", List.of(new GregorianCalendar(-2332, 0, 03).getTime())); - put("ethiopic", List.of(new GregorianCalendar(8, 07, 26).getTime(), new GregorianCalendar(8, 07, 31).getTime())); - put("ethiopic-amete-alem", List.of(new GregorianCalendar(-5492, 07, 27).getTime())); - put("indian", List.of(new GregorianCalendar(79, 0, 03).getTime())); - put("roc", List.of(new GregorianCalendar(1911, 11, 29).getTime(), new GregorianCalendar(1912, 0, 03).getTime())); - }}; + */ + public static final Map> CALENDAR_ERAS = + new HashMap>() { + { // month 0-indexed. start/end days adjusted by +/- 2, respectively + put( + "gregorian", + List.of( + new GregorianCalendar(0, 11, 29).getTime(), + new GregorianCalendar(1, 0, 03).getTime())); + put( + "japanese", + List.of( + new GregorianCalendar(1989, 0, 10).getTime(), + new GregorianCalendar(2019, 4, 3).getTime())); + put("islamic", List.of(new GregorianCalendar(622, 6, 17).getTime())); + put("chinese", List.of(new GregorianCalendar(-2636, 0, 03).getTime())); + put("hebrew", List.of(new GregorianCalendar(-3760, 9, 9).getTime())); + put("buddhist", List.of(new GregorianCalendar(-542, 0, 03).getTime())); + put( + "coptic", + List.of( + new GregorianCalendar(284, 07, 26).getTime(), + new GregorianCalendar(284, 07, 31).getTime())); + put("persian", List.of(new GregorianCalendar(622, 0, 03).getTime())); + put("dangi", List.of(new GregorianCalendar(-2332, 0, 03).getTime())); + put( + "ethiopic", + List.of( + new GregorianCalendar(8, 07, 26).getTime(), + new GregorianCalendar(8, 07, 31).getTime())); + put( + "ethiopic-amete-alem", + List.of(new GregorianCalendar(-5492, 07, 27).getTime())); + put("indian", List.of(new GregorianCalendar(79, 0, 03).getTime())); + put( + "roc", + List.of( + new GregorianCalendar(1911, 11, 29).getTime(), + new GregorianCalendar(1912, 0, 03).getTime())); + } + }; public CLDRFile getCldrFile() { return cldrFile; @@ -2889,21 +2914,23 @@ private String handleDateRangePattern(String value) { } /** - * Add examples for eras. First checks if there is info for this - * calendar type and this era type in the CALENDAR_ERAS map, then - * generates a sample date based on this info and formats it + * Add examples for eras. First checks if there is info for this calendar type and this era type + * in the CALENDAR_ERAS map, then generates a sample date based on this info and formats it */ private String handleEras(XPathParts parts, String value) { String calendarId = parts.getAttributeValue(3, "type"); String type = parts.getAttributeValue(-1, "type"); - String id = (calendarId.contains("islamic")) ? "islamic" : calendarId; // islamic variations map to same sample + String id = + (calendarId.startsWith("islamic")) + ? "islamic" + : calendarId; // islamic variations map to same sample if (!CALENDAR_ERAS.containsKey(id)) { - return null; + return null; } int typeIndex = Integer.parseInt(type); - if (calendarId.equals("japanese")) { + if (calendarId.equals("japanese")) { if (typeIndex < 235) { // examples only for 2 most recent eras - return null; + return null; } else { typeIndex %= 235; // map to length 2 list } @@ -2918,8 +2945,7 @@ private String handleEras(XPathParts parts, String value) { + skeleton + "\"]"; String dateFormat = cldrFile.getWinningValue(checkPath); - SimpleDateFormat sdf = - icuServiceBuilder.getDateFormat(calendarId, dateFormat); + SimpleDateFormat sdf = icuServiceBuilder.getDateFormat(calendarId, dateFormat); DateFormatSymbols dfs = sdf.getDateFormatSymbols(); String[] eraNames = dfs.getEras(); eraNames[typeIndex] = value; // overwrite era to current value @@ -2929,22 +2955,21 @@ private String handleEras(XPathParts parts, String value) { } /** - * Add examples for quarters for the gregorian calendar, - * matching each quarter type (1, 2, 3, 4) to a corresponding - * sample month and formatting an example with that date + * Add examples for quarters for the gregorian calendar, matching each quarter type (1, 2, 3, 4) + * to a corresponding sample month and formatting an example with that date */ private String handleQuarters(XPathParts parts, String value) { String calendarId = parts.getAttributeValue(3, "type"); if (!calendarId.equals("gregorian")) { return null; } - String width = parts.findAttributeValue("quarterWidth", "type"); + String width = parts.findAttributeValue("quarterWidth", "type"); if (width.equals("narrow")) { - return null; + return null; } String context = parts.findAttributeValue("quarterContext", "type"); - String type = parts.getAttributeValue(-1, "type"); // 1-indexed - int quarterIndex = Integer.parseInt(type) - 1; + String type = parts.getAttributeValue(-1, "type"); // 1-indexed + int quarterIndex = Integer.parseInt(type) - 1; String skeleton = (width.equals("wide")) ? "yQQQQ" : "yQQQ"; String checkPath = "//ldml/dates/calendars/calendar[@type=\"" @@ -2953,8 +2978,7 @@ private String handleQuarters(XPathParts parts, String value) { + skeleton + "\"]"; String dateFormat = cldrFile.getWinningValue(checkPath); - SimpleDateFormat sdf = - icuServiceBuilder.getDateFormat(calendarId, dateFormat); + SimpleDateFormat sdf = icuServiceBuilder.getDateFormat(calendarId, dateFormat); DateFormatSymbols dfs = sdf.getDateFormatSymbols(); int widthVal = width.equals("abbreviated") ? 0 : 1; String[] quarterNames = dfs.getQuarters(0, widthVal); // 0 for formatting @@ -2962,11 +2986,11 @@ private String handleQuarters(XPathParts parts, String value) { dfs.setQuarters(quarterNames, 0, widthVal); sdf.setDateFormatSymbols(dfs); sdf.setTimeZone(ZONE_SAMPLE); - final int[] monthSamples = new int[]{1, 4, 7, 10}; // {feb, may, oct, nov} + final int[] monthSamples = new int[] {1, 4, 7, 10}; // {feb, may, oct, nov} int month = monthSamples[quarterIndex]; - calendar.set(1999, month, 5, 13, 25, 59); + calendar.set(1999, month, 5, 13, 25, 59); Date sample = calendar.getTime(); - return sdf.format(sample); + return sdf.format(sample); } /** diff --git a/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/TestExampleGenerator.java b/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/TestExampleGenerator.java index 3a02a25a569..d8c9ceaca69 100644 --- a/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/TestExampleGenerator.java +++ b/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/TestExampleGenerator.java @@ -2,6 +2,7 @@ import com.google.common.collect.ImmutableSet; import com.ibm.icu.dev.test.TestFmwk; +import com.ibm.icu.impl.Relation; import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; @@ -35,7 +36,6 @@ import org.unicode.cldr.util.SupplementalDataInfo.PluralType; import org.unicode.cldr.util.UnitPathType; import org.unicode.cldr.util.With; -import com.ibm.icu.impl.Relation; public class TestExampleGenerator extends TestFmwk { @@ -1652,50 +1652,53 @@ public void TestEraMap() { ExampleGenerator exampleGenerator = getExampleGenerator("en"); Relation keyToSubtypes = SupplementalDataInfo.getInstance().getBcp47Keys(); Set calendars = keyToSubtypes.get("ca"); // gets calendar codes - Map codeToType = new HashMap() {{ // calendars where code != type - put("gregory", "gregorian"); - put("ethioaa", "ethiopic-amete-alem"); - put("islamic-civil", "islamic"); - put("islamic-rgsa", "islamic"); - put("islamic-tbla", "islamic"); - put("islamic-umalqura", "islamic"); - put("islamicc", "islamic"); - }}; + Map codeToType = + new HashMap() { + { // calendars where code != type + put("gregory", "gregorian"); + put("iso8601", "gregorian"); + put("ethioaa", "ethiopic-amete-alem"); + put("islamic-civil", "islamic"); + put("islamic-rgsa", "islamic"); + put("islamic-tbla", "islamic"); + put("islamic-umalqura", "islamic"); + put("islamicc", "islamic"); + } + }; for (String id : calendars) { - if (id.equals("iso8601")) { // generic - continue; - } if (codeToType.containsKey(id)) { id = codeToType.get(id); } Map> calendarMap = exampleGenerator.CALENDAR_ERAS; - assertTrue("CALENDAR_ERAS map contains calendar type \"" + id + "\"", calendarMap.containsKey(id)); - } + assertTrue( + "CALENDAR_ERAS map contains calendar type \"" + id + "\"", + calendarMap.containsKey(id)); + } } - public void TestEraFormats() { + public void TestEraFormats() { ExampleGenerator exampleGeneratorJa = getExampleGenerator("ja"); ExampleGenerator exampleGeneratorEs = getExampleGenerator("es"); ExampleGenerator exampleGeneratorZh = getExampleGenerator("zh"); checkValue( - "japanese type=235 abbreviated", - "〖平成1年〗", - exampleGeneratorJa, + "japanese type=235 abbreviated", + "〖平成1年〗", + exampleGeneratorJa, "//ldml/dates/calendars/calendar[@type=\"japanese\"]/eras/eraAbbr/era[@type=\"235\"]"); checkValue( - "gregorian type=0 wide", - "〖1 antes de Cristo〗", - exampleGeneratorEs, + "gregorian type=0 wide", + "〖1 antes de Cristo〗", + exampleGeneratorEs, "//ldml/dates/calendars/calendar[@type=\"gregorian\"]/eras/eraNames/era[@type=\"0\"]"); checkValue( - "gregorian type=0-variant wide", - "〖1 antes de la era común〗", - exampleGeneratorEs, + "gregorian type=0-variant wide", + "〖1 antes de la era común〗", + exampleGeneratorEs, "//ldml/dates/calendars/calendar[@type=\"gregorian\"]/eras/eraNames/era[@type=\"0\"][@alt=\"variant\"]"); checkValue( - "roc type=1 abbreviated", - "〖民国1年〗", - exampleGeneratorZh, + "roc type=1 abbreviated", + "〖民国1年〗", + exampleGeneratorZh, "//ldml/dates/calendars/calendar[@type=\"roc\"]/eras/eraAbbr/era[@type=\"1\"]"); } @@ -1723,5 +1726,3 @@ public void TestQuarterFormats() { "//ldml/dates/calendars/calendar[@type=\"gregorian\"]/quarters/quarterContext[@type=\"stand-alone\"]/quarterWidth[@type=\"abbreviated\"]/quarter[@type=\"4\"]"); } } - -