Path: blob/master/src/java.base/share/classes/java/text/spi/NumberFormatProvider.java
41159 views
/*1* Copyright (c) 2005, 2019, 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 java.text.spi;2627import java.text.NumberFormat;28import java.util.Locale;29import java.util.spi.LocaleServiceProvider;3031/**32* An abstract class for service providers that33* provide concrete implementations of the34* {@link java.text.NumberFormat NumberFormat} class.35*36* @since 1.637*/38public abstract class NumberFormatProvider extends LocaleServiceProvider {3940/**41* Sole constructor. (For invocation by subclass constructors, typically42* implicit.)43*/44protected NumberFormatProvider() {45}4647/**48* Returns a new {@code NumberFormat} instance which formats49* monetary values for the specified locale.50*51* @param locale the desired locale.52* @throws NullPointerException if {@code locale} is null53* @throws IllegalArgumentException if {@code locale} isn't54* one of the locales returned from55* {@link java.util.spi.LocaleServiceProvider#getAvailableLocales()56* getAvailableLocales()}.57* @return a currency formatter58* @see java.text.NumberFormat#getCurrencyInstance(java.util.Locale)59*/60public abstract NumberFormat getCurrencyInstance(Locale locale);6162/**63* Returns a new {@code NumberFormat} instance which formats64* integer values for the specified locale.65* The returned number format is configured to66* round floating point numbers to the nearest integer using67* half-even rounding (see {@link java.math.RoundingMode#HALF_EVEN HALF_EVEN})68* for formatting, and to parse only the integer part of69* an input string (see {@link70* java.text.NumberFormat#isParseIntegerOnly isParseIntegerOnly}).71*72* @param locale the desired locale73* @throws NullPointerException if {@code locale} is null74* @throws IllegalArgumentException if {@code locale} isn't75* one of the locales returned from76* {@link java.util.spi.LocaleServiceProvider#getAvailableLocales()77* getAvailableLocales()}.78* @return a number format for integer values79* @see java.text.NumberFormat#getIntegerInstance(java.util.Locale)80*/81public abstract NumberFormat getIntegerInstance(Locale locale);8283/**84* Returns a new general-purpose {@code NumberFormat} instance for85* the specified locale.86*87* @param locale the desired locale88* @throws NullPointerException if {@code locale} is null89* @throws IllegalArgumentException if {@code locale} isn't90* one of the locales returned from91* {@link java.util.spi.LocaleServiceProvider#getAvailableLocales()92* getAvailableLocales()}.93* @return a general-purpose number formatter94* @see java.text.NumberFormat#getNumberInstance(java.util.Locale)95*/96public abstract NumberFormat getNumberInstance(Locale locale);9798/**99* Returns a new {@code NumberFormat} instance which formats100* percentage values for the specified locale.101*102* @param locale the desired locale103* @throws NullPointerException if {@code locale} is null104* @throws IllegalArgumentException if {@code locale} isn't105* one of the locales returned from106* {@link java.util.spi.LocaleServiceProvider#getAvailableLocales()107* getAvailableLocales()}.108* @return a percent formatter109* @see java.text.NumberFormat#getPercentInstance(java.util.Locale)110*/111public abstract NumberFormat getPercentInstance(Locale locale);112113/**114* Returns a new {@code NumberFormat} instance which formats115* a number in its compact form for the specified116* {@code locale} and {@code formatStyle}.117*118* @implSpec The default implementation of this method throws119* {@link java.lang.UnsupportedOperationException120* UnsupportedOperationException}. Overriding the implementation121* of this method returns the compact number formatter instance122* of the given {@code locale} with specified {@code formatStyle}.123*124* @param locale the desired locale125* @param formatStyle the style for formatting a number126* @throws NullPointerException if {@code locale} or {@code formatStyle}127* is {@code null}128* @throws IllegalArgumentException if {@code locale} is not129* one of the locales returned from130* {@link java.util.spi.LocaleServiceProvider#getAvailableLocales()131* getAvailableLocales()}.132* @throws UnsupportedOperationException if the implementation does not133* support this method134* @return a compact number formatter135*136* @see java.text.NumberFormat#getCompactNumberInstance(Locale,137* NumberFormat.Style)138* @since 12139*/140public NumberFormat getCompactNumberInstance(Locale locale,141NumberFormat.Style formatStyle) {142throw new UnsupportedOperationException(143"The " + this.getClass().getName() + " should override this"144+ " method to return compact number format instance of "145+ locale + " locale and " + formatStyle + " style.");146}147148}149150151