Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/util/PluggableLocale/providersrc/DateFormatProviderImpl.java
47311 views
/*1* Copyright (c) 2007, 2010, 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 DateFormatProviderImpl extends DateFormatProvider {3536static Locale[] avail = {37Locale.JAPAN,38new Locale("ja", "JP", "osaka"),39new Locale("ja", "JP", "kyoto"),40new Locale("yy")};4142static String[] datePattern = {43"yyyy'\u5e74'M'\u6708'd'\u65e5'", // full date pattern44"yyyy/MMM/dd", // long date pattern45"yyyy/MM/dd", // medium date pattern46"yy/MM/dd" // short date pattern47};4849static String[] timePattern = {50"H'\u6642'mm'\u5206'ss'\u79d2' z", // full time pattern51"H:mm:ss z", // long time pattern52"H:mm:ss", // medium time pattern53"H:mm" // short time pattern54};5556static String[] dialect = {57"\u3067\u3059\u3002",58"\u3084\u3002",59"\u3069\u3059\u3002",60"\u308f\u3044\u308f\u3044"61};6263public Locale[] getAvailableLocales() {64return avail;65}6667public DateFormat getDateInstance(int style, Locale locale) {68for (int i = 0; i < avail.length; i ++) {69if (Utils.supportsLocale(avail[i], locale)) {70return new FooDateFormat(datePattern[style]+dialect[i], locale);71}72}73throw new IllegalArgumentException("locale is not supported: "+locale);74}7576public DateFormat getTimeInstance(int style, Locale locale) {77for (int i = 0; i < avail.length; i ++) {78if (Utils.supportsLocale(avail[i], locale)) {79return new FooDateFormat(timePattern[style]+dialect[i], locale);80}81}82throw new IllegalArgumentException("locale is not supported: "+locale);83}8485public DateFormat getDateTimeInstance(int dateStyle, int timeStyle, Locale locale) {86for (int i = 0; i < avail.length; i ++) {87if (Utils.supportsLocale(avail[i], locale)) {88return new FooDateFormat(89datePattern[dateStyle]+" "+timePattern[timeStyle]+dialect[i], locale);90}91}92throw new IllegalArgumentException("locale is not supported: "+locale);93}94}959697