< prev index next >

src/java.base/share/classes/java/time/format/DateTimeTextProvider.java

Print this page

        

@@ -1,7 +1,7 @@
 /*
- * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 2016, 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.  Oracle designates this

@@ -346,51 +346,85 @@
             }
             return new LocaleStore(styleMap);
         }
 
         if (field == MONTH_OF_YEAR) {
+            Map<Long, String> map = new HashMap<>();
             for (TextStyle textStyle : TextStyle.values()) {
+                switch (textStyle) {
+                case NARROW:
+                case NARROW_STANDALONE:
+                    // Narrow names may have duplicated names, such as "J" for January, June, July.
+                    // Get names one by one in that case.
+                    for (int month = Calendar.JANUARY; month <= Calendar.DECEMBER; month++) {
+                        String name;
+                        name = CalendarDataUtility.retrieveJavaTimeFieldValueName(
+                                "gregory", Calendar.MONTH,
+                                month, textStyle.toCalendarStyle(), locale);
+                        if (name == null) {
+                            break;
+                        }
+                        map.put((month + 1L), name);
+                    }
+                    break;
+                default:
                 Map<String, Integer> displayNames = CalendarDataUtility.retrieveJavaTimeFieldValueNames(
                         "gregory", Calendar.MONTH, textStyle.toCalendarStyle(), locale);
-                Map<Long, String> map = new HashMap<>();
                 if (displayNames != null) {
                     for (Entry<String, Integer> entry : displayNames.entrySet()) {
-                        map.put((long) (entry.getValue() + 1), entry.getKey());
+                                map.put((long)(entry.getValue() + 1), entry.getKey());
                     }
-
                 } else {
-                    // Narrow names may have duplicated names, such as "J" for January, Jun, July.
+                            // Although probability is very less, but if other styles have duplicate names.
                     // Get names one by one in that case.
                     for (int month = Calendar.JANUARY; month <= Calendar.DECEMBER; month++) {
                         String name;
                         name = CalendarDataUtility.retrieveJavaTimeFieldValueName(
                                 "gregory", Calendar.MONTH, month, textStyle.toCalendarStyle(), locale);
                         if (name == null) {
                             break;
                         }
-                        map.put((long) (month + 1), name);
+                                map.put((month + 1L), name);
                     }
                 }
+                        break;
+                }
                 if (!map.isEmpty()) {
                     styleMap.put(textStyle, map);
                 }
             }
             return new LocaleStore(styleMap);
         }
 
         if (field == DAY_OF_WEEK) {
+            Map<Long, String> map = new HashMap<>();
             for (TextStyle textStyle : TextStyle.values()) {
+                switch (textStyle) {
+                case NARROW:
+                case NARROW_STANDALONE:
+                    // Narrow names may have duplicated names, such as "S" for Sunday and Saturday.
+                    // Get names one by one in that case.
+                    for (int wday = Calendar.SUNDAY; wday <= Calendar.SATURDAY; wday++) {
+                        String name;
+                        name = CalendarDataUtility.retrieveJavaTimeFieldValueName(
+                                "gregory", Calendar.DAY_OF_WEEK,
+                                wday, textStyle.toCalendarStyle(), locale);
+                        if (name == null) {
+                            break;
+                        }
+                        map.put((long)toWeekDay(wday), name);
+                    }
+                    break;
+                default:
                 Map<String, Integer> displayNames = CalendarDataUtility.retrieveJavaTimeFieldValueNames(
                         "gregory", Calendar.DAY_OF_WEEK, textStyle.toCalendarStyle(), locale);
-                Map<Long, String> map = new HashMap<>();
                 if (displayNames != null) {
                     for (Entry<String, Integer> entry : displayNames.entrySet()) {
                         map.put((long)toWeekDay(entry.getValue()), entry.getKey());
                     }
-
                 } else {
-                    // Narrow names may have duplicated names, such as "S" for Sunday and Saturday.
+                            // Although probability is very less, but if other styles have duplicate names.
                     // Get names one by one in that case.
                     for (int wday = Calendar.SUNDAY; wday <= Calendar.SATURDAY; wday++) {
                         String name;
                         name = CalendarDataUtility.retrieveJavaTimeFieldValueName(
                             "gregory", Calendar.DAY_OF_WEEK, wday, textStyle.toCalendarStyle(), locale);

@@ -398,10 +432,12 @@
                             break;
                         }
                         map.put((long)toWeekDay(wday), name);
                     }
                 }
+                        break;
+                }
                 if (!map.isEmpty()) {
                     styleMap.put(textStyle, map);
                 }
             }
             return new LocaleStore(styleMap);
< prev index next >