Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/java.base/share/classes/java/text/spi/NumberFormatProvider.java
41159 views
1
/*
2
* Copyright (c) 2005, 2019, 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} instance which formats
50
* monetary values for the specified locale.
51
*
52
* @param locale the desired locale.
53
* @throws NullPointerException if {@code locale} is null
54
* @throws IllegalArgumentException if {@code locale} 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} 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
* @throws NullPointerException if {@code locale} is null
75
* @throws IllegalArgumentException if {@code locale} 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} instance for
86
* the specified locale.
87
*
88
* @param locale the desired locale
89
* @throws NullPointerException if {@code locale} is null
90
* @throws IllegalArgumentException if {@code locale} 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} instance which formats
101
* percentage values for the specified locale.
102
*
103
* @param locale the desired locale
104
* @throws NullPointerException if {@code locale} is null
105
* @throws IllegalArgumentException if {@code locale} 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
* {@link java.lang.UnsupportedOperationException
121
* UnsupportedOperationException}. Overriding the implementation
122
* of this method returns the compact number formatter instance
123
* of the given {@code locale} with specified {@code formatStyle}.
124
*
125
* @param locale the desired locale
126
* @param formatStyle the style for formatting a number
127
* @throws NullPointerException if {@code locale} or {@code formatStyle}
128
* is {@code null}
129
* @throws IllegalArgumentException if {@code locale} is not
130
* one of the locales returned from
131
* {@link java.util.spi.LocaleServiceProvider#getAvailableLocales()
132
* getAvailableLocales()}.
133
* @throws UnsupportedOperationException if the implementation does not
134
* support this method
135
* @return a compact number formatter
136
*
137
* @see java.text.NumberFormat#getCompactNumberInstance(Locale,
138
* NumberFormat.Style)
139
* @since 12
140
*/
141
public NumberFormat getCompactNumberInstance(Locale locale,
142
NumberFormat.Style formatStyle) {
143
throw new UnsupportedOperationException(
144
"The " + this.getClass().getName() + " should override this"
145
+ " method to return compact number format instance of "
146
+ locale + " locale and " + formatStyle + " style.");
147
}
148
149
}
150
151