Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/util/PluggableLocale/providersrc/DecimalFormatSymbolsProviderImpl.java
47311 views
/*1* Copyright (c) 2007, 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 DecimalFormatSymbolsProviderImpl extends DecimalFormatSymbolsProvider {3536static Locale[] avail = {37new Locale("ja", "JP", "osaka"),38new Locale("ja", "JP", "kyoto"),39Locale.JAPAN,40new Locale("yy", "ZZ", "UUU")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-UUU"49};5051static HashMap<Locale, FooDecimalFormatSymbols> symbols = new HashMap<Locale, FooDecimalFormatSymbols>(4);5253public Locale[] getAvailableLocales() {54return avail;55}5657public DecimalFormatSymbols getInstance(Locale locale) {58if (!Utils.supportsLocale(availList, locale)) {59throw new IllegalArgumentException("locale is not supported: "+locale);60}6162FooDecimalFormatSymbols fdfs = symbols.get(locale);63if (fdfs == null) {64for (int index = 0; index < avail.length; index ++) {65if (Utils.supportsLocale(avail[index], locale)) {66fdfs = new FooDecimalFormatSymbols(index);67symbols.put(locale, fdfs);68break;69}70}71}72return fdfs;73}7475class FooDecimalFormatSymbols extends DecimalFormatSymbols {76String dialect = "";7778String infinity = null;79String nan = null;8081public FooDecimalFormatSymbols(int index) {82super(DecimalFormatSymbolsProviderImpl.this.avail[index]);83dialect = DecimalFormatSymbolsProviderImpl.this.dialect[index];84}8586// overrides methods only returns Strings87public String getInfinity() {88if (infinity == null) {89infinity = super.getInfinity() + dialect;90}91return infinity;92}9394public void setInfinity(String infinity) {95this.infinity = infinity;96}9798public String getNaN() {99if (nan == null) {100nan = super.getNaN() + dialect;101}102return nan;103}104105public void setNaN(String nan) {106this.nan = nan;107}108}109}110111112