Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/util/PluggableLocale/providersrc/CollatorProviderImpl.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 CollatorProviderImpl extends CollatorProvider {3536static Locale[] avail = {37Locale.JAPAN,38new Locale("ja", "JP", "osaka"),39new Locale("ja", "JP", "kyoto"),40new Locale("xx", "YY", "ZZZZ")};4142static String[] dialect = {43"\u3067\u3059\u3002",44"\u3084\u3002",45"\u3069\u3059\u3002",46"-xx-YY-ZZZZ"47};4849public Locale[] getAvailableLocales() {50return avail;51}5253public Collator getInstance(Locale locale) {54for (int i = 0; i < avail.length; i ++) {55if (Utils.supportsLocale(avail[i], locale)) {56RuleBasedCollator ja = (RuleBasedCollator)Collator.getInstance(Locale.JAPANESE);57try {58return new RuleBasedCollator(ja.getRules()+"& Z < "+dialect[i]);59} catch (ParseException pe) {60System.err.println(pe+ja.getRules()+"& Z < "+dialect[i]);61return ja;62}63}64}65throw new IllegalArgumentException("locale is not supported: "+locale);66}67}686970