Mercurial > hg > openjdk > jdk8u > jdk
changeset 13458:bc0a3a91a074
8202088: Japanese new era implementation
8207152: Placeholder for Japanese new era should be two characters
8211398: Square character support for the Japanese new era
8180469: Wrong short form text for supplemental Japanese era
8206120: Add test cases for lenient Japanese era parsing
8218915: Change isJavaIdentifierStart and isJavaIdentifierPart to handle new code points
8217710: Add 5 currency code points to Java SE 8uX
Reviewed-by: coffeys, naoto
Contributed-by: deepak.kejriwal@oracle.com
line wrap: on
line diff
--- a/make/data/characterdata/CharacterData00.java.template Fri Mar 01 00:55:45 2019 +0000 +++ b/make/data/characterdata/CharacterData00.java.template Fri Feb 22 14:47:49 2019 +0530 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2019, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -105,11 +105,21 @@ } boolean isJavaIdentifierStart(int ch) { + // isJavaIdentifierStart strictly conforms to code points assigned + // in Unicode 6.2. Since code points {32FF} and {20BB..20BF} are not + // from Unicode 6.2, return false. + if(ch == 0x32FF || (ch>= 0x20BB && ch<= 0x20BF)) + return false; int props = getProperties(ch); return ((props & $$maskIdentifierInfo) >= $$lowJavaStart); } boolean isJavaIdentifierPart(int ch) { + // isJavaIdentifierPart strictly conforms to code points assigned + // in Unicode 6.2. Since code points {32FF} and {20BB..20BF} are not + // from Unicode 6.2, return false. + if(ch == 0x32FF || (ch>= 0x20BB && ch<= 0x20BF)) + return false; int props = getProperties(ch); return ((props & $$nonzeroJavaPart) != 0); }
--- a/make/data/unicodedata/UnicodeData.txt Fri Mar 01 00:55:45 2019 +0000 +++ b/make/data/unicodedata/UnicodeData.txt Fri Feb 22 14:47:49 2019 +0530 @@ -7191,6 +7191,11 @@ 20B8;TENGE SIGN;Sc;0;ET;;;;;N;;;;; 20B9;INDIAN RUPEE SIGN;Sc;0;ET;;;;;N;;;;; 20BA;TURKISH LIRA SIGN;Sc;0;ET;;;;;N;;;;; +20BB;NORDIC MARK SIGN;Sc;0;ET;;;;;N;;;;; +20BC;MANAT SIGN;Sc;0;ET;;;;;N;;;;; +20BD;RUBLE SIGN;Sc;0;ET;;;;;N;;;;; +20BE;LARI SIGN;Sc;0;ET;;;;;N;;;;; +20BF;BITCOIN SIGN;Sc;0;ET;;;;;N;;;;; 20D0;COMBINING LEFT HARPOON ABOVE;Mn;230;NSM;;;;;N;NON-SPACING LEFT HARPOON ABOVE;;;; 20D1;COMBINING RIGHT HARPOON ABOVE;Mn;230;NSM;;;;;N;NON-SPACING RIGHT HARPOON ABOVE;;;; 20D2;COMBINING LONG VERTICAL LINE OVERLAY;Mn;1;NSM;;;;;N;NON-SPACING LONG VERTICAL BAR OVERLAY;;;; @@ -11403,6 +11408,7 @@ 32FC;CIRCLED KATAKANA WI;So;0;L;<circle> 30F0;;;;N;;;;; 32FD;CIRCLED KATAKANA WE;So;0;L;<circle> 30F1;;;;N;;;;; 32FE;CIRCLED KATAKANA WO;So;0;L;<circle> 30F2;;;;N;;;;; +32FF;SQUARE ERA NAME NEWERA;So;0;L;<square> 5143 53F7;;;;N;SQUARED TWO IDEOGRAPHS ERA NAME NEWERA;;;; 3300;SQUARE APAATO;So;0;L;<square> 30A2 30D1 30FC 30C8;;;;N;SQUARED APAATO;;;; 3301;SQUARE ARUHUA;So;0;L;<square> 30A2 30EB 30D5 30A1;;;;N;SQUARED ARUHUA;;;; 3302;SQUARE ANPEA;So;0;L;<square> 30A2 30F3 30DA 30A2;;;;N;SQUARED ANPEA;;;;
--- a/src/share/classes/java/lang/Character.java Fri Mar 01 00:55:45 2019 +0000 +++ b/src/share/classes/java/lang/Character.java Fri Feb 22 14:47:49 2019 +0530 @@ -3928,7 +3928,9 @@ 0x3220, // 3220..325F; COMMON 0x3260, // 3260..327E; HANGUL 0x327F, // 327F..32CF; COMMON - 0x32D0, // 32D0..3357; KATAKANA + 0x32D0, // 32D0..32FE; KATAKANA + 0x32FF, // 32FF ; COMMON + 0x3300, // 3300..3357; KATAKANA 0x3358, // 3358..33FF; COMMON 0x3400, // 3400..4DBF; HAN 0x4DC0, // 4DC0..4DFF; COMMON @@ -4249,7 +4251,9 @@ COMMON, HANGUL, COMMON, - KATAKANA, + KATAKANA, // 32D0..32FE + COMMON, // 32FF + KATAKANA, // 3300..3357 COMMON, HAN, COMMON,
--- a/src/share/classes/java/time/chrono/JapaneseEra.java Fri Mar 01 00:55:45 2019 +0000 +++ b/src/share/classes/java/time/chrono/JapaneseEra.java Fri Feb 22 14:47:49 2019 +0530 @@ -150,10 +150,15 @@ * which has the value 2. */ public static final JapaneseEra HEISEI = new JapaneseEra(2, LocalDate.of(1989, 1, 8)); + /** + * The singleton instance for the 'NewEra' era (2019-05-01 - current) + * which has the value 3. + */ + private static final JapaneseEra NEWERA = new JapaneseEra(3, LocalDate.of(2019, 5, 1)); // The number of predefined JapaneseEra constants. // There may be a supplemental era defined by the property. - private static final int N_ERA_CONSTANTS = HEISEI.getValue() + ERA_OFFSET; + private static final int N_ERA_CONSTANTS = NEWERA.getValue() + ERA_OFFSET; /** * Serialization version. @@ -171,6 +176,7 @@ KNOWN_ERAS[1] = TAISHO; KNOWN_ERAS[2] = SHOWA; KNOWN_ERAS[3] = HEISEI; + KNOWN_ERAS[4] = NEWERA; for (int i = N_ERA_CONSTANTS; i < ERA_CONFIG.length; i++) { CalendarDate date = ERA_CONFIG[i].getSinceDate(); LocalDate isoDate = LocalDate.of(date.getYear(), date.getMonth(), date.getDayOfMonth());
--- a/src/share/classes/java/util/JapaneseImperialCalendar.java Fri Mar 01 00:55:45 2019 +0000 +++ b/src/share/classes/java/util/JapaneseImperialCalendar.java Fri Feb 22 14:47:49 2019 +0530 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 2019, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -50,6 +50,7 @@ * 2 Taisho 1912-07-30 midnight local time * 3 Showa 1926-12-25 midnight local time * 4 Heisei 1989-01-08 midnight local time + * 5 NewEra 2019-05-01 midnight local time * ------------------------------------------------------ * </tt></pre> * @@ -101,6 +102,11 @@ */ public static final int HEISEI = 4; + /** + * The ERA constant designating the NewEra era. + */ + private static final int NEWERA = 5; + private static final int EPOCH_OFFSET = 719163; // Fixed date of January 1, 1970 (Gregorian) private static final int EPOCH_YEAR = 1970; @@ -133,6 +139,9 @@ // Fixed date of the first date of each era. private static final long[] sinceFixedDates; + // The current era + private static final int currentEra; + /* * <pre> * Greatest Least @@ -228,13 +237,18 @@ // eras[BEFORE_MEIJI] and sinceFixedDate[BEFORE_MEIJI] are the // same as Gregorian. int index = BEFORE_MEIJI; + int current = index; sinceFixedDates[index] = gcal.getFixedDate(BEFORE_MEIJI_ERA.getSinceDate()); eras[index++] = BEFORE_MEIJI_ERA; for (Era e : es) { + if(e.getSince(TimeZone.NO_TIMEZONE) < System.currentTimeMillis()) { + current = index; + } CalendarDate d = e.getSinceDate(); sinceFixedDates[index] = gcal.getFixedDate(d); eras[index++] = e; } + currentEra = current; LEAST_MAX_VALUES[ERA] = MAX_VALUES[ERA] = eras.length - 1; @@ -1713,12 +1727,12 @@ } } else if (transitionYear) { if (jdate.getYear() == 1) { - // As of Heisei (since Meiji) there's no case + // As of NewEra (since Meiji) there's no case // that there are multiple transitions in a // year. Historically there was such // case. There might be such case again in the // future. - if (era > HEISEI) { + if (era > NEWERA) { CalendarDate pd = eras[era - 1].getSinceDate(); if (normalizedYear == pd.getYear()) { d.setMonth(pd.getMonth()).setDayOfMonth(pd.getDayOfMonth()); @@ -1853,7 +1867,7 @@ year = isSet(YEAR) ? internalGet(YEAR) : 1; } else { if (isSet(YEAR)) { - era = eras.length - 1; + era = currentEra; year = internalGet(YEAR); } else { // Equivalent to 1970 (Gregorian) @@ -2337,7 +2351,7 @@ * default ERA is the current era, but a zero (unset) ERA means before Meiji. */ private int internalGetEra() { - return isSet(ERA) ? internalGet(ERA) : eras.length - 1; + return isSet(ERA) ? internalGet(ERA) : currentEra; } /**
--- a/src/share/classes/sun/text/resources/FormatData.java Fri Mar 01 00:55:45 2019 +0000 +++ b/src/share/classes/sun/text/resources/FormatData.java Fri Feb 22 14:47:49 2019 +0530 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1996, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1996, 2019, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -106,6 +106,7 @@ "T", "S", "H", + "N", // NewEra }; // Japanese imperial calendar era strings @@ -115,6 +116,7 @@ "Taisho", "Showa", "Heisei", + "NewEra", // NewEra }; return new Object[][] {
--- a/src/share/classes/sun/text/resources/JavaTimeSupplementary.java Fri Mar 01 00:55:45 2019 +0000 +++ b/src/share/classes/sun/text/resources/JavaTimeSupplementary.java Fri Feb 22 14:47:49 2019 +0530 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 2019, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -237,6 +237,7 @@ "Taisho", "Showa", "Heisei", + "NewEra", // New Era } }, { "java.time.japanese.short.Eras", @@ -246,6 +247,7 @@ "Taisho", "Showa", "Heisei", + "NewEra", // New Era } }, { "java.time.roc.DatePatterns",
--- a/src/share/classes/sun/text/resources/ja/FormatData_ja.java Fri Mar 01 00:55:45 2019 +0000 +++ b/src/share/classes/sun/text/resources/ja/FormatData_ja.java Fri Feb 22 14:47:49 2019 +0530 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1996, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1996, 2019, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -91,6 +91,7 @@ "\u5927\u6b63", // Taisho "\u662d\u548c", // Showa "\u5e73\u6210", // Heisei + "\u5143\u53f7", // NewEra }; final String[] rocEras = { "\u6c11\u56fd\u524d",
--- a/src/share/classes/sun/text/resources/ja/JavaTimeSupplementary_ja.java Fri Mar 01 00:55:45 2019 +0000 +++ b/src/share/classes/sun/text/resources/ja/JavaTimeSupplementary_ja.java Fri Feb 22 14:47:49 2019 +0530 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 2019, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -198,6 +198,7 @@ "\u5927\u6b63", "\u662d\u548c", "\u5e73\u6210", + "\u5143\u53f7", // NewEra } }, { "java.time.japanese.short.Eras", @@ -207,6 +208,7 @@ "\u5927\u6b63", "\u662d\u548c", "\u5e73\u6210", + "\u5143\u53f7", // NewEra } }, { "java.time.long.Eras",
--- a/src/share/classes/sun/util/calendar/Era.java Fri Mar 01 00:55:45 2019 +0000 +++ b/src/share/classes/sun/util/calendar/Era.java Fri Feb 22 14:47:49 2019 +0530 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2005, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2019, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -49,6 +49,7 @@ * Taisho 1912-07-30 midnight local time * Showa 1926-12-26 midnight local time * Heisei 1989-01-08 midnight local time + * NewEra 2019-05-01 midnight local time * Julian calendar BeforeCommonEra -292275055-05-16T16:47:04.192Z * CommonEra 0000-12-30 midnight local time * Taiwanese calendar MinGuo 1911-01-01 midnight local time
--- a/src/share/classes/sun/util/locale/provider/CalendarNameProviderImpl.java Fri Mar 01 00:55:45 2019 +0000 +++ b/src/share/classes/sun/util/locale/provider/CalendarNameProviderImpl.java Fri Feb 22 14:47:49 2019 +0530 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2017, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2019, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -35,8 +35,8 @@ import sun.util.calendar.Era; /** - * Concrete implementation of the {@link java.util.spi.CalendarDataProvider - * CalendarDataProvider} class for the JRE LocaleProviderAdapter. + * Concrete implementation of the {@link java.util.spi.CalendarNameProvider + * CalendarNameProvider} class for the JRE LocaleProviderAdapter. * * @author Masayoshi Okutsu * @author Naoto Sato @@ -69,23 +69,44 @@ if (field == DAY_OF_WEEK || field == YEAR) { --value; } - if (value < 0 || value > strings.length) { + if (value < 0) { return null; - } else if (value == strings.length) { + } else if (value >= strings.length) { if (field == ERA && "japanese".equals(calendarType)) { - // get the supplemental era, if any, specified through - // the property "jdk.calendar.japanese.supplemental.era" - // which is always the last element. Era[] jeras = CalendarSystem.forName("japanese").getEras(); - if (jeras.length == value) { + if (value <= jeras.length) { + // Localized era name could not be retrieved from this provider. + // This can occur either for NewEra or SupEra. + // + // If it's CLDR provider, try COMPAT first, which is guaranteed to have + // the name for NewEra. + if (type == LocaleProviderAdapter.Type.CLDR) { + lr = LocaleProviderAdapter.forJRE().getLocaleResources(locale); + key = getResourceKeyFor(LocaleProviderAdapter.Type.JRE, + calendarType, field, style, javatime); + strings = + javatime ? lr.getJavaTimeNames(key) : lr.getCalendarNames(key); + } + if (strings == null || value >= strings.length) { + // Get the default name for SupEra Era supEra = jeras[value - 1]; // 0-based index - return style == LONG ? + if (javatime) { + return getBaseStyle(style) == NARROW_FORMAT ? + supEra.getAbbreviation() : + supEra.getName(); + } else { + return (style & LONG) != 0 ? supEra.getName() : supEra.getAbbreviation(); } } + } else { return null; } + } else { + return null; + } + } name = strings[value]; // If name is empty in standalone, try its `format' style. if (name.length() == 0 @@ -158,7 +179,7 @@ return map; } - private int getBaseStyle(int style) { + private static int getBaseStyle(int style) { return style & ~(SHORT_STANDALONE - SHORT_FORMAT); } @@ -239,6 +260,11 @@ } private String getResourceKey(String type, int field, int style, boolean javatime) { + return getResourceKeyFor(this.type, type, field, style, javatime); + } + + private static String getResourceKeyFor(LocaleProviderAdapter.Type adapterType, + String type, int field, int style, boolean javatime) { int baseStyle = getBaseStyle(style); boolean isStandalone = (style != baseStyle); @@ -262,7 +288,7 @@ // JRE and CLDR use different resource key conventions // due to historical reasons. (JRE DateFormatSymbols.getEras returns // abbreviations while other getShort*() return abbreviations.) - if (this.type == LocaleProviderAdapter.Type.JRE) { + if (adapterType == LocaleProviderAdapter.Type.JRE) { if (javatime) { if (baseStyle == LONG) { key.append("long."); @@ -314,7 +340,7 @@ return key.length() > 0 ? key.toString() : null; } - private String toStyleName(int baseStyle) { + private static String toStyleName(int baseStyle) { switch (baseStyle) { case SHORT: return "Abbreviations";
--- a/src/share/lib/calendars.properties Fri Mar 01 00:55:45 2019 +0000 +++ b/src/share/lib/calendars.properties Fri Feb 22 14:47:49 2019 +0530 @@ -29,12 +29,14 @@ # Taisho since 1912-07-30 00:00:00 local time (Gregorian) # Showa since 1926-12-25 00:00:00 local time (Gregorian) # Heisei since 1989-01-08 00:00:00 local time (Gregorian) +# NewEra since 2019-05-01 00:00:00 local time (Gregorian) calendar.japanese.type: LocalGregorianCalendar calendar.japanese.eras: \ name=Meiji,abbr=M,since=-3218832000000; \ name=Taisho,abbr=T,since=-1812153600000; \ name=Showa,abbr=S,since=-1357603200000; \ - name=Heisei,abbr=H,since=600220800000 + name=Heisei,abbr=H,since=600220800000; \ + name=NewEra,abbr=N,since=1556668800000 # # Taiwanese calendar
--- a/test/java/lang/Character/Scripts.txt Fri Mar 01 00:55:45 2019 +0000 +++ b/test/java/lang/Character/Scripts.txt Fri Feb 22 14:47:49 2019 +0530 @@ -147,6 +147,7 @@ 208D ; Common # Ps SUBSCRIPT LEFT PARENTHESIS 208E ; Common # Pe SUBSCRIPT RIGHT PARENTHESIS 20A0..20BA ; Common # Sc [27] EURO-CURRENCY SIGN..TURKISH LIRA SIGN +20BB..20BF ; Common # Sc [5] NORDIC MARK SIGN..BITCOIN SIGN 2100..2101 ; Common # So [2] ACCOUNT OF..ADDRESSED TO THE SUBJECT 2102 ; Common # L& DOUBLE-STRUCK CAPITAL C 2103..2106 ; Common # So [4] DEGREE CELSIUS..CADA UNA @@ -381,6 +382,7 @@ 328A..32B0 ; Common # So [39] CIRCLED IDEOGRAPH MOON..CIRCLED IDEOGRAPH NIGHT 32B1..32BF ; Common # No [15] CIRCLED NUMBER THIRTY SIX..CIRCLED NUMBER FIFTY 32C0..32CF ; Common # So [16] IDEOGRAPHIC TELEGRAPH SYMBOL FOR JANUARY..LIMITED LIABILITY SIGN +32FF ; Common # So SQUARE ERA NAME NEWERA 3358..33FF ; Common # So [168] IDEOGRAPHIC TELEGRAPH SYMBOL FOR HOUR ZERO..SQUARE GAL 4DC0..4DFF ; Common # So [64] HEXAGRAM FOR THE CREATIVE HEAVEN..HEXAGRAM FOR BEFORE COMPLETION A700..A716 ; Common # Sk [23] MODIFIER LETTER CHINESE TONE YIN PING..MODIFIER LETTER EXTRA-LOW LEFT-STEM TONE BAR
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/java/lang/Character/TestIsJavaIdentifierMethods.java Fri Feb 22 14:47:49 2019 +0530 @@ -0,0 +1,309 @@ +/* + * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/** + * @test + * @summary Test behavior of isJavaIdentifierXX, testIsJavaLetter, and + * testIsJavaLetterOrDigit methods for all code points. + * @bug 8218915 + */ + +import java.util.List; +import java.util.ArrayList; + +public class TestIsJavaIdentifierMethods { + + // List of new code points are not present in Unicode 6.2. + private static final List<Integer> UNASSIGNED_CODEPOINTS_IN_6_2 + = new ArrayList<Integer>() + {{ + add(0x20BB); // NORDIC MARK SIGN + add(0x20BC); // MANAT SIGN + add(0x20BD); // RUBLE SIGN + add(0x20BE); // LARI SIGN + add(0x20BF); // BITCOIN SIGN + add(0x32FF); // SQUARE ERA NAME NEWERA + }}; + + public static void main(String[] args) { + testIsJavaIdentifierPart_int(); + testIsJavaIdentifierPart_char(); + testIsJavaIdentifierStart_int(); + testIsJavaIdentifierStart_char(); + testIsJavaLetter(); + testIsJavaLetterOrDigit(); + } + + /** + * Assertion testing for public static boolean isJavaIdentifierPart(int + * codePoint), A character may be part of a Java identifier if any of the + * following are true: + * <ul> + * <li>it is a letter</li> + * <li>it is a currency symbol (such as <code>'$'</code>)</li> + * <li>it is a connecting punctuation character (such as <code>'_'</code>) + * </li> + * <li>it is a digit</li> + * <li>it is a numeric letter (such as a Roman numeral character)</li> + * <li>it is a combining mark</li> + * <li>it is a non-spacing mark</li> + * <li><code>isIdentifierIgnorable</code> returns <code>true</code> for the + * character</li> + * </ul> + * All code points from (0x0000..0x10FFFF) are tested. + */ + public static void testIsJavaIdentifierPart_int() { + for (int cp = 0; cp <= Character.MAX_CODE_POINT; cp++) { + boolean expected = false; + + // Since Character.isJavaIdentifierPart(int) strictly conforms to + // character information from version 6.2 of the Unicode Standard, + // check if code point is in "UNASSIGNED_CODEPOINTS_IN_6_2" + // list. If the code point is found in list + // "UNASSIGNED_CODEPOINTS_IN_6_2", value of variable + // "expected" is considered false. + if (!UNASSIGNED_CODEPOINTS_IN_6_2.contains(cp)) { + byte type = (byte) Character.getType(cp); + expected = Character.isLetter(cp) + || type == Character.CURRENCY_SYMBOL + || type == Character.CONNECTOR_PUNCTUATION + || Character.isDigit(cp) + || type == Character.LETTER_NUMBER + || type == Character.COMBINING_SPACING_MARK + || type == Character.NON_SPACING_MARK + || Character.isIdentifierIgnorable(cp); + } + + if (Character.isJavaIdentifierPart(cp) != expected) { + throw new RuntimeException( + "Character.isJavaIdentifierPart(int) failed for codepoint " + + Integer.toHexString(cp)); + } + } + } + + /** + * Assertion testing for public static boolean isJavaIdentifierPart(char + * ch), A character may be part of a Java identifier if any of the + * following are true: + * <ul> + * <li>it is a letter; + * <li>it is a currency symbol (such as "$"); + * <li>it is a connecting punctuation character (such as "_"); + * <li>it is a digit; + * <li>it is a numeric letter (such as a Roman numeral character); + * <li>it is a combining mark; + * <li>it is a non-spacing mark; + * <li>isIdentifierIgnorable returns true for the character. + * </ul> + * All Unicode code points in the BMP (0x0000..0xFFFF) are tested. + */ + public static void testIsJavaIdentifierPart_char() { + for (int i = 0; i <= Character.MAX_VALUE; ++i) { + char ch = (char) i; + boolean expected = false; + // Since Character.isJavaIdentifierPart(char) strictly conforms to + // character information from version 6.2 of the Unicode Standard, + // check if code point is in "UNASSIGNED_CODEPOINTS_IN_6_2" + // list. If the code point is found in list + // "UNASSIGNED_CODEPOINTS_IN_6_2", value of variable + // "expected" is considered false. + if (!UNASSIGNED_CODEPOINTS_IN_6_2.contains(i)) { + byte type = (byte) Character.getType(ch); + expected = Character.isLetter(ch) + || type == Character.CURRENCY_SYMBOL + || type == Character.CONNECTOR_PUNCTUATION + || Character.isDigit(ch) + || type == Character.LETTER_NUMBER + || type == Character.COMBINING_SPACING_MARK + || type == Character.NON_SPACING_MARK + || Character.isIdentifierIgnorable(ch); + } + + if (Character.isJavaIdentifierPart((char) i) != expected) { + throw new RuntimeException( + "Character.isJavaIdentifierPart(char) failed for codepoint " + + Integer.toHexString(i)); + } + } + } + + /** + * Assertion testing for public static boolean isJavaIdentifierStart(int + * codePoint), A character may start a Java identifier if and only if it is + * one of the following: + * <ul> + * <li>it is a letter;</li> + * <li>getType(ch) returns LETTER_NUMBER;</li> + * <li>it is a currency symbol (such as "$");</li> + * <li>it is a connecting punctuation character (such as "_");</li> + * </ul> + * All Code points from (0x0000..0x10FFFF) are tested. + */ + public static void testIsJavaIdentifierStart_int() { + for (int cp = 0; cp <= Character.MAX_CODE_POINT; cp++) { + boolean expected = false; + // Since Character.isJavaIdentifierStart(int) strictly conforms to + // character information from version 6.2 of the Unicode Standard, + // check if code point is in "UNASSIGNED_CODEPOINTS_IN_6_2" + // list. If the code point is found in list + // "UNASSIGNED_CODEPOINTS_IN_6_2", value of variable + // "expected" is considered false. + if (!UNASSIGNED_CODEPOINTS_IN_6_2.contains(cp)) { + byte type = (byte) Character.getType(cp); + expected = Character.isLetter(cp) + || type == Character.LETTER_NUMBER + || type == Character.CURRENCY_SYMBOL + || type == Character.CONNECTOR_PUNCTUATION; + } + + if (Character.isJavaIdentifierStart(cp) != expected) { + throw new RuntimeException( + "Character.isJavaIdentifierStart(int) failed for codepoint " + + Integer.toHexString(cp)); + } + } + } + + /** + * Assertion testing for public static boolean isJavaIdentifierStart(char), + * A character may start a Java identifier if and only if it is + * one of the following: + * <ul> + * <li>it is a letter;</li> + * <li>getType(ch) returns LETTER_NUMBER;</li> + * <li>it is a currency symbol (such as "$");</li> + * <li>it is a connecting punctuation character (such as "_");</li> + * </ul> + * All Unicode code points in the BMP (0x0000..0xFFFF) are tested. + */ + public static void testIsJavaIdentifierStart_char() { + for (int i = 0; i <= Character.MAX_VALUE; i++) { + char ch = (char) i; + boolean expected = false; + // Since Character.isJavaIdentifierStart(char) strictly conforms to + // character information from version 6.2 of the Unicode Standard, + // check if code point is in "UNASSIGNED_CODEPOINTS_IN_6_2" + // list. If the code point is found in list + // "UNASSIGNED_CODEPOINTS_IN_6_2", value of variable + // "expected" is considered false. + if (!UNASSIGNED_CODEPOINTS_IN_6_2.contains(i)) { + byte type = (byte) Character.getType(ch); + expected = Character.isLetter(ch) + || type == Character.LETTER_NUMBER + || type == Character.CURRENCY_SYMBOL + || type == Character.CONNECTOR_PUNCTUATION; + } + + if (Character.isJavaIdentifierStart(ch) != expected) { + throw new RuntimeException( + "Character.isJavaIdentifierStart(char) failed for codepoint " + + Integer.toHexString(i)); + } + } + } + + /** + * Assertion testing for public static boolean isJavaLetter(char ch), A + * character may start a Java identifier if and only if one of the + * following is true: + * <ul> + * <li>isLetter(ch) returns true + * <li>getType(ch) returns LETTER_NUMBER + * <li>ch is a currency symbol (such as "$") + * <li>ch is a connecting punctuation character (such as "_"). + * </ul> + * All Unicode code points in the BMP (0x0000..0xFFFF) are tested. + */ + public static void testIsJavaLetter() { + for (int i = 0; i <= Character.MAX_VALUE; ++i) { + char ch = (char) i; + boolean expected = false; + // Since Character.isJavaLetter(char) strictly conforms to + // character information from version 6.2 of the Unicode Standard, + // check if code point is in "UNASSIGNED_CODEPOINTS_IN_6_2" + // list. If the code point is found in list + // "UNASSIGNED_CODEPOINTS_IN_6_2", value of variable + // "expected" is considered false. + if (!UNASSIGNED_CODEPOINTS_IN_6_2.contains(i)) { + byte type = (byte) Character.getType(ch); + expected = Character.isLetter(ch) + || type == Character.LETTER_NUMBER + || type == Character.CURRENCY_SYMBOL + || type == Character.CONNECTOR_PUNCTUATION; + } + + if (Character.isJavaLetter(ch) != expected) { + throw new RuntimeException( + "Character.isJavaLetter(ch) failed for codepoint " + + Integer.toHexString(i)); + } + } + } + + /** + * Assertion testing for public static boolean isJavaLetterOrDigit(char + * ch), A character may be part of a Java identifier if and only if any + * of the following are true: + * <ul> + * <li>it is a letter + * <li>it is a currency symbol (such as '$') + * <li>it is a connecting punctuation character (such as '_') + * <li>it is a digit + * <li>it is a numeric letter (such as a Roman numeral character) + * <li>it is a combining mark + * <li>it is a non-spacing mark + * <li>isIdentifierIgnorable returns true for the character. + * </ul> + * All Unicode code points in the BMP (0x0000..0xFFFF) are tested. + */ + public static void testIsJavaLetterOrDigit() { + for (int i = 0; i <= Character.MAX_VALUE; ++i) { + char ch = (char) i; + boolean expected = false; + // Since Character.isJavaLetterOrDigit(char) strictly conforms to + // character information from version 6.2 of the Unicode Standard, + // check if code point is in "UNASSIGNED_CODEPOINTS_IN_6_2" + // list. If the code point is found in list + // "UNASSIGNED_CODEPOINTS_IN_6_2", value of variable + // "expected" is considered false. + if (!UNASSIGNED_CODEPOINTS_IN_6_2.contains(i)) { + byte type = (byte) Character.getType(ch); + expected = Character.isLetter(ch) + || type == Character.CURRENCY_SYMBOL + || type == Character.CONNECTOR_PUNCTUATION + || Character.isDigit(ch) + || type == Character.LETTER_NUMBER + || type == Character.COMBINING_SPACING_MARK + || type == Character.NON_SPACING_MARK + || Character.isIdentifierIgnorable(ch); + } + + if (Character.isJavaLetterOrDigit(ch) != expected) { + throw new RuntimeException( + "Character.isJavaLetterOrDigit(ch) failed for codepoint " + + Integer.toHexString(i)); + } + } + } +}
--- a/test/java/text/Format/DateFormat/WeekDateTest.java Fri Mar 01 00:55:45 2019 +0000 +++ b/test/java/text/Format/DateFormat/WeekDateTest.java Fri Feb 22 14:47:49 2019 +0530 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2010, 2019, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -137,20 +137,28 @@ Calendar jcal = Calendar.getInstance(TimeZone.getTimeZone("GMT"), new Locale("ja", "JP", "JP")); + String format = "2-W01-2"; // 2019-12-31 == N1-12-31 + int expectedYear = 2019; + // Check the current era, Heisei or NewEra + if (System.currentTimeMillis() < 1556668800000L) { + format = "21-W01-3"; // 2008-12-31 == H20-12-31 + expectedYear = 2008; + } jcal.setFirstDayOfWeek(MONDAY); jcal.setMinimalDaysInFirstWeek(4); SimpleDateFormat sdf = new SimpleDateFormat("Y-'W'ww-u"); sdf.setCalendar(jcal); - Date d = sdf.parse("21-W01-3"); // 2008-12-31 == H20-12-31 + Date d = sdf.parse(format); GregorianCalendar gcal = newCalendar(); gcal.setTime(d); - if (gcal.get(YEAR) != 2008 + if (gcal.get(YEAR) != expectedYear || gcal.get(MONTH) != DECEMBER || gcal.get(DAY_OF_MONTH) != 31) { - String s = String.format("noWeekDateSupport: got %04d-%02d-%02d, expected 2008-12-31%n", + String s = String.format("noWeekDateSupport: got %04d-%02d-%02d, expected %4d-12-31%n", gcal.get(YEAR), gcal.get(MONTH)+1, - gcal.get(DAY_OF_MONTH)); + gcal.get(DAY_OF_MONTH), + expectedYear); throw new RuntimeException(s); } }
--- a/test/java/time/tck/java/time/chrono/TCKJapaneseChronology.java Fri Mar 01 00:55:45 2019 +0000 +++ b/test/java/time/tck/java/time/chrono/TCKJapaneseChronology.java Fri Feb 22 14:47:49 2019 +0530 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2019, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -111,6 +111,7 @@ */ @Test public class TCKJapaneseChronology { + private static final int YDIFF_NEWERA = 2018; private static final int YDIFF_HEISEI = 1988; private static final int YDIFF_MEIJI = 1867; private static final int YDIFF_SHOWA = 1925; @@ -173,6 +174,7 @@ @DataProvider(name="createByEra") Object[][] data_createByEra() { return new Object[][] { + {JapaneseEra.of(3), 2020 - YDIFF_NEWERA, 2, 29, 60, LocalDate.of(2020, 2, 29)}, // NEWERA {JapaneseEra.HEISEI, 1996 - YDIFF_HEISEI, 2, 29, 60, LocalDate.of(1996, 2, 29)}, {JapaneseEra.HEISEI, 2000 - YDIFF_HEISEI, 2, 29, 60, LocalDate.of(2000, 2, 29)}, {JapaneseEra.MEIJI, 1874 - YDIFF_MEIJI, 2, 28, 59, LocalDate.of(1874, 2, 28)}, @@ -365,8 +367,11 @@ @DataProvider(name="prolepticYear") Object[][] data_prolepticYear() { return new Object[][] { + {3, JapaneseEra.of(3), 1, 1 + YDIFF_NEWERA, false}, // NEWERA + {3, JapaneseEra.of(3), 102, 102 + YDIFF_NEWERA, true}, // NEWERA + {2, JapaneseEra.HEISEI, 1, 1 + YDIFF_HEISEI, false}, - {2, JapaneseEra.HEISEI, 100, 100 + YDIFF_HEISEI, true}, + {2, JapaneseEra.HEISEI, 4, 4 + YDIFF_HEISEI, true}, {-1, JapaneseEra.MEIJI, 9, 9 + YDIFF_MEIJI, true}, {-1, JapaneseEra.MEIJI, 10, 10 + YDIFF_MEIJI, false}, @@ -548,6 +553,7 @@ { JapaneseEra.TAISHO, 0, "Taisho"}, { JapaneseEra.SHOWA, 1, "Showa"}, { JapaneseEra.HEISEI, 2, "Heisei"}, + { JapaneseEra.of(3), 3, "NewEra"}, // NEWERA }; } @@ -562,7 +568,7 @@ @Test public void test_Japanese_badEras() { - int badEras[] = {-1000, -998, -997, -2, 3, 4, 1000}; + int badEras[] = {-1000, -998, -997, -2, 4, 5, 1000}; for (int badEra : badEras) { try { Era era = JapaneseChronology.INSTANCE.eraOf(badEra); @@ -683,6 +689,7 @@ {JapaneseChronology.INSTANCE.date(1989, 1, 7), "Japanese Showa 64-01-07"}, {JapaneseChronology.INSTANCE.date(1989, 1, 8), "Japanese Heisei 1-01-08"}, {JapaneseChronology.INSTANCE.date(2012, 12, 6), "Japanese Heisei 24-12-06"}, + {JapaneseChronology.INSTANCE.date(2020, 1, 6), "Japanese NewEra 2-01-06"}, }; }
--- a/test/java/time/tck/java/time/chrono/TCKJapaneseEra.java Fri Mar 01 00:55:45 2019 +0000 +++ b/test/java/time/tck/java/time/chrono/TCKJapaneseEra.java Fri Feb 22 14:47:49 2019 +0530 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2019, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -77,6 +77,7 @@ @DataProvider(name = "JapaneseEras") Object[][] data_of_eras() { return new Object[][] { + {JapaneseEra.of(3), "NewEra", 3}, // NEWERA {JapaneseEra.HEISEI, "Heisei", 2}, {JapaneseEra.SHOWA, "Showa", 1}, {JapaneseEra.TAISHO, "Taisho", 0},
--- a/test/java/time/test/java/time/chrono/TestJapaneseChronology.java Fri Mar 01 00:55:45 2019 +0000 +++ b/test/java/time/test/java/time/chrono/TestJapaneseChronology.java Fri Feb 22 14:47:49 2019 +0530 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 2019, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -58,6 +58,8 @@ { JapaneseEra.SHOWA, 1, 12, 25, 1926 }, { JapaneseEra.SHOWA, 64, 1, 7, 1989 }, { JapaneseEra.HEISEI, 1, 1, 8, 1989 }, + { JapaneseEra.HEISEI, 31, 4, 30, 2019 }, + { JapaneseEra.of(3), 1, 5, 1, 2019 }, // NEWERA }; } @@ -74,6 +76,8 @@ { JapaneseEra.SHOWA, 64, 7, 1, 7 }, { JapaneseEra.HEISEI, 1, 1, 1, 8 }, { JapaneseEra.HEISEI, 2, 8, 1, 8 }, + { JapaneseEra.HEISEI, 31, 120, 4, 30 }, + { JapaneseEra.of(3), 1, 1, 5, 1 }, // NEWERA }; } @@ -81,8 +85,8 @@ Object[][] rangeData() { return new Object[][] { // field, minSmallest, minLargest, maxSmallest, maxLargest - { ChronoField.ERA, -1, -1, 2, 2}, - { ChronoField.YEAR_OF_ERA, 1, 1, 15, 999999999-1989 }, // depends on the current era + { ChronoField.ERA, -1, -1, 3, 3}, + { ChronoField.YEAR_OF_ERA, 1, 1, 15, 999999999-2019}, // depends on the current era { ChronoField.DAY_OF_YEAR, 1, 1, 7, 366}, { ChronoField.YEAR, 1873, 1873, 999999999, 999999999}, }; @@ -105,7 +109,9 @@ { JapaneseEra.SHOWA, 65, 1, 1 }, { JapaneseEra.HEISEI, 1, 1, 7 }, { JapaneseEra.HEISEI, 1, 2, 29 }, - { JapaneseEra.HEISEI, Year.MAX_VALUE, 12, 31 }, + { JapaneseEra.HEISEI, 31, 5, 1 }, + { JapaneseEra.of(3), 1, 4, 30 }, // NEWERA + { JapaneseEra.of(3), Year.MAX_VALUE, 12, 31 }, // NEWERA }; } @@ -124,7 +130,10 @@ { JapaneseEra.SHOWA, 65 }, { JapaneseEra.HEISEI, -1 }, { JapaneseEra.HEISEI, 0 }, - { JapaneseEra.HEISEI, Year.MAX_VALUE }, + { JapaneseEra.HEISEI, 32 }, + { JapaneseEra.of(3), -1 }, // NEWERA + { JapaneseEra.of(3), 0 }, // NEWERA + { JapaneseEra.of(3), Year.MAX_VALUE }, // NEWERA }; } @@ -141,6 +150,9 @@ { JapaneseEra.SHOWA, 64, 8 }, { JapaneseEra.HEISEI, 1, 360 }, { JapaneseEra.HEISEI, 2, 366 }, + { JapaneseEra.HEISEI, 31, 121 }, + { JapaneseEra.of(3), 1, 246 }, // NEWERA + { JapaneseEra.of(3), 2, 367 }, // NEWERA }; }
--- a/test/java/time/test/java/time/chrono/TestUmmAlQuraChronology.java Fri Mar 01 00:55:45 2019 +0000 +++ b/test/java/time/test/java/time/chrono/TestUmmAlQuraChronology.java Fri Feb 22 14:47:49 2019 +0530 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 2019, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -775,8 +775,10 @@ {HijrahDate.of(1350,5,15), "Japanese Showa 6-09-28"}, {HijrahDate.of(1434,5,1), "Japanese Heisei 25-03-13"}, {HijrahDate.of(1436,1,1), "Japanese Heisei 26-10-25"}, - {HijrahDate.of(1500,6,12), "Japanese Heisei 89-05-05"}, - {HijrahDate.of(1550,3,11), "Japanese Heisei 137-08-11"}, + {HijrahDate.of(1440,8,25), "Japanese Heisei 31-04-30"}, + {HijrahDate.of(1440,8,26), "Japanese NewEra 1-05-01"}, + {HijrahDate.of(1500,6,12), "Japanese NewEra 59-05-05"}, + {HijrahDate.of(1550,3,11), "Japanese NewEra 107-08-11"}, }; }
--- a/test/java/time/test/java/time/format/TestNonIsoFormatter.java Fri Mar 01 00:55:45 2019 +0000 +++ b/test/java/time/test/java/time/format/TestNonIsoFormatter.java Fri Feb 22 14:47:49 2019 +0530 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 2019, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -20,6 +20,13 @@ * or visit www.oracle.com if you need additional information or have any * questions. */ + +/* + * + * @test + * @bug 8206120 + */ + package test.java.time.format; import static org.testng.Assert.assertEquals; @@ -37,6 +44,7 @@ import java.time.format.DateTimeFormatterBuilder; import java.time.format.DateTimeParseException; import java.time.format.FormatStyle; +import java.time.format.ResolverStyle; import java.time.format.TextStyle; import java.time.temporal.TemporalAccessor; import java.time.temporal.TemporalQueries; @@ -128,6 +136,16 @@ }; } + @DataProvider(name="lenient_eraYear") + Object[][] lenientEraYear() { + return new Object[][] { + // Chronology, lenient era/year, strict era/year + { JAPANESE, "Meiji 123", "Heisei 2" }, + { JAPANESE, "Showa 65", "Heisei 2" }, + { JAPANESE, "Heisei 32", "NewEra 2" }, // NewEra + }; + } + @Test(dataProvider="format_data") public void test_formatLocalizedDate(Chronology chrono, Locale formatLocale, Locale numberingLocale, ChronoLocalDate date, String expected) { @@ -166,4 +184,15 @@ Chronology cal = ta.query(TemporalQueries.chronology()); assertEquals(cal, chrono); } + + @Test(dataProvider="lenient_eraYear") + public void test_lenientEraYear(Chronology chrono, String lenient, String strict) { + String mdStr = "-01-01"; + DateTimeFormatter dtf = new DateTimeFormatterBuilder() + .appendPattern("GGGG y-M-d") + .toFormatter() + .withChronology(chrono); + DateTimeFormatter dtfLenient = dtf.withResolverStyle(ResolverStyle.LENIENT); + assertEquals(LocalDate.parse(lenient+mdStr, dtfLenient), LocalDate.parse(strict+mdStr, dtf)); } +}
--- a/test/java/util/Calendar/Bug8007038.java Fri Mar 01 00:55:45 2019 +0000 +++ b/test/java/util/Calendar/Bug8007038.java Fri Feb 22 14:47:49 2019 +0530 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 2019, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -45,7 +45,7 @@ private final static int[][] eraMinMax = { {GregorianCalendar.BC, GregorianCalendar.AD}, {0, 1}, - {0, 4}, + {0, 5}, {0, 1}, {0, 1}, {0, 1},
--- a/test/java/util/Calendar/Builder/BuilderTest.java Fri Mar 01 00:55:45 2019 +0000 +++ b/test/java/util/Calendar/Builder/BuilderTest.java Fri Feb 22 14:47:49 2019 +0530 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 2019, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -27,6 +27,7 @@ * @summary Unit test for Calendar.Builder. */ +import java.time.LocalDateTime; import java.util.*; import static java.util.Calendar.*; @@ -132,7 +133,11 @@ .setFields(YEAR, 1, DAY_OF_YEAR, 1).build(); expected = Calendar.getInstance(jaJPJP); expected.clear(); + if (LocalDateTime.now().isBefore(LocalDateTime.of(2019, 5, 1, 0, 0))) { expected.set(1, JANUARY, 8); + } else { + expected.set(1, MAY, 1); + } check(cal, expected); // setLocale calb = builder();
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/java/util/Calendar/JapaneseEraNameTest.java Fri Feb 22 14:47:49 2019 +0530 @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @bug 8202088 + * @summary Test the localized Japanese new era name (May 1st. 2019-) + * is retrieved no matter CLDR provider contains the name or not. + * @run testng/othervm JapaneseEraNameTest + * @run testng/othervm -Djava.locale.providers=CLDR,JRE JapaneseEraNameTest + */ + +import static java.util.Calendar.*; +import static java.util.Locale.*; +import java.util.Calendar; +import java.util.Locale; + +import org.testng.annotations.DataProvider; +import org.testng.annotations.Test; +import static org.testng.Assert.assertEquals; + +@Test +public class JapaneseEraNameTest { + static final Calendar c = new Calendar.Builder() + .setCalendarType("japanese") + .setFields(ERA, 5, YEAR, 1, MONTH, MAY, DAY_OF_MONTH, 1) + .build(); + + @DataProvider(name="names") + Object[][] names() { + return new Object[][] { + // type, locale, name + { LONG, JAPAN, "\u5143\u53f7" }, // NewEra + { LONG, US, "NewEra" }, + { SHORT, JAPAN, "N" }, + { SHORT, US, "N" }, + }; + } + + @Test(dataProvider="names") + public void testJapaneseNewEraName(int type, Locale locale, String expected) { + assertEquals(c.getDisplayName(ERA, type, locale), expected); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/java/util/Calendar/JapaneseLenientEraTest.java Fri Feb 22 14:47:49 2019 +0530 @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @bug 8206120 + * @summary Test whether lenient era is accepted in JapaneseImperialCalendar + * @run testng/othervm JapaneseLenientEraTest + */ + +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.Calendar; +import java.util.Date; +import java.util.Locale; + +import org.testng.annotations.DataProvider; +import org.testng.annotations.Test; +import static org.testng.Assert.assertEquals; + +@Test +public class JapaneseLenientEraTest { + + @DataProvider(name="lenientEra") + Object[][] names() { + return new Object[][] { + // lenient era/year, strict era/year + { "Meiji 123", "Heisei 2" }, + { "Showa 65", "Heisei 2" }, + { "Heisei 32", "NewEra 2" }, // NewEra + }; + } + + @Test(dataProvider="lenientEra") + public void testLenientEra(String lenient, String strict) throws Exception { + Calendar c = new Calendar.Builder() + .setCalendarType("japanese") + .build(); + DateFormat df = new SimpleDateFormat("GGGG y-M-d", Locale.ROOT); + df.setCalendar(c); + Date lenDate = df.parse(lenient + "-01-01"); + df.setLenient(false); + Date strDate = df.parse(strict + "-01-01"); + assertEquals(lenDate, strDate); + } +}
--- a/test/java/util/Calendar/NarrowNamesTest.java Fri Mar 01 00:55:45 2019 +0000 +++ b/test/java/util/Calendar/NarrowNamesTest.java Fri Feb 22 14:47:49 2019 +0530 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2019, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -21,6 +21,7 @@ * questions. */ +import java.time.LocalDateTime; import java.util.*; import static java.util.GregorianCalendar.*; @@ -45,7 +46,9 @@ HOUR_OF_DAY, 10); test(US, AM_PM, "p", HOUR_OF_DAY, 23); - test(JAJPJP, DAY_OF_WEEK, "\u65e5", + test(JAJPJP, DAY_OF_WEEK, + LocalDateTime.now().isBefore(LocalDateTime.of(2019, 5, 1, 0, 0)) ? + "\u65e5" : "\u706b", // "Sun" for HEISEI, "Tue" for NEWERA YEAR, 24, MONTH, DECEMBER, DAY_OF_MONTH, 23); test(THTH, MONTH, NARROW_STANDALONE, "\u0e18.\u0e04.", YEAR, 2555, MONTH, DECEMBER, DAY_OF_MONTH, 5);
--- a/test/java/util/Calendar/SupplementalJapaneseEraTest.java Fri Mar 01 00:55:45 2019 +0000 +++ b/test/java/util/Calendar/SupplementalJapaneseEraTest.java Fri Feb 22 14:47:49 2019 +0530 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -60,8 +60,8 @@ public class SupplementalJapaneseEraTest { private static final Locale WAREKI_LOCALE = Locale.forLanguageTag("ja-JP-u-ca-japanese"); - private static final String NEW_ERA_NAME = "NewEra"; - private static final String NEW_ERA_ABBR = "N.E."; + private static final String SUP_ERA_NAME = "SupEra"; + private static final String SUP_ERA_ABBR = "S.E."; private static final int NEW_ERA_YEAR = 200; private static final int NEW_ERA_MONTH = FEBRUARY; private static final int NEW_ERA_DAY = 11; @@ -96,7 +96,7 @@ private static void testProperty() { Calendar jcal = new Calendar.Builder() .setCalendarType("japanese") - .setFields(YEAR, 1, DAY_OF_YEAR, 1) + .setFields(ERA, 6, YEAR, 1, DAY_OF_YEAR, 1) .build(); Date firstDayOfEra = jcal.getTime(); @@ -114,7 +114,7 @@ // test long era name sdf = new SimpleDateFormat("GGGG y-MM-dd", WAREKI_LOCALE); got = sdf.format(firstDayOfEra); - expected = NEW_ERA_NAME + " 1-02-11"; + expected = SUP_ERA_NAME + " 1-02-11"; if (!expected.equals(got)) { System.err.printf("GGGG y-MM-dd: got=\"%s\", expected=\"%s\"%n", got, expected); errors++; @@ -123,7 +123,7 @@ // test era abbreviation sdf = new SimpleDateFormat("G y-MM-dd", WAREKI_LOCALE); got = sdf.format(firstDayOfEra); - expected = NEW_ERA_ABBR+" 1-02-11"; + expected = SUP_ERA_ABBR+" 1-02-11"; if (!expected.equals(got)) { System.err.printf("G y-MM-dd: got=\"%s\", expected=\"%s\"%n", got, expected); errors++; @@ -140,30 +140,30 @@ // test java.time.chrono.JapaneseEra JapaneseDate jdate = JapaneseDate.of(year, 2, 11); got = jdate.toString(); - expected = "Japanese " + NEW_ERA_NAME + " 1-02-11"; + expected = "Japanese " + SUP_ERA_NAME + " 1-02-11"; if (!expected.equals(got)) { System.err.printf("JapaneseDate: got=\"%s\", expected=\"%s\"%n", got, expected); errors++; } JapaneseEra jera = jdate.getEra(); got = jera.getDisplayName(TextStyle.FULL, Locale.US); - if (!NEW_ERA_NAME.equals(got)) { - System.err.printf("JapaneseEra (FULL): got=\"%s\", expected=\"%s\"%n", got, NEW_ERA_NAME); + if (!SUP_ERA_NAME.equals(got)) { + System.err.printf("JapaneseEra (FULL): got=\"%s\", expected=\"%s\"%n", got, SUP_ERA_NAME); errors++; } got = jera.getDisplayName(TextStyle.SHORT, Locale.US); - if (!NEW_ERA_NAME.equals(got)) { - System.err.printf("JapaneseEra (SHORT): got=\"%s\", expected=\"%s\"%n", got, NEW_ERA_NAME); + if (!SUP_ERA_NAME.equals(got)) { + System.err.printf("JapaneseEra (SHORT): got=\"%s\", expected=\"%s\"%n", got, SUP_ERA_NAME); errors++; } got = jera.getDisplayName(TextStyle.NARROW, Locale.US); - if (!NEW_ERA_ABBR.equals(got)) { - System.err.printf("JapaneseEra (NARROW): got=\"%s\", expected=\"%s\"%n", got, NEW_ERA_ABBR); + if (!SUP_ERA_ABBR.equals(got)) { + System.err.printf("JapaneseEra (NARROW): got=\"%s\", expected=\"%s\"%n", got, SUP_ERA_ABBR); errors++; } got = jera.getDisplayName(TextStyle.NARROW_STANDALONE, Locale.US); - if (!NEW_ERA_ABBR.equals(got)) { - System.err.printf("JapaneseEra (NARROW_STANDALONE): got=\"%s\", expected=\"%s\"%n", got, NEW_ERA_ABBR); + if (!SUP_ERA_ABBR.equals(got)) { + System.err.printf("JapaneseEra (NARROW_STANDALONE): got=\"%s\", expected=\"%s\"%n", got, SUP_ERA_ABBR); errors++; } @@ -172,10 +172,12 @@ .appendPattern("GGGG") .appendLiteral(" ") .appendPattern("G") + .appendLiteral(" ") + .appendPattern("GGGGG") .toFormatter(Locale.US) .withChronology(JapaneseChronology.INSTANCE) .format(jdate); - expected = NEW_ERA_NAME + " " + NEW_ERA_ABBR; + expected = SUP_ERA_NAME + " " + SUP_ERA_NAME + " " + SUP_ERA_ABBR; if (!expected.equals(got)) { System.err.printf("java.time formatter long/abbr names: got=\"%s\", expected=\"%s\"%n", got, expected); errors++; @@ -230,8 +232,8 @@ if (eras != null) { p.setProperty(JA_CAL_KEY, eras + - "; name=" + SupplementalJapaneseEraTest.NEW_ERA_NAME + - ",abbr=" + SupplementalJapaneseEraTest.NEW_ERA_ABBR + + "; name=" + SupplementalJapaneseEraTest.SUP_ERA_NAME + + ",abbr=" + SupplementalJapaneseEraTest.SUP_ERA_ABBR + ",since=" + since()); } try (BufferedWriter bw = Files.newBufferedWriter(dst)) { @@ -243,6 +245,7 @@ return new Calendar.Builder() .setCalendarType("japanese") .setTimeZone(TimeZone.getTimeZone("GMT")) + .setFields(ERA, 5) .setDate(SupplementalJapaneseEraTest.NEW_ERA_YEAR, SupplementalJapaneseEraTest.NEW_ERA_MONTH, SupplementalJapaneseEraTest.NEW_ERA_DAY)