Path: blob/master/test/jdk/java/text/testlib/TestUtils.java
41152 views
/*1* Copyright (c) 2016, 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*/2223import java.text.DecimalFormatSymbols;24import java.util.Calendar;25import java.util.GregorianCalendar;26import java.util.Locale;2728import java.util.Locale.Builder;2930/**31* TestUtils provides utility methods to get a locale-dependent attribute.32* For example,33* - whether or not a non-Gregorian calendar is used34* - whether or not non-ASCII digits are used35*36* This class was developed to help testing for internationalization &37* localization and is not versatile.38*/39public class TestUtils {4041/**42* Returns true if the give locale uses Gregorian calendar.43*/44public static boolean usesGregorianCalendar(Locale locale) {45return Calendar.getInstance(locale).getClass() == GregorianCalendar.class;46}4748/**49* Returns true if the given locale uses ASCII digits.50*/51public static boolean usesAsciiDigits(Locale locale) {52return DecimalFormatSymbols.getInstance(locale).getZeroDigit() == '0';53}5455/**56* Returns true if the given locale has a special variant which is treated57* as ill-formed in BCP 47.58*59* BCP 47 requires a variant subtag to be 5 to 8 alphanumerics or a60* single numeric followed by 3 alphanumerics.61* However, note that this methods doesn't check a variant so rigorously62* because this is a utility method for testing. Intended special variants63* are: JP, NY, and TH, which can be commonly provided by64* Locale.getAvailableLocales().65*66*/67public static boolean hasSpecialVariant(Locale locale) {68String variant = locale.getVariant();69return !variant.isEmpty()70&& "JP".equals(variant) || "NY".equals(variant) || "TH".equals(variant);71}7273}747576