Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/util/PluggableLocale/providersrc/DateFormatSymbolsProviderImpl.java
47311 views
/*1* Copyright (c) 2007, 2012, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/22/*23*24*/2526package com.foo;2728import java.text.*;29import java.text.spi.*;30import java.util.*;3132import com.foobar.Utils;3334public class DateFormatSymbolsProviderImpl extends DateFormatSymbolsProvider {3536static Locale[] avail = {37new Locale("ja", "JP", "osaka"),38new Locale("ja", "JP", "kyoto"),39Locale.JAPAN,40new Locale("yy", "ZZ")41};42static List<Locale> availList = Arrays.asList(avail);4344static String[] dialect = {45"\u3084\u3002",46"\u3069\u3059\u3002",47"\u3067\u3059\u3002",48"-yy-ZZ"49};5051static Map<Locale, FooDateFormatSymbols> symbols = new HashMap<Locale, FooDateFormatSymbols>(4);5253public Locale[] getAvailableLocales() {54return avail;55}5657public DateFormatSymbols getInstance(Locale locale) {58if (!Utils.supportsLocale(availList, locale)) {59throw new IllegalArgumentException("locale is not supported: "+locale);60}6162FooDateFormatSymbols fdfs = symbols.get(locale);63if (fdfs == null) {64for (int index = 0; index < avail.length; index ++) {65if (Utils.supportsLocale(avail[index], locale)) {66fdfs = new FooDateFormatSymbols(index);67symbols.put(locale, fdfs);68break;69}70}71}72return fdfs;73}7475class FooDateFormatSymbols extends DateFormatSymbols {76String dialect = "";7778String[] eras = null;79String[] months = null;80String[] shortMonths = null;81String[] weekdays = null;82String[] shortWeekdays = null;83String[] ampms = null;8485public FooDateFormatSymbols(int index) {86super(DateFormatSymbolsProviderImpl.this.avail[index]);87dialect = DateFormatSymbolsProviderImpl.this.dialect[index];88}8990public String[] getEras() {91if (eras == null) {92eras = super.getEras();93for (int i = 0; i < eras.length; i++) {94eras[i] = eras[i]+dialect;95}96}97return eras;98}99100/**101* Sets era strings. For example: "AD" and "BC".102* @param newEras the new era strings.103*/104public void setEras(String[] newEras) {105eras = newEras;106}107108/**109* Gets month strings. For example: "January", "February", etc.110* @return the month strings.111*/112public String[] getMonths() {113if (months == null) {114months = super.getMonths();115for (int i = 0; i < months.length; i++) {116months[i] = months[i]+dialect;117}118}119return months;120}121122/**123* Sets month strings. For example: "January", "February", etc.124* @param newMonths the new month strings.125*/126public void setMonths(String[] newMonths) {127months = newMonths;128}129130/**131* Gets short month strings. For example: "Jan", "Feb", etc.132* @return the short month strings.133*/134public String[] getShortMonths() {135if (shortMonths == null) {136shortMonths = super.getShortMonths();137for (int i = 0; i < shortMonths.length; i++) {138shortMonths[i] = shortMonths[i]+dialect;139}140}141return shortMonths;142}143144/**145* Sets short month strings. For example: "Jan", "Feb", etc.146* @param newShortMonths the new short month strings.147*/148public void setShortMonths(String[] newShortMonths) {149shortMonths = newShortMonths;150}151152/**153* Gets weekday strings. For example: "Sunday", "Monday", etc.154* @return the weekday strings. Use <code>Calendar.SUNDAY</code>,155* <code>Calendar.MONDAY</code>, etc. to index the result array.156*/157public String[] getWeekdays() {158if (weekdays == null) {159weekdays = super.getWeekdays();160for (int i = 0; i < weekdays.length; i++) {161weekdays[i] = weekdays[i]+dialect;162}163}164return weekdays;165}166167/**168* Sets weekday strings. For example: "Sunday", "Monday", etc.169* @param newWeekdays the new weekday strings. The array should170* be indexed by <code>Calendar.SUNDAY</code>,171* <code>Calendar.MONDAY</code>, etc.172*/173public void setWeekdays(String[] newWeekdays) {174weekdays = newWeekdays;175}176177/**178* Gets short weekday strings. For example: "Sun", "Mon", etc.179* @return the short weekday strings. Use <code>Calendar.SUNDAY</code>,180* <code>Calendar.MONDAY</code>, etc. to index the result array.181*/182public String[] getShortWeekdays() {183if (shortWeekdays == null) {184shortWeekdays = super.getShortWeekdays();185for (int i = 0; i < shortWeekdays.length; i++) {186shortWeekdays[i] = shortWeekdays[i]+dialect;187}188}189return shortWeekdays;190}191192/**193* Sets short weekday strings. For example: "Sun", "Mon", etc.194* @param newShortWeekdays the new short weekday strings. The array should195* be indexed by <code>Calendar.SUNDAY</code>,196* <code>Calendar.MONDAY</code>, etc.197*/198public void setShortWeekdays(String[] newShortWeekdays) {199shortWeekdays = newShortWeekdays;200}201202/**203* Gets ampm strings. For example: "AM" and "PM".204* @return the ampm strings.205*/206public String[] getAmPmStrings() {207if (ampms == null) {208ampms = super.getAmPmStrings();209for (int i = 0; i < ampms.length; i++) {210ampms[i] = ampms[i]+dialect;211}212}213return ampms;214}215216/**217* Sets ampm strings. For example: "AM" and "PM".218* @param newAmpms the new ampm strings.219*/220public void setAmPmStrings(String[] newAmpms) {221ampms = newAmpms;222}223224@Override225public String[][] getZoneStrings() {226return new String[0][0];227}228}229}230231232