1 /* 2 * Copyright (c) 2005, 2018, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 package java.text.spi; 27 28 import java.text.NumberFormat; 29 import java.util.Locale; 30 import java.util.spi.LocaleServiceProvider; 31 32 /** 33 * An abstract class for service providers that 34 * provide concrete implementations of the 35 * {@link java.text.NumberFormat NumberFormat} class. 36 * 37 * @since 1.6 38 */ 39 public abstract class NumberFormatProvider extends LocaleServiceProvider { 40 41 /** 42 * Sole constructor. (For invocation by subclass constructors, typically 43 * implicit.) 44 */ 45 protected NumberFormatProvider() { 46 } 47 48 /** 49 * Returns a new <code>NumberFormat</code> instance which formats 50 * monetary values for the specified locale. 51 * 52 * @param locale the desired locale. 53 * @exception NullPointerException if <code>locale</code> is null 54 * @exception IllegalArgumentException if <code>locale</code> isn't 55 * one of the locales returned from 56 * {@link java.util.spi.LocaleServiceProvider#getAvailableLocales() 57 * getAvailableLocales()}. 58 * @return a currency formatter 59 * @see java.text.NumberFormat#getCurrencyInstance(java.util.Locale) 60 */ 61 public abstract NumberFormat getCurrencyInstance(Locale locale); 62 63 /** 64 * Returns a new <code>NumberFormat</code> instance which formats 65 * integer values for the specified locale. 66 * The returned number format is configured to 67 * round floating point numbers to the nearest integer using 68 * half-even rounding (see {@link java.math.RoundingMode#HALF_EVEN HALF_EVEN}) 69 * for formatting, and to parse only the integer part of 70 * an input string (see {@link 71 * java.text.NumberFormat#isParseIntegerOnly isParseIntegerOnly}). 72 * 73 * @param locale the desired locale 74 * @exception NullPointerException if <code>locale</code> is null 75 * @exception IllegalArgumentException if <code>locale</code> isn't 76 * one of the locales returned from 77 * {@link java.util.spi.LocaleServiceProvider#getAvailableLocales() 78 * getAvailableLocales()}. 79 * @return a number format for integer values 80 * @see java.text.NumberFormat#getIntegerInstance(java.util.Locale) 81 */ 82 public abstract NumberFormat getIntegerInstance(Locale locale); 83 84 /** 85 * Returns a new general-purpose <code>NumberFormat</code> instance for 86 * the specified locale. 87 * 88 * @param locale the desired locale 89 * @exception NullPointerException if <code>locale</code> is null 90 * @exception IllegalArgumentException if <code>locale</code> isn't 91 * one of the locales returned from 92 * {@link java.util.spi.LocaleServiceProvider#getAvailableLocales() 93 * getAvailableLocales()}. 94 * @return a general-purpose number formatter 95 * @see java.text.NumberFormat#getNumberInstance(java.util.Locale) 96 */ 97 public abstract NumberFormat getNumberInstance(Locale locale); 98 99 /** 100 * Returns a new <code>NumberFormat</code> instance which formats 101 * percentage values for the specified locale. 102 * 103 * @param locale the desired locale 104 * @exception NullPointerException if <code>locale</code> is null 105 * @exception IllegalArgumentException if <code>locale</code> isn't 106 * one of the locales returned from 107 * {@link java.util.spi.LocaleServiceProvider#getAvailableLocales() 108 * getAvailableLocales()}. 109 * @return a percent formatter 110 * @see java.text.NumberFormat#getPercentInstance(java.util.Locale) 111 */ 112 public abstract NumberFormat getPercentInstance(Locale locale); 113 114 /** 115 * Returns a new {@code NumberFormat} instance which formats 116 * a number in its compact form for the specified 117 * {@code locale} and {@code formatStyle}. 118 * 119 * @implSpec The default implementation of this method throws 120 * {@code UnSupportedOperationException}. Overriding the implementation 121 * of this method returns the compact number formatter instance 122 * of the given {@code locale} with specified {@code formatStyle}. 123 * 124 * @param locale the desired locale 125 * @param formatStyle the style for formatting a number 126 * @throws NullPointerException if {@code locale} or {@code formatStyle} 127 * is {@code null} 128 * @throws IllegalArgumentException if {@code locale} is not 129 * one of the locales returned from 130 * {@link java.util.spi.LocaleServiceProvider#getAvailableLocales() 131 * getAvailableLocales()}. 132 * @return a compact number formatter 133 * 134 * @see java.text.NumberFormat#getCompactNumberInstance(Locale, 135 * NumberFormat.Style) 136 * @since 12 137 */ 138 public NumberFormat getCompactNumberInstance(Locale locale, 139 NumberFormat.Style formatStyle) { 140 throw new UnsupportedOperationException( 141 "The " + this.getClass().getName() + " should override this" 142 + " method to return compact number format instance of " 143 + locale + " locale and " + formatStyle + " style."); 144 } 145 146 }