< prev index next >

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

Print this page


   1 /*
   2  * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 331                 if (textStyle.isStandalone()) {
 332                     // Stand-alone isn't applicable to era names.
 333                     continue;
 334                 }
 335                 Map<String, Integer> displayNames = CalendarDataUtility.retrieveJavaTimeFieldValueNames(
 336                         "gregory", Calendar.ERA, textStyle.toCalendarStyle(), locale);
 337                 if (displayNames != null) {
 338                     Map<Long, String> map = new HashMap<>();
 339                     for (Entry<String, Integer> entry : displayNames.entrySet()) {
 340                         map.put((long) entry.getValue(), entry.getKey());
 341                     }
 342                     if (!map.isEmpty()) {
 343                         styleMap.put(textStyle, map);
 344                     }
 345                 }
 346             }
 347             return new LocaleStore(styleMap);
 348         }
 349 
 350         if (field == MONTH_OF_YEAR) {

 351             for (TextStyle textStyle : TextStyle.values()) {

















 352                 Map<String, Integer> displayNames = CalendarDataUtility.retrieveJavaTimeFieldValueNames(
 353                         "gregory", Calendar.MONTH, textStyle.toCalendarStyle(), locale);
 354                 Map<Long, String> map = new HashMap<>();
 355                 if (displayNames != null) {
 356                     for (Entry<String, Integer> entry : displayNames.entrySet()) {
 357                         map.put((long) (entry.getValue() + 1), entry.getKey());
 358                     }
 359 
 360                 } else {
 361                     // Narrow names may have duplicated names, such as "J" for January, Jun, July.
 362                     // Get names one by one in that case.
 363                     for (int month = Calendar.JANUARY; month <= Calendar.DECEMBER; month++) {
 364                         String name;
 365                         name = CalendarDataUtility.retrieveJavaTimeFieldValueName(
 366                                 "gregory", Calendar.MONTH, month, textStyle.toCalendarStyle(), locale);
 367                         if (name == null) {
 368                             break;
 369                         }
 370                         map.put((long) (month + 1), name);
 371                     }
 372                 }


 373                 if (!map.isEmpty()) {
 374                     styleMap.put(textStyle, map);
 375                 }
 376             }
 377             return new LocaleStore(styleMap);
 378         }
 379 
 380         if (field == DAY_OF_WEEK) {

 381             for (TextStyle textStyle : TextStyle.values()) {

















 382                 Map<String, Integer> displayNames = CalendarDataUtility.retrieveJavaTimeFieldValueNames(
 383                         "gregory", Calendar.DAY_OF_WEEK, textStyle.toCalendarStyle(), locale);
 384                 Map<Long, String> map = new HashMap<>();
 385                 if (displayNames != null) {
 386                     for (Entry<String, Integer> entry : displayNames.entrySet()) {
 387                         map.put((long)toWeekDay(entry.getValue()), entry.getKey());
 388                     }
 389 
 390                 } else {
 391                     // Narrow names may have duplicated names, such as "S" for Sunday and Saturday.
 392                     // Get names one by one in that case.
 393                     for (int wday = Calendar.SUNDAY; wday <= Calendar.SATURDAY; wday++) {
 394                         String name;
 395                         name = CalendarDataUtility.retrieveJavaTimeFieldValueName(
 396                             "gregory", Calendar.DAY_OF_WEEK, wday, textStyle.toCalendarStyle(), locale);
 397                         if (name == null) {
 398                             break;
 399                         }
 400                         map.put((long)toWeekDay(wday), name);
 401                     }
 402                 }


 403                 if (!map.isEmpty()) {
 404                     styleMap.put(textStyle, map);
 405                 }
 406             }
 407             return new LocaleStore(styleMap);
 408         }
 409 
 410         if (field == AMPM_OF_DAY) {
 411             for (TextStyle textStyle : TextStyle.values()) {
 412                 if (textStyle.isStandalone()) {
 413                     // Stand-alone isn't applicable to AM/PM.
 414                     continue;
 415                 }
 416                 Map<String, Integer> displayNames = CalendarDataUtility.retrieveJavaTimeFieldValueNames(
 417                         "gregory", Calendar.AM_PM, textStyle.toCalendarStyle(), locale);
 418                 if (displayNames != null) {
 419                     Map<Long, String> map = new HashMap<>();
 420                     for (Entry<String, Integer> entry : displayNames.entrySet()) {
 421                         map.put((long) entry.getValue(), entry.getKey());
 422                     }


   1 /*
   2  * Copyright (c) 2012, 2016, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 331                 if (textStyle.isStandalone()) {
 332                     // Stand-alone isn't applicable to era names.
 333                     continue;
 334                 }
 335                 Map<String, Integer> displayNames = CalendarDataUtility.retrieveJavaTimeFieldValueNames(
 336                         "gregory", Calendar.ERA, textStyle.toCalendarStyle(), locale);
 337                 if (displayNames != null) {
 338                     Map<Long, String> map = new HashMap<>();
 339                     for (Entry<String, Integer> entry : displayNames.entrySet()) {
 340                         map.put((long) entry.getValue(), entry.getKey());
 341                     }
 342                     if (!map.isEmpty()) {
 343                         styleMap.put(textStyle, map);
 344                     }
 345                 }
 346             }
 347             return new LocaleStore(styleMap);
 348         }
 349 
 350         if (field == MONTH_OF_YEAR) {
 351             Map<Long, String> map = new HashMap<>();
 352             for (TextStyle textStyle : TextStyle.values()) {
 353                 switch (textStyle) {
 354                 case NARROW:
 355                 case NARROW_STANDALONE:
 356                     // Narrow names may have duplicated names, such as "J" for January, June, July.
 357                     // Get names one by one in that case.
 358                     for (int month = Calendar.JANUARY; month <= Calendar.DECEMBER; month++) {
 359                         String name;
 360                         name = CalendarDataUtility.retrieveJavaTimeFieldValueName(
 361                                 "gregory", Calendar.MONTH,
 362                                 month, textStyle.toCalendarStyle(), locale);
 363                         if (name == null) {
 364                             break;
 365                         }
 366                         map.put((month + 1L), name);
 367                     }
 368                     break;
 369                 default:
 370                         Map<String, Integer> displayNames = CalendarDataUtility.retrieveJavaTimeFieldValueNames(
 371                                 "gregory", Calendar.MONTH, textStyle.toCalendarStyle(), locale);

 372                         if (displayNames != null) {
 373                             for (Entry<String, Integer> entry : displayNames.entrySet()) {
 374                                 map.put((long)(entry.getValue() + 1), entry.getKey());
 375                             }

 376                         } else {
 377                             // Although probability is very less, but if other styles have duplicate names.
 378                             // Get names one by one in that case.
 379                             for (int month = Calendar.JANUARY; month <= Calendar.DECEMBER; month++) {
 380                                 String name;
 381                                 name = CalendarDataUtility.retrieveJavaTimeFieldValueName(
 382                                         "gregory", Calendar.MONTH, month, textStyle.toCalendarStyle(), locale);
 383                                 if (name == null) {
 384                                     break;
 385                                 }
 386                                 map.put((month + 1L), name);
 387                             }
 388                         }
 389                         break;
 390                 }
 391                 if (!map.isEmpty()) {
 392                     styleMap.put(textStyle, map);
 393                 }
 394             }
 395             return new LocaleStore(styleMap);
 396         }
 397 
 398         if (field == DAY_OF_WEEK) {
 399             Map<Long, String> map = new HashMap<>();
 400             for (TextStyle textStyle : TextStyle.values()) {
 401                 switch (textStyle) {
 402                 case NARROW:
 403                 case NARROW_STANDALONE:
 404                     // Narrow names may have duplicated names, such as "S" for Sunday and Saturday.
 405                     // Get names one by one in that case.
 406                     for (int wday = Calendar.SUNDAY; wday <= Calendar.SATURDAY; wday++) {
 407                         String name;
 408                         name = CalendarDataUtility.retrieveJavaTimeFieldValueName(
 409                                 "gregory", Calendar.DAY_OF_WEEK,
 410                                 wday, textStyle.toCalendarStyle(), locale);
 411                         if (name == null) {
 412                             break;
 413                         }
 414                         map.put((long)toWeekDay(wday), name);
 415                     }
 416                     break;
 417                 default:
 418                         Map<String, Integer> displayNames = CalendarDataUtility.retrieveJavaTimeFieldValueNames(
 419                                 "gregory", Calendar.DAY_OF_WEEK, textStyle.toCalendarStyle(), locale);

 420                         if (displayNames != null) {
 421                             for (Entry<String, Integer> entry : displayNames.entrySet()) {
 422                                 map.put((long)toWeekDay(entry.getValue()), entry.getKey());
 423                             }

 424                         } else {
 425                             // Although probability is very less, but if other styles have duplicate names.
 426                             // Get names one by one in that case.
 427                             for (int wday = Calendar.SUNDAY; wday <= Calendar.SATURDAY; wday++) {
 428                                 String name;
 429                                 name = CalendarDataUtility.retrieveJavaTimeFieldValueName(
 430                                         "gregory", Calendar.DAY_OF_WEEK, wday, textStyle.toCalendarStyle(), locale);
 431                                 if (name == null) {
 432                                     break;
 433                                 }
 434                                 map.put((long)toWeekDay(wday), name);
 435                             }
 436                         }
 437                         break;
 438                 }
 439                 if (!map.isEmpty()) {
 440                     styleMap.put(textStyle, map);
 441                 }
 442             }
 443             return new LocaleStore(styleMap);
 444         }
 445 
 446         if (field == AMPM_OF_DAY) {
 447             for (TextStyle textStyle : TextStyle.values()) {
 448                 if (textStyle.isStandalone()) {
 449                     // Stand-alone isn't applicable to AM/PM.
 450                     continue;
 451                 }
 452                 Map<String, Integer> displayNames = CalendarDataUtility.retrieveJavaTimeFieldValueNames(
 453                         "gregory", Calendar.AM_PM, textStyle.toCalendarStyle(), locale);
 454                 if (displayNames != null) {
 455                     Map<Long, String> map = new HashMap<>();
 456                     for (Entry<String, Integer> entry : displayNames.entrySet()) {
 457                         map.put((long) entry.getValue(), entry.getKey());
 458                     }


< prev index next >