Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/sun/util/locale/provider/CalendarProviderImpl.java
38918 views
/*1* Copyright (c) 2013, 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. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package sun.util.locale.provider;2627import java.util.Calendar;28import java.util.Calendar.Builder;29import java.util.Locale;30import java.util.Set;31import java.util.TimeZone;32import sun.util.spi.CalendarProvider;3334/**35* Concrete implementation of the {@link sun.util.spi.CalendarProvider36* CalendarProvider} class for the JRE LocaleProviderAdapter.37*38* @author Naoto Sato39*/40public class CalendarProviderImpl extends CalendarProvider implements AvailableLanguageTags {41private final LocaleProviderAdapter.Type type;42private final Set<String> langtags;4344public CalendarProviderImpl(LocaleProviderAdapter.Type type, Set<String> langtags) {45this.type = type;46this.langtags = langtags;47}4849/**50* Returns an array of all locales for which this locale service provider51* can provide localized objects or names.52*53* @return An array of all locales for which this locale service provider54* can provide localized objects or names.55*/56@Override57public Locale[] getAvailableLocales() {58return LocaleProviderAdapter.toLocaleArray(langtags);59}6061@Override62public boolean isSupportedLocale(Locale locale) {63// Support any locales.64return true;65}6667/**68* Returns a new <code>Calendar</code> instance for the69* specified locale.70*71* @param zone the time zone72* @param locale the desired locale73* @exception NullPointerException if <code>locale</code> is null74* @exception IllegalArgumentException if <code>locale</code> isn't75* one of the locales returned from76* {@link java.util.spi.LocaleServiceProvider#getAvailableLocales()77* getAvailableLocales()}.78* @return a <code>Calendar</code> instance.79* @see java.util.Calendar#getInstance(java.util.Locale)80*/81@Override82public Calendar getInstance(TimeZone zone, Locale locale) {83return new Calendar.Builder()84.setLocale(locale)85.setTimeZone(zone)86.setInstant(System.currentTimeMillis())87.build();88}8990@Override91public Set<String> getAvailableLanguageTags() {92return langtags;93}94}959697