Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/util/PluggableLocale/providersrc/BreakIteratorProviderImpl.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.*;31import com.foobar.Utils;3233public class BreakIteratorProviderImpl extends BreakIteratorProvider {3435static Locale[] avail = {36Locale.JAPAN,37new Locale("ja", "JP", "osaka"),38new Locale("ja", "JP", "kyoto"),39new Locale("xx", "YY")};4041static String[] dialect = {42"\u3067\u3059\u3002",43"\u3084\u3002",44"\u3069\u3059\u3002",45"-xx-YY"46};4748static enum Type {CHARACTER, LINE, SENTENCE, WORD};4950public Locale[] getAvailableLocales() {51return avail;52}5354public BreakIterator getCharacterInstance(Locale locale) {55for (int i = 0; i < avail.length; i ++) {56if (Utils.supportsLocale(avail[i], locale)) {57return new FooBreakIterator(Type.CHARACTER, i);58}59}60throw new IllegalArgumentException("locale is not supported: "+locale);61}6263public BreakIterator getLineInstance(Locale locale) {64for (int i = 0; i < avail.length; i ++) {65if (Utils.supportsLocale(avail[i], locale)) {66return new FooBreakIterator(Type.LINE, i);67}68}69throw new IllegalArgumentException("locale is not supported: "+locale);70}7172public BreakIterator getSentenceInstance(Locale locale) {73for (int i = 0; i < avail.length; i ++) {74if (Utils.supportsLocale(avail[i], locale)) {75return new FooBreakIterator(Type.SENTENCE, i);76}77}78throw new IllegalArgumentException("locale is not supported: "+locale);79}8081public BreakIterator getWordInstance(Locale locale) {82for (int i = 0; i < avail.length; i ++) {83if (Utils.supportsLocale(avail[i], locale)) {84return new FooBreakIterator(Type.WORD, i);85}86}87throw new IllegalArgumentException("locale is not supported: "+locale);88}8990// dummy implementation91class FooBreakIterator extends BreakIterator {92public FooBreakIterator(Type t, int index) {93super();94}9596public int current() {97return 0;98}99100public int first() {101return 0;102}103104public int following(int offset) {105return 0;106}107108public CharacterIterator getText() {109return null;110}111112public boolean isBoundary(int offset) {113return true;114}115116public int last() {117return 0;118}119120public int next() {121return 0;122}123124public int next(int n) {125return 0;126}127128public int preceding(int offset) {129return 0;130}131132public int previous() {133return 0;134}135136public void setText(CharacterIterator ci) {137}138}139}140141142