@jahia/javascript-modules-library 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/README.md +35 -0
- package/core/index.js +1 -0
- package/core/server/components/AbsoluteArea.js +1 -0
- package/core/server/components/AddContentButtons.js +1 -0
- package/core/server/components/AddResources.js +1 -0
- package/core/server/components/Area.js +1 -0
- package/core/server/components/index.js +1 -0
- package/core/server/components/render/HydrateInBrowser.js +1 -0
- package/core/server/components/render/Render.js +1 -0
- package/core/server/components/render/RenderInBrowser.js +1 -0
- package/core/server/components/render/index.js +1 -0
- package/core/server/components/render/internal/InBrowser.js +1 -0
- package/core/server/framework/defineJahiaComponent.js +1 -0
- package/core/server/framework/index.js +1 -0
- package/core/server/framework/register.js +1 -0
- package/core/server/hooks/index.js +1 -0
- package/core/server/hooks/useGQLQuery.js +1 -0
- package/core/server/hooks/useJCRQuery.js +1 -0
- package/core/server/hooks/useServerContext.js +1 -0
- package/core/server/hooks/useUrlBuilder.js +1 -0
- package/core/server/index.js +1 -0
- package/core/server/utils/index.js +1 -0
- package/core/server/utils/jcr/getChildNodes.js +1 -0
- package/core/server/utils/jcr/getNodeFromPathOrId.js +1 -0
- package/core/server/utils/jcr/getNodeProps.js +1 -0
- package/core/server/utils/jcr/getNodesByJCRQuery.js +1 -0
- package/core/server/utils/jcr/index.js +1 -0
- package/core/server/utils/urlBuilder/index.js +1 -0
- package/core/server/utils/urlBuilder/urlBuilder.js +1 -0
- package/index.js +1 -0
- package/nav/index.js +1 -0
- package/nav/server/index.js +1 -0
- package/nav/server/navBuilder/index.js +1 -0
- package/nav/server/navBuilder/navBuilder.js +24 -0
- package/package.json +60 -0
- package/types/@jahia/javascript-modules-library-private.d.ts +60 -0
- package/types/core/index.d.ts +1 -0
- package/types/core/server/components/AbsoluteArea.d.ts +29 -0
- package/types/core/server/components/AddContentButtons.d.ts +13 -0
- package/types/core/server/components/AddResources.d.ts +31 -0
- package/types/core/server/components/Area.d.ts +27 -0
- package/types/core/server/components/index.d.ts +5 -0
- package/types/core/server/components/render/HydrateInBrowser.d.ts +13 -0
- package/types/core/server/components/render/Render.d.ts +23 -0
- package/types/core/server/components/render/RenderInBrowser.d.ts +13 -0
- package/types/core/server/components/render/index.d.ts +3 -0
- package/types/core/server/components/render/internal/InBrowser.d.ts +8 -0
- package/types/core/server/framework/defineJahiaComponent.d.ts +41 -0
- package/types/core/server/framework/index.d.ts +2 -0
- package/types/core/server/framework/register.d.ts +7 -0
- package/types/core/server/hooks/index.d.ts +4 -0
- package/types/core/server/hooks/useGQLQuery.d.ts +5 -0
- package/types/core/server/hooks/useJCRQuery.d.ts +3 -0
- package/types/core/server/hooks/useServerContext.d.ts +14 -0
- package/types/core/server/hooks/useUrlBuilder.d.ts +31 -0
- package/types/core/server/index.d.ts +4 -0
- package/types/core/server/utils/index.d.ts +2 -0
- package/types/core/server/utils/jcr/getChildNodes.d.ts +9 -0
- package/types/core/server/utils/jcr/getNodeFromPathOrId.d.ts +12 -0
- package/types/core/server/utils/jcr/getNodeProps.d.ts +7 -0
- package/types/core/server/utils/jcr/getNodesByJCRQuery.d.ts +9 -0
- package/types/core/server/utils/jcr/index.d.ts +4 -0
- package/types/core/server/utils/urlBuilder/index.d.ts +1 -0
- package/types/core/server/utils/urlBuilder/urlBuilder.d.ts +27 -0
- package/types/globals.d.ts +11 -0
- package/types/index.d.ts +19 -0
- package/types/java.io.d.ts +694 -0
- package/types/java.net.d.ts +190 -0
- package/types/java.security.d.ts +27 -0
- package/types/java.util.d.ts +1536 -0
- package/types/javax.jcr.d.ts +1250 -0
- package/types/javax.servlet.d.ts +426 -0
- package/types/javax.servlet.http.d.ts +1431 -0
- package/types/nav/index.d.ts +1 -0
- package/types/nav/server/index.d.ts +1 -0
- package/types/nav/server/navBuilder/index.d.ts +1 -0
- package/types/nav/server/navBuilder/navBuilder.d.ts +78 -0
- package/types/org.jahia.modules.npm.modules.engine.js.server.d.ts +292 -0
- package/types/org.jahia.services.content.d.ts +1463 -0
- package/types/org.jahia.services.content.decorator.d.ts +92 -0
- package/types/org.jahia.services.query.d.ts +35 -0
- package/types/org.jahia.services.render.d.ts +168 -0
- package/types/org.jahia.services.usermanager.d.ts +85 -0
- package/types/org.osgi.framework.d.ts +1004 -0
- package/types/server.d.ts +27 -0
- package/types/servercontext.d.ts +29 -0
|
@@ -0,0 +1,1536 @@
|
|
|
1
|
+
declare module 'java.util' {
|
|
2
|
+
export class Collection<E> {
|
|
3
|
+
/**
|
|
4
|
+
* Returns the number of elements in this collection. If this collection
|
|
5
|
+
* contains more than `Integer.MAX_VALUE` elements, returns
|
|
6
|
+
* `Integer.MAX_VALUE`.
|
|
7
|
+
*
|
|
8
|
+
* @return the number of elements in this collection
|
|
9
|
+
*/
|
|
10
|
+
size(): number;
|
|
11
|
+
/**
|
|
12
|
+
* Returns `true` if this collection contains no elements.
|
|
13
|
+
*
|
|
14
|
+
* @return `true` if this collection contains no elements
|
|
15
|
+
*/
|
|
16
|
+
isEmpty(): boolean;
|
|
17
|
+
/**
|
|
18
|
+
* Returns `true` if this collection contains the specified element.
|
|
19
|
+
* More formally, returns `true` if and only if this collection
|
|
20
|
+
* contains at least one element `e` such that
|
|
21
|
+
* `Objects.equals(o, e)`.
|
|
22
|
+
*
|
|
23
|
+
* @param o element whose presence in this collection is to be tested
|
|
24
|
+
* @return `true` if this collection contains the specified
|
|
25
|
+
* element
|
|
26
|
+
* @throws ClassCastException if the type of the specified element
|
|
27
|
+
* is incompatible with this collection
|
|
28
|
+
* (optional)
|
|
29
|
+
* @throws NullPointerException if the specified element is null and this
|
|
30
|
+
* collection does not permit null elements
|
|
31
|
+
* (optional)
|
|
32
|
+
*/
|
|
33
|
+
contains(o: any): boolean;
|
|
34
|
+
/**
|
|
35
|
+
* Returns an iterator over the elements in this collection. There are no
|
|
36
|
+
* guarantees concerning the order in which the elements are returned
|
|
37
|
+
* (unless this collection is an instance of some class that provides a
|
|
38
|
+
* guarantee).
|
|
39
|
+
*
|
|
40
|
+
* @return an `Iterator` over the elements in this collection
|
|
41
|
+
*/
|
|
42
|
+
iterator(): Iterator<E>;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* The class `Date` represents a specific instant
|
|
46
|
+
* in time, with millisecond precision.
|
|
47
|
+
*
|
|
48
|
+
* Prior to JDK 1.1, the class `Date` had two additional
|
|
49
|
+
* functions. It allowed the interpretation of dates as year, month, day, hour,
|
|
50
|
+
* minute, and second values. It also allowed the formatting and parsing
|
|
51
|
+
* of date strings. Unfortunately, the API for these functions was not
|
|
52
|
+
* amenable to internationalization. As of JDK 1.1, the
|
|
53
|
+
* `Calendar` class should be used to convert between dates and time
|
|
54
|
+
* fields and the `DateFormat` class should be used to format and
|
|
55
|
+
* parse date strings.
|
|
56
|
+
* The corresponding methods in `Date` are deprecated.
|
|
57
|
+
*
|
|
58
|
+
* Although the `Date` class is intended to reflect
|
|
59
|
+
* coordinated universal time (UTC), it may not do so exactly,
|
|
60
|
+
* depending on the host environment of the Java Virtual Machine.
|
|
61
|
+
* Nearly all modern operating systems assume that 1 day =
|
|
62
|
+
* 24 × 60 × 60 = 86400 seconds
|
|
63
|
+
* in all cases. In UTC, however, about once every year or two there
|
|
64
|
+
* is an extra second, called a "leap second." The leap
|
|
65
|
+
* second is always added as the last second of the day, and always
|
|
66
|
+
* on December 31 or June 30. For example, the last minute of the
|
|
67
|
+
* year 1995 was 61 seconds long, thanks to an added leap second.
|
|
68
|
+
* Most computer clocks are not accurate enough to be able to reflect
|
|
69
|
+
* the leap-second distinction.
|
|
70
|
+
*
|
|
71
|
+
* Some computer standards are defined in terms of Greenwich mean
|
|
72
|
+
* time (GMT), which is equivalent to universal time (UT). GMT is
|
|
73
|
+
* the "civil" name for the standard; UT is the
|
|
74
|
+
* "scientific" name for the same standard. The
|
|
75
|
+
* distinction between UTC and UT is that UTC is based on an atomic
|
|
76
|
+
* clock and UT is based on astronomical observations, which for all
|
|
77
|
+
* practical purposes is an invisibly fine hair to split. Because the
|
|
78
|
+
* earth's rotation is not uniform (it slows down and speeds up
|
|
79
|
+
* in complicated ways), UT does not always flow uniformly. Leap
|
|
80
|
+
* seconds are introduced as needed into UTC so as to keep UTC within
|
|
81
|
+
* 0.9 seconds of UT1, which is a version of UT with certain
|
|
82
|
+
* corrections applied. There are other time and date systems as
|
|
83
|
+
* well; for example, the time scale used by the satellite-based
|
|
84
|
+
* global positioning system (GPS) is synchronized to UTC but is
|
|
85
|
+
* not adjusted for leap seconds. An interesting source of
|
|
86
|
+
* further information is the United States Naval Observatory (USNO):
|
|
87
|
+
* * http://www.usno.navy.mil/USNO
|
|
88
|
+
*
|
|
89
|
+
*
|
|
90
|
+
* and the material regarding "Systems of Time" at:
|
|
91
|
+
* * http://www.usno.navy.mil/USNO/time/master-clock/systems-of-time
|
|
92
|
+
*
|
|
93
|
+
*
|
|
94
|
+
* which has descriptions of various different time systems including
|
|
95
|
+
* UT, UT1, and UTC.
|
|
96
|
+
*
|
|
97
|
+
* In all methods of class `Date` that accept or return
|
|
98
|
+
* year, month, date, hours, minutes, and seconds values, the
|
|
99
|
+
* following representations are used:
|
|
100
|
+
*
|
|
101
|
+
* A year y is represented by the integer
|
|
102
|
+
* y `- 1900`.
|
|
103
|
+
* A month is represented by an integer from 0 to 11; 0 is January,
|
|
104
|
+
* 1 is February, and so forth; thus 11 is December.
|
|
105
|
+
* A date (day of month) is represented by an integer from 1 to 31
|
|
106
|
+
* in the usual manner.
|
|
107
|
+
* An hour is represented by an integer from 0 to 23. Thus, the hour
|
|
108
|
+
* from midnight to 1 a.m. is hour 0, and the hour from noon to 1
|
|
109
|
+
* p.m. is hour 12.
|
|
110
|
+
* A minute is represented by an integer from 0 to 59 in the usual manner.
|
|
111
|
+
* A second is represented by an integer from 0 to 61; the values 60 and
|
|
112
|
+
* 61 occur only for leap seconds and even then only in Java
|
|
113
|
+
* implementations that actually track leap seconds correctly. Because
|
|
114
|
+
* of the manner in which leap seconds are currently introduced, it is
|
|
115
|
+
* extremely unlikely that two leap seconds will occur in the same
|
|
116
|
+
* minute, but this specification follows the date and time conventions
|
|
117
|
+
* for ISO C.
|
|
118
|
+
*
|
|
119
|
+
*
|
|
120
|
+
* In all cases, arguments given to methods for these purposes need
|
|
121
|
+
* not fall within the indicated ranges; for example, a date may be
|
|
122
|
+
* specified as January 32 and is interpreted as meaning February 1.
|
|
123
|
+
*
|
|
124
|
+
* @author James Gosling
|
|
125
|
+
* @author Arthur van Hoff
|
|
126
|
+
* @author Alan Liu
|
|
127
|
+
* @see java.text.DateFormat
|
|
128
|
+
* @see java.util.Calendar
|
|
129
|
+
* @see java.util.TimeZone
|
|
130
|
+
* @since 1.0
|
|
131
|
+
*/
|
|
132
|
+
export class Date {
|
|
133
|
+
/**
|
|
134
|
+
* Returns the number of milliseconds since January 1, 1970, 00:00:00 GMT
|
|
135
|
+
* represented by this `Date` object.
|
|
136
|
+
*
|
|
137
|
+
* @return the number of milliseconds since January 1, 1970, 00:00:00 GMT
|
|
138
|
+
* represented by this date.
|
|
139
|
+
*/
|
|
140
|
+
getTime(): number;
|
|
141
|
+
/**
|
|
142
|
+
* Converts this `Date` object to a `String`
|
|
143
|
+
* of the form:
|
|
144
|
+
* * dow mon dd hh:mm:ss zzz yyyy
|
|
145
|
+
* where:
|
|
146
|
+
* `dow` is the day of the week ({@code Sun, Mon, Tue, Wed,
|
|
147
|
+
* Thu, Fri, Sat}).
|
|
148
|
+
* `mon` is the month ({@code Jan, Feb, Mar, Apr, May, Jun,
|
|
149
|
+
* Jul, Aug, Sep, Oct, Nov, Dec}).
|
|
150
|
+
* `dd` is the day of the month (`01` through
|
|
151
|
+
* `31`), as two decimal digits.
|
|
152
|
+
* `hh` is the hour of the day (`00` through
|
|
153
|
+
* `23`), as two decimal digits.
|
|
154
|
+
* `mm` is the minute within the hour (`00` through
|
|
155
|
+
* `59`), as two decimal digits.
|
|
156
|
+
* `ss` is the second within the minute (`00` through
|
|
157
|
+
* `61`, as two decimal digits.
|
|
158
|
+
* `zzz` is the time zone (and may reflect daylight saving
|
|
159
|
+
* time). Standard time zone abbreviations include those
|
|
160
|
+
* recognized by the method `parse`. If time zone
|
|
161
|
+
* information is not available, then `zzz` is empty -
|
|
162
|
+
* that is, it consists of no characters at all.
|
|
163
|
+
* `yyyy` is the year, as four decimal digits.
|
|
164
|
+
*
|
|
165
|
+
*
|
|
166
|
+
* @return a string representation of this date.
|
|
167
|
+
* @see java.util.Date#toLocaleString()
|
|
168
|
+
* @see java.util.Date#toGMTString()
|
|
169
|
+
*/
|
|
170
|
+
toString(): string;
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* The `Dictionary` class is the abstract parent of any
|
|
174
|
+
* class, such as `Hashtable`, which maps keys to values.
|
|
175
|
+
* Every key and every value is an object. In any one `Dictionary`
|
|
176
|
+
* object, every key is associated with at most one value. Given a
|
|
177
|
+
* `Dictionary` and a key, the associated element can be looked up.
|
|
178
|
+
* Any non-`null` object can be used as a key and as a value.
|
|
179
|
+
*
|
|
180
|
+
* As a rule, the `equals` method should be used by
|
|
181
|
+
* implementations of this class to decide if two keys are the same.
|
|
182
|
+
*
|
|
183
|
+
* NOTE: This class is obsolete. New implementations should
|
|
184
|
+
* implement the Map interface, rather than extending this class.
|
|
185
|
+
*
|
|
186
|
+
* @author unascribed
|
|
187
|
+
* @see java.util.Map
|
|
188
|
+
* @see java.lang.Object#equals(java.lang.Object)
|
|
189
|
+
* @see java.lang.Object#hashCode()
|
|
190
|
+
* @see java.util.Hashtable
|
|
191
|
+
* @since 1.0
|
|
192
|
+
*/
|
|
193
|
+
export class Dictionary<K, V> {
|
|
194
|
+
/**
|
|
195
|
+
* Returns the number of entries (distinct keys) in this dictionary.
|
|
196
|
+
*
|
|
197
|
+
* @return the number of keys in this dictionary.
|
|
198
|
+
*/
|
|
199
|
+
size(): number;
|
|
200
|
+
/**
|
|
201
|
+
* Tests if this dictionary maps no keys to value. The general contract
|
|
202
|
+
* for the `isEmpty` method is that the result is true if and only
|
|
203
|
+
* if this dictionary contains no entries.
|
|
204
|
+
*
|
|
205
|
+
* @return `true` if this dictionary maps no keys to values;
|
|
206
|
+
* `false` otherwise.
|
|
207
|
+
*/
|
|
208
|
+
isEmpty(): boolean;
|
|
209
|
+
/**
|
|
210
|
+
* Returns the value to which the key is mapped in this dictionary.
|
|
211
|
+
* The general contract for the `isEmpty` method is that if this
|
|
212
|
+
* dictionary contains an entry for the specified key, the associated
|
|
213
|
+
* value is returned; otherwise, `null` is returned.
|
|
214
|
+
*
|
|
215
|
+
* @return the value to which the key is mapped in this dictionary;
|
|
216
|
+
* @param key a key in this dictionary.
|
|
217
|
+
* `null` if the key is not mapped to any value in
|
|
218
|
+
* this dictionary.
|
|
219
|
+
* @exception NullPointerException if the `key` is `null`.
|
|
220
|
+
* @see java.util.Dictionary#put(java.lang.Object, java.lang.Object)
|
|
221
|
+
*/
|
|
222
|
+
get(key: any): V;
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* An object that implements the Enumeration interface generates a
|
|
226
|
+
* series of elements, one at a time. Successive calls to the
|
|
227
|
+
* `nextElement` method return successive elements of the
|
|
228
|
+
* series.
|
|
229
|
+
*
|
|
230
|
+
* For example, to print all elements of a `Vector` v:
|
|
231
|
+
* * for (Enumeration<E> e = v.elements(); e.hasMoreElements();)
|
|
232
|
+
* System.out.println(e.nextElement());
|
|
233
|
+
*
|
|
234
|
+
* Methods are provided to enumerate through the elements of a
|
|
235
|
+
* vector, the keys of a hashtable, and the values in a hashtable.
|
|
236
|
+
* Enumerations are also used to specify the input streams to a
|
|
237
|
+
* `SequenceInputStream`.
|
|
238
|
+
*
|
|
239
|
+
* @apiNote
|
|
240
|
+
* The functionality of this interface is duplicated by the {@link Iterator}
|
|
241
|
+
* interface. In addition, `Iterator` adds an optional remove operation,
|
|
242
|
+
* and has shorter method names. New implementations should consider using
|
|
243
|
+
* `Iterator` in preference to `Enumeration`. It is possible to
|
|
244
|
+
* adapt an `Enumeration` to an `Iterator` by using the
|
|
245
|
+
* {@link #asIterator} method.
|
|
246
|
+
*
|
|
247
|
+
* @see java.util.Iterator
|
|
248
|
+
* @see java.io.SequenceInputStream
|
|
249
|
+
* @see java.util.Enumeration#nextElement()
|
|
250
|
+
* @see java.util.Hashtable
|
|
251
|
+
* @see java.util.Hashtable#elements()
|
|
252
|
+
* @see java.util.Hashtable#keys()
|
|
253
|
+
* @see java.util.Vector
|
|
254
|
+
* @see java.util.Vector#elements()
|
|
255
|
+
*
|
|
256
|
+
* @author Lee Boynton
|
|
257
|
+
* @since 1.0
|
|
258
|
+
*/
|
|
259
|
+
export class Enumeration<E> {
|
|
260
|
+
/**
|
|
261
|
+
* Tests if this enumeration contains more elements.
|
|
262
|
+
*
|
|
263
|
+
* @return `true` if and only if this enumeration object
|
|
264
|
+
* contains at least one more element to provide;
|
|
265
|
+
* `false` otherwise.
|
|
266
|
+
*/
|
|
267
|
+
hasMoreElements(): boolean;
|
|
268
|
+
/**
|
|
269
|
+
* Returns the next element of this enumeration if this enumeration
|
|
270
|
+
* object has at least one more element to provide.
|
|
271
|
+
*
|
|
272
|
+
* @return the next element of this enumeration.
|
|
273
|
+
* @exception NoSuchElementException if no more elements exist.
|
|
274
|
+
*/
|
|
275
|
+
nextElement(): E;
|
|
276
|
+
}
|
|
277
|
+
/**
|
|
278
|
+
* An iterator over a collection. `Iterator` takes the place of
|
|
279
|
+
* {@link Enumeration} in the Java Collections Framework. Iterators
|
|
280
|
+
* differ from enumerations in two ways:
|
|
281
|
+
*
|
|
282
|
+
*
|
|
283
|
+
* Iterators allow the caller to remove elements from the
|
|
284
|
+
* underlying collection during the iteration with well-defined
|
|
285
|
+
* semantics.
|
|
286
|
+
* Method names have been improved.
|
|
287
|
+
*
|
|
288
|
+
*
|
|
289
|
+
* This interface is a member of the
|
|
290
|
+
*
|
|
291
|
+
* Java Collections Framework.
|
|
292
|
+
*
|
|
293
|
+
* @apiNote
|
|
294
|
+
* An {@link Enumeration} can be converted into an `Iterator` by
|
|
295
|
+
* using the {@link Enumeration#asIterator} method.
|
|
296
|
+
*
|
|
297
|
+
* @param the type of elements returned by this iterator
|
|
298
|
+
*
|
|
299
|
+
* @author Josh Bloch
|
|
300
|
+
* @see Collection
|
|
301
|
+
* @see ListIterator
|
|
302
|
+
* @see Iterable
|
|
303
|
+
* @since 1.2
|
|
304
|
+
*/
|
|
305
|
+
export class Iterator<E> {
|
|
306
|
+
/**
|
|
307
|
+
* Returns `true` if the iteration has more elements.
|
|
308
|
+
* (In other words, returns `true` if {@link #next} would
|
|
309
|
+
* return an element rather than throwing an exception.)
|
|
310
|
+
*
|
|
311
|
+
* @return `true` if the iteration has more elements
|
|
312
|
+
*/
|
|
313
|
+
hasNext(): boolean;
|
|
314
|
+
/**
|
|
315
|
+
* Returns the next element in the iteration.
|
|
316
|
+
*
|
|
317
|
+
* @return the next element in the iteration
|
|
318
|
+
* @throws NoSuchElementException if the iteration has no more elements
|
|
319
|
+
*/
|
|
320
|
+
next(): E;
|
|
321
|
+
}
|
|
322
|
+
export class List<E> {
|
|
323
|
+
/**
|
|
324
|
+
* Returns the number of elements in this list. If this list contains
|
|
325
|
+
* more than `Integer.MAX_VALUE` elements, returns
|
|
326
|
+
* `Integer.MAX_VALUE`.
|
|
327
|
+
*
|
|
328
|
+
* @return the number of elements in this list
|
|
329
|
+
*/
|
|
330
|
+
size(): number;
|
|
331
|
+
/**
|
|
332
|
+
* Returns `true` if this list contains no elements.
|
|
333
|
+
*
|
|
334
|
+
* @return `true` if this list contains no elements
|
|
335
|
+
*/
|
|
336
|
+
isEmpty(): boolean;
|
|
337
|
+
/**
|
|
338
|
+
* Returns an iterator over the elements in this list in proper sequence.
|
|
339
|
+
*
|
|
340
|
+
* @return an iterator over the elements in this list in proper sequence
|
|
341
|
+
*/
|
|
342
|
+
iterator(): Iterator<E>;
|
|
343
|
+
/**
|
|
344
|
+
* Returns the element at the specified position in this list.
|
|
345
|
+
*
|
|
346
|
+
* @param index index of the element to return
|
|
347
|
+
* @return the element at the specified position in this list
|
|
348
|
+
* @throws IndexOutOfBoundsException if the index is out of range
|
|
349
|
+
* (`index < 0 || index >= size()`)
|
|
350
|
+
*/
|
|
351
|
+
get(index: number): E;
|
|
352
|
+
}
|
|
353
|
+
/**
|
|
354
|
+
* A Locale object represents a specific geographical, political,
|
|
355
|
+
* or cultural region. An operation that requires a Locale to perform
|
|
356
|
+
* its task is called locale-sensitive and uses the Locale
|
|
357
|
+
* to tailor information for the user. For example, displaying a number
|
|
358
|
+
* is a locale-sensitive operation— the number should be formatted
|
|
359
|
+
* according to the customs and conventions of the user's native country,
|
|
360
|
+
* region, or culture.
|
|
361
|
+
*
|
|
362
|
+
* The `Locale` class implements IETF BCP 47 which is composed of
|
|
363
|
+
* RFC 4647 "Matching of Language
|
|
364
|
+
* Tags" and RFC 5646 "Tags
|
|
365
|
+
* for Identifying Languages" with support for the LDML (UTS#35, "Unicode
|
|
366
|
+
* Locale Data Markup Language") BCP 47-compatible extensions for locale data
|
|
367
|
+
* exchange.
|
|
368
|
+
*
|
|
369
|
+
* A Locale object logically consists of the fields
|
|
370
|
+
* described below.
|
|
371
|
+
*
|
|
372
|
+
*
|
|
373
|
+
* language
|
|
374
|
+
*
|
|
375
|
+
* ISO 639 alpha-2 or alpha-3 language code, or registered
|
|
376
|
+
* language subtags up to 8 alpha letters (for future enhancements).
|
|
377
|
+
* When a language has both an alpha-2 code and an alpha-3 code, the
|
|
378
|
+
* alpha-2 code must be used. You can find a full list of valid
|
|
379
|
+
* language codes in the IANA Language Subtag Registry (search for
|
|
380
|
+
* "Type: language"). The language field is case insensitive, but
|
|
381
|
+
* Locale always canonicalizes to lower case.
|
|
382
|
+
*
|
|
383
|
+
* Well-formed language values have the form
|
|
384
|
+
* [a-zA-Z]{2,8}. Note that this is not the full
|
|
385
|
+
* BCP47 language production, since it excludes extlang. They are
|
|
386
|
+
* not needed since modern three-letter language codes replace
|
|
387
|
+
* them.
|
|
388
|
+
*
|
|
389
|
+
* Example: "en" (English), "ja" (Japanese), "kok" (Konkani)
|
|
390
|
+
*
|
|
391
|
+
* script
|
|
392
|
+
*
|
|
393
|
+
* ISO 15924 alpha-4 script code. You can find a full list of
|
|
394
|
+
* valid script codes in the IANA Language Subtag Registry (search
|
|
395
|
+
* for "Type: script"). The script field is case insensitive, but
|
|
396
|
+
* Locale always canonicalizes to title case (the first
|
|
397
|
+
* letter is upper case and the rest of the letters are lower
|
|
398
|
+
* case).
|
|
399
|
+
*
|
|
400
|
+
* Well-formed script values have the form
|
|
401
|
+
* [a-zA-Z]{4}
|
|
402
|
+
*
|
|
403
|
+
* Example: "Latn" (Latin), "Cyrl" (Cyrillic)
|
|
404
|
+
*
|
|
405
|
+
* country (region)
|
|
406
|
+
*
|
|
407
|
+
* ISO 3166 alpha-2 country code or UN M.49 numeric-3 area code.
|
|
408
|
+
* You can find a full list of valid country and region codes in the
|
|
409
|
+
* IANA Language Subtag Registry (search for "Type: region"). The
|
|
410
|
+
* country (region) field is case insensitive, but
|
|
411
|
+
* Locale always canonicalizes to upper case.
|
|
412
|
+
*
|
|
413
|
+
* Well-formed country/region values have
|
|
414
|
+
* the form [a-zA-Z]{2} | [0-9]{3}
|
|
415
|
+
*
|
|
416
|
+
* Example: "US" (United States), "FR" (France), "029"
|
|
417
|
+
* (Caribbean)
|
|
418
|
+
*
|
|
419
|
+
* variant
|
|
420
|
+
*
|
|
421
|
+
* Any arbitrary value used to indicate a variation of a
|
|
422
|
+
* Locale. Where there are two or more variant values
|
|
423
|
+
* each indicating its own semantics, these values should be ordered
|
|
424
|
+
* by importance, with most important first, separated by
|
|
425
|
+
* underscore('_'). The variant field is case sensitive.
|
|
426
|
+
*
|
|
427
|
+
* Note: IETF BCP 47 places syntactic restrictions on variant
|
|
428
|
+
* subtags. Also BCP 47 subtags are strictly used to indicate
|
|
429
|
+
* additional variations that define a language or its dialects that
|
|
430
|
+
* are not covered by any combinations of language, script and
|
|
431
|
+
* region subtags. You can find a full list of valid variant codes
|
|
432
|
+
* in the IANA Language Subtag Registry (search for "Type: variant").
|
|
433
|
+
*
|
|
434
|
+
* However, the variant field in Locale has
|
|
435
|
+
* historically been used for any kind of variation, not just
|
|
436
|
+
* language variations. For example, some supported variants
|
|
437
|
+
* available in Java SE Runtime Environments indicate alternative
|
|
438
|
+
* cultural behaviors such as calendar type or number script. In
|
|
439
|
+
* BCP 47 this kind of information, which does not identify the
|
|
440
|
+
* language, is supported by extension subtags or private use
|
|
441
|
+
* subtags.
|
|
442
|
+
*
|
|
443
|
+
* Well-formed variant values have the form SUBTAG
|
|
444
|
+
* (('_'|'-') SUBTAG)* where SUBTAG =
|
|
445
|
+
* [0-9][0-9a-zA-Z]{3} | [0-9a-zA-Z]{5,8}. (Note: BCP 47 only
|
|
446
|
+
* uses hyphen ('-') as a delimiter, this is more lenient).
|
|
447
|
+
*
|
|
448
|
+
* Example: "polyton" (Polytonic Greek), "POSIX"
|
|
449
|
+
*
|
|
450
|
+
* extensions
|
|
451
|
+
*
|
|
452
|
+
* A map from single character keys to string values, indicating
|
|
453
|
+
* extensions apart from language identification. The extensions in
|
|
454
|
+
* Locale implement the semantics and syntax of BCP 47
|
|
455
|
+
* extension subtags and private use subtags. The extensions are
|
|
456
|
+
* case insensitive, but Locale canonicalizes all
|
|
457
|
+
* extension keys and values to lower case. Note that extensions
|
|
458
|
+
* cannot have empty values.
|
|
459
|
+
*
|
|
460
|
+
* Well-formed keys are single characters from the set
|
|
461
|
+
* [0-9a-zA-Z]. Well-formed values have the form
|
|
462
|
+
* SUBTAG ('-' SUBTAG)* where for the key 'x'
|
|
463
|
+
* SUBTAG = [0-9a-zA-Z]{1,8} and for other keys
|
|
464
|
+
* SUBTAG = [0-9a-zA-Z]{2,8} (that is, 'x' allows
|
|
465
|
+
* single-character subtags).
|
|
466
|
+
*
|
|
467
|
+
* Example: key="u"/value="ca-japanese" (Japanese Calendar),
|
|
468
|
+
* key="x"/value="java-1-7"
|
|
469
|
+
*
|
|
470
|
+
*
|
|
471
|
+
* Note: Although BCP 47 requires field values to be registered
|
|
472
|
+
* in the IANA Language Subtag Registry, the Locale class
|
|
473
|
+
* does not provide any validation features. The Builder
|
|
474
|
+
* only checks if an individual field satisfies the syntactic
|
|
475
|
+
* requirement (is well-formed), but does not validate the value
|
|
476
|
+
* itself. See {@link Builder} for details.
|
|
477
|
+
*
|
|
478
|
+
* Unicode locale/language extension
|
|
479
|
+
*
|
|
480
|
+
* UTS#35, "Unicode Locale Data Markup Language" defines optional
|
|
481
|
+
* attributes and keywords to override or refine the default behavior
|
|
482
|
+
* associated with a locale. A keyword is represented by a pair of
|
|
483
|
+
* key and type. For example, "nu-thai" indicates that Thai local
|
|
484
|
+
* digits (value:"thai") should be used for formatting numbers
|
|
485
|
+
* (key:"nu").
|
|
486
|
+
*
|
|
487
|
+
* The keywords are mapped to a BCP 47 extension value using the
|
|
488
|
+
* extension key 'u' ({@link #UNICODE_LOCALE_EXTENSION}). The above
|
|
489
|
+
* example, "nu-thai", becomes the extension "u-nu-thai".
|
|
490
|
+
*
|
|
491
|
+
* Thus, when a Locale object contains Unicode locale
|
|
492
|
+
* attributes and keywords,
|
|
493
|
+
* getExtension(UNICODE_LOCALE_EXTENSION) will return a
|
|
494
|
+
* String representing this information, for example, "nu-thai". The
|
|
495
|
+
* Locale class also provides {@link
|
|
496
|
+
* #getUnicodeLocaleAttributes}, {@link #getUnicodeLocaleKeys}, and
|
|
497
|
+
* {@link #getUnicodeLocaleType} which allow you to access Unicode
|
|
498
|
+
* locale attributes and key/type pairs directly. When represented as
|
|
499
|
+
* a string, the Unicode Locale Extension lists attributes
|
|
500
|
+
* alphabetically, followed by key/type sequences with keys listed
|
|
501
|
+
* alphabetically (the order of subtags comprising a key's type is
|
|
502
|
+
* fixed when the type is defined)
|
|
503
|
+
*
|
|
504
|
+
* A well-formed locale key has the form
|
|
505
|
+
* [0-9a-zA-Z]{2}. A well-formed locale type has the
|
|
506
|
+
* form "" | [0-9a-zA-Z]{3,8} ('-' [0-9a-zA-Z]{3,8})* (it
|
|
507
|
+
* can be empty, or a series of subtags 3-8 alphanums in length). A
|
|
508
|
+
* well-formed locale attribute has the form
|
|
509
|
+
* [0-9a-zA-Z]{3,8} (it is a single subtag with the same
|
|
510
|
+
* form as a locale type subtag).
|
|
511
|
+
*
|
|
512
|
+
* The Unicode locale extension specifies optional behavior in
|
|
513
|
+
* locale-sensitive services. Although the LDML specification defines
|
|
514
|
+
* various keys and values, actual locale-sensitive service
|
|
515
|
+
* implementations in a Java Runtime Environment might not support any
|
|
516
|
+
* particular Unicode locale attributes or key/type pairs.
|
|
517
|
+
*
|
|
518
|
+
* Creating a Locale
|
|
519
|
+
*
|
|
520
|
+
* There are several different ways to create a Locale
|
|
521
|
+
* object.
|
|
522
|
+
*
|
|
523
|
+
* Builder
|
|
524
|
+
*
|
|
525
|
+
* Using {@link Builder} you can construct a Locale object
|
|
526
|
+
* that conforms to BCP 47 syntax.
|
|
527
|
+
*
|
|
528
|
+
* Constructors
|
|
529
|
+
*
|
|
530
|
+
* The Locale class provides three constructors:
|
|
531
|
+
*
|
|
532
|
+
* * {@link #Locale(String language)}
|
|
533
|
+
* {@link #Locale(String language, String country)}
|
|
534
|
+
* {@link #Locale(String language, String country, String variant)}
|
|
535
|
+
*
|
|
536
|
+
*
|
|
537
|
+
* These constructors allow you to create a Locale object
|
|
538
|
+
* with language, country and variant, but you cannot specify
|
|
539
|
+
* script or extensions.
|
|
540
|
+
*
|
|
541
|
+
* Factory Methods
|
|
542
|
+
*
|
|
543
|
+
* The method {@link #forLanguageTag} creates a Locale
|
|
544
|
+
* object for a well-formed BCP 47 language tag.
|
|
545
|
+
*
|
|
546
|
+
* Locale Constants
|
|
547
|
+
*
|
|
548
|
+
* The Locale class provides a number of convenient constants
|
|
549
|
+
* that you can use to create Locale objects for commonly used
|
|
550
|
+
* locales. For example, the following creates a Locale object
|
|
551
|
+
* for the United States:
|
|
552
|
+
*
|
|
553
|
+
* * Locale.US
|
|
554
|
+
*
|
|
555
|
+
*
|
|
556
|
+
*
|
|
557
|
+
* Locale Matching
|
|
558
|
+
*
|
|
559
|
+
* If an application or a system is internationalized and provides localized
|
|
560
|
+
* resources for multiple locales, it sometimes needs to find one or more
|
|
561
|
+
* locales (or language tags) which meet each user's specific preferences. Note
|
|
562
|
+
* that a term "language tag" is used interchangeably with "locale" in this
|
|
563
|
+
* locale matching documentation.
|
|
564
|
+
*
|
|
565
|
+
* In order to do matching a user's preferred locales to a set of language
|
|
566
|
+
* tags, RFC 4647 Matching of
|
|
567
|
+
* Language Tags defines two mechanisms: filtering and lookup.
|
|
568
|
+
* Filtering is used to get all matching locales, whereas
|
|
569
|
+
* lookup is to choose the best matching locale.
|
|
570
|
+
* Matching is done case-insensitively. These matching mechanisms are described
|
|
571
|
+
* in the following sections.
|
|
572
|
+
*
|
|
573
|
+
* A user's preference is called a Language Priority List and is
|
|
574
|
+
* expressed as a list of language ranges. There are syntactically two types of
|
|
575
|
+
* language ranges: basic and extended. See
|
|
576
|
+
* {@link Locale.LanguageRange Locale.LanguageRange} for details.
|
|
577
|
+
*
|
|
578
|
+
* Filtering
|
|
579
|
+
*
|
|
580
|
+
* The filtering operation returns all matching language tags. It is defined
|
|
581
|
+
* in RFC 4647 as follows:
|
|
582
|
+
* "In filtering, each language range represents the least specific language
|
|
583
|
+
* tag (that is, the language tag with fewest number of subtags) that is an
|
|
584
|
+
* acceptable match. All of the language tags in the matching set of tags will
|
|
585
|
+
* have an equal or greater number of subtags than the language range. Every
|
|
586
|
+
* non-wildcard subtag in the language range will appear in every one of the
|
|
587
|
+
* matching language tags."
|
|
588
|
+
*
|
|
589
|
+
* There are two types of filtering: filtering for basic language ranges
|
|
590
|
+
* (called "basic filtering") and filtering for extended language ranges
|
|
591
|
+
* (called "extended filtering"). They may return different results by what
|
|
592
|
+
* kind of language ranges are included in the given Language Priority List.
|
|
593
|
+
* {@link Locale.FilteringMode} is a parameter to specify how filtering should
|
|
594
|
+
* be done.
|
|
595
|
+
*
|
|
596
|
+
* Lookup
|
|
597
|
+
*
|
|
598
|
+
* The lookup operation returns the best matching language tags. It is
|
|
599
|
+
* defined in RFC 4647 as follows:
|
|
600
|
+
* "By contrast with filtering, each language range represents the most
|
|
601
|
+
* specific tag that is an acceptable match. The first matching tag found,
|
|
602
|
+
* according to the user's priority, is considered the closest match and is the
|
|
603
|
+
* item returned."
|
|
604
|
+
*
|
|
605
|
+
* For example, if a Language Priority List consists of two language ranges,
|
|
606
|
+
* `"zh-Hant-TW"` and `"en-US"`, in prioritized order, lookup
|
|
607
|
+
* method progressively searches the language tags below in order to find the
|
|
608
|
+
* best matching language tag.
|
|
609
|
+
*
|
|
610
|
+
* * 1. zh-Hant-TW
|
|
611
|
+
* 2. zh-Hant
|
|
612
|
+
* 3. zh
|
|
613
|
+
* 4. en-US
|
|
614
|
+
* 5. en
|
|
615
|
+
*
|
|
616
|
+
*
|
|
617
|
+
* If there is a language tag which matches completely to a language range
|
|
618
|
+
* above, the language tag is returned.
|
|
619
|
+
*
|
|
620
|
+
* `"*"` is the special language range, and it is ignored in lookup.
|
|
621
|
+
*
|
|
622
|
+
* If multiple language tags match as a result of the subtag `'*'`
|
|
623
|
+
* included in a language range, the first matching language tag returned by
|
|
624
|
+
* an {@link Iterator} over a {@link Collection} of language tags is treated as
|
|
625
|
+
* the best matching one.
|
|
626
|
+
*
|
|
627
|
+
* Use of Locale
|
|
628
|
+
*
|
|
629
|
+
* Once you've created a Locale you can query it for information
|
|
630
|
+
* about itself. Use getCountry to get the country (or region)
|
|
631
|
+
* code and getLanguage to get the language code.
|
|
632
|
+
* You can use getDisplayCountry to get the
|
|
633
|
+
* name of the country suitable for displaying to the user. Similarly,
|
|
634
|
+
* you can use getDisplayLanguage to get the name of
|
|
635
|
+
* the language suitable for displaying to the user. Interestingly,
|
|
636
|
+
* the getDisplayXXX methods are themselves locale-sensitive
|
|
637
|
+
* and have two versions: one that uses the default
|
|
638
|
+
* {@link Locale.Category#DISPLAY DISPLAY} locale and one
|
|
639
|
+
* that uses the locale specified as an argument.
|
|
640
|
+
*
|
|
641
|
+
* The Java Platform provides a number of classes that perform locale-sensitive
|
|
642
|
+
* operations. For example, the NumberFormat class formats
|
|
643
|
+
* numbers, currency, and percentages in a locale-sensitive manner. Classes
|
|
644
|
+
* such as NumberFormat have several convenience methods
|
|
645
|
+
* for creating a default object of that type. For example, the
|
|
646
|
+
* NumberFormat class provides these three convenience methods
|
|
647
|
+
* for creating a default NumberFormat object:
|
|
648
|
+
*
|
|
649
|
+
* * NumberFormat.getInstance()
|
|
650
|
+
* NumberFormat.getCurrencyInstance()
|
|
651
|
+
* NumberFormat.getPercentInstance()
|
|
652
|
+
*
|
|
653
|
+
*
|
|
654
|
+
* Each of these methods has two variants; one with an explicit locale
|
|
655
|
+
* and one without; the latter uses the default
|
|
656
|
+
* {@link Locale.Category#FORMAT FORMAT} locale:
|
|
657
|
+
*
|
|
658
|
+
* * NumberFormat.getInstance(myLocale)
|
|
659
|
+
* NumberFormat.getCurrencyInstance(myLocale)
|
|
660
|
+
* NumberFormat.getPercentInstance(myLocale)
|
|
661
|
+
*
|
|
662
|
+
*
|
|
663
|
+
* A Locale is the mechanism for identifying the kind of object
|
|
664
|
+
* (NumberFormat) that you would like to get. The locale is
|
|
665
|
+
* just a mechanism for identifying objects,
|
|
666
|
+
* not a container for the objects themselves.
|
|
667
|
+
*
|
|
668
|
+
* Compatibility
|
|
669
|
+
*
|
|
670
|
+
* In order to maintain compatibility with existing usage, Locale's
|
|
671
|
+
* constructors retain their behavior prior to the Java Runtime
|
|
672
|
+
* Environment version 1.7. The same is largely true for the
|
|
673
|
+
* toString method. Thus Locale objects can continue to
|
|
674
|
+
* be used as they were. In particular, clients who parse the output
|
|
675
|
+
* of toString into language, country, and variant fields can continue
|
|
676
|
+
* to do so (although this is strongly discouraged), although the
|
|
677
|
+
* variant field will have additional information in it if script or
|
|
678
|
+
* extensions are present.
|
|
679
|
+
*
|
|
680
|
+
* In addition, BCP 47 imposes syntax restrictions that are not
|
|
681
|
+
* imposed by Locale's constructors. This means that conversions
|
|
682
|
+
* between some Locales and BCP 47 language tags cannot be made without
|
|
683
|
+
* losing information. Thus toLanguageTag cannot
|
|
684
|
+
* represent the state of locales whose language, country, or variant
|
|
685
|
+
* do not conform to BCP 47.
|
|
686
|
+
*
|
|
687
|
+
* Because of these issues, it is recommended that clients migrate
|
|
688
|
+
* away from constructing non-conforming locales and use the
|
|
689
|
+
* forLanguageTag and Locale.Builder APIs instead.
|
|
690
|
+
* Clients desiring a string representation of the complete locale can
|
|
691
|
+
* then always rely on toLanguageTag for this purpose.
|
|
692
|
+
*
|
|
693
|
+
* Special cases
|
|
694
|
+
*
|
|
695
|
+
* For compatibility reasons, two
|
|
696
|
+
* non-conforming locales are treated as special cases. These are
|
|
697
|
+
* `ja_JP_JP` and `th_TH_TH`. These are ill-formed
|
|
698
|
+
* in BCP 47 since the variants are too short. To ease migration to BCP 47,
|
|
699
|
+
* these are treated specially during construction. These two cases (and only
|
|
700
|
+
* these) cause a constructor to generate an extension, all other values behave
|
|
701
|
+
* exactly as they did prior to Java 7.
|
|
702
|
+
*
|
|
703
|
+
* Java has used `ja_JP_JP` to represent Japanese as used in
|
|
704
|
+
* Japan together with the Japanese Imperial calendar. This is now
|
|
705
|
+
* representable using a Unicode locale extension, by specifying the
|
|
706
|
+
* Unicode locale key `ca` (for "calendar") and type
|
|
707
|
+
* `japanese`. When the Locale constructor is called with the
|
|
708
|
+
* arguments "ja", "JP", "JP", the extension "u-ca-japanese" is
|
|
709
|
+
* automatically added.
|
|
710
|
+
*
|
|
711
|
+
* Java has used `th_TH_TH` to represent Thai as used in
|
|
712
|
+
* Thailand together with Thai digits. This is also now representable using
|
|
713
|
+
* a Unicode locale extension, by specifying the Unicode locale key
|
|
714
|
+
* `nu` (for "number") and value `thai`. When the Locale
|
|
715
|
+
* constructor is called with the arguments "th", "TH", "TH", the
|
|
716
|
+
* extension "u-nu-thai" is automatically added.
|
|
717
|
+
*
|
|
718
|
+
* Serialization
|
|
719
|
+
*
|
|
720
|
+
* During serialization, writeObject writes all fields to the output
|
|
721
|
+
* stream, including extensions.
|
|
722
|
+
*
|
|
723
|
+
* During deserialization, readResolve adds extensions as described
|
|
724
|
+
* in Special Cases, only
|
|
725
|
+
* for the two cases th_TH_TH and ja_JP_JP.
|
|
726
|
+
*
|
|
727
|
+
* Legacy language codes
|
|
728
|
+
*
|
|
729
|
+
* Locale's constructor has always converted three language codes to
|
|
730
|
+
* their earlier, obsoleted forms: `he` maps to `iw`,
|
|
731
|
+
* `yi` maps to `ji`, and `id` maps to
|
|
732
|
+
* `in`. This continues to be the case, in order to not break
|
|
733
|
+
* backwards compatibility.
|
|
734
|
+
*
|
|
735
|
+
* The APIs added in 1.7 map between the old and new language codes,
|
|
736
|
+
* maintaining the old codes internal to Locale (so that
|
|
737
|
+
* getLanguage and toString reflect the old
|
|
738
|
+
* code), but using the new codes in the BCP 47 language tag APIs (so
|
|
739
|
+
* that toLanguageTag reflects the new one). This
|
|
740
|
+
* preserves the equivalence between Locales no matter which code or
|
|
741
|
+
* API is used to construct them. Java's default resource bundle
|
|
742
|
+
* lookup mechanism also implements this mapping, so that resources
|
|
743
|
+
* can be named using either convention, see {@link ResourceBundle.Control}.
|
|
744
|
+
*
|
|
745
|
+
* Three-letter language/country(region) codes
|
|
746
|
+
*
|
|
747
|
+
* The Locale constructors have always specified that the language
|
|
748
|
+
* and the country param be two characters in length, although in
|
|
749
|
+
* practice they have accepted any length. The specification has now
|
|
750
|
+
* been relaxed to allow language codes of two to eight characters and
|
|
751
|
+
* country (region) codes of two to three characters, and in
|
|
752
|
+
* particular, three-letter language codes and three-digit region
|
|
753
|
+
* codes as specified in the IANA Language Subtag Registry. For
|
|
754
|
+
* compatibility, the implementation still does not impose a length
|
|
755
|
+
* constraint.
|
|
756
|
+
*
|
|
757
|
+
* @see Builder
|
|
758
|
+
* @see ResourceBundle
|
|
759
|
+
* @see java.text.Format
|
|
760
|
+
* @see java.text.NumberFormat
|
|
761
|
+
* @see java.text.Collator
|
|
762
|
+
* @author Mark Davis
|
|
763
|
+
* @since 1.1
|
|
764
|
+
*/
|
|
765
|
+
export class Locale {
|
|
766
|
+
/**
|
|
767
|
+
* Gets the current value of the default locale for this instance
|
|
768
|
+
* of the Java Virtual Machine.
|
|
769
|
+
*
|
|
770
|
+
* The Java Virtual Machine sets the default locale during startup
|
|
771
|
+
* based on the host environment. It is used by many locale-sensitive
|
|
772
|
+
* methods if no locale is explicitly specified.
|
|
773
|
+
* It can be changed using the
|
|
774
|
+
* {@link #setDefault(java.util.Locale) setDefault} method.
|
|
775
|
+
*
|
|
776
|
+
* @return the default locale for this instance of the Java Virtual Machine
|
|
777
|
+
*/
|
|
778
|
+
static getDefault(): Locale;
|
|
779
|
+
/**
|
|
780
|
+
* Returns an array of all installed locales.
|
|
781
|
+
* The returned array represents the union of locales supported
|
|
782
|
+
* by the Java runtime environment and by installed
|
|
783
|
+
* {@link java.util.spi.LocaleServiceProvider LocaleServiceProvider}
|
|
784
|
+
* implementations. It must contain at least a Locale
|
|
785
|
+
* instance equal to {@link java.util.Locale#US Locale.US}.
|
|
786
|
+
*
|
|
787
|
+
* @return An array of installed locales.
|
|
788
|
+
*/
|
|
789
|
+
static getAvailableLocales(): Locale[];
|
|
790
|
+
/**
|
|
791
|
+
* Returns a list of all 2-letter country codes defined in ISO 3166.
|
|
792
|
+
* Can be used to create Locales.
|
|
793
|
+
* This method is equivalent to {@link #getISOCountries(Locale.IsoCountryCode type)}
|
|
794
|
+
* with `type` {@link IsoCountryCode#PART1_ALPHA2}.
|
|
795
|
+
*
|
|
796
|
+
* Note: The Locale class also supports other codes for
|
|
797
|
+
* country (region), such as 3-letter numeric UN M.49 area codes.
|
|
798
|
+
* Therefore, the list returned by this method does not contain ALL valid
|
|
799
|
+
* codes that can be used to create Locales.
|
|
800
|
+
*
|
|
801
|
+
* Note that this method does not return obsolete 2-letter country codes.
|
|
802
|
+
* ISO3166-3 codes which designate country codes for those obsolete codes,
|
|
803
|
+
* can be retrieved from {@link #getISOCountries(Locale.IsoCountryCode type)} with
|
|
804
|
+
* `type` {@link IsoCountryCode#PART3}.
|
|
805
|
+
* @return An array of ISO 3166 two-letter country codes.
|
|
806
|
+
*/
|
|
807
|
+
static getISOCountries(): string[];
|
|
808
|
+
/**
|
|
809
|
+
* Returns a list of all 2-letter language codes defined in ISO 639.
|
|
810
|
+
* Can be used to create Locales.
|
|
811
|
+
*
|
|
812
|
+
* Note:
|
|
813
|
+
*
|
|
814
|
+
* ISO 639 is not a stable standard— some languages' codes have changed.
|
|
815
|
+
* The list this function returns includes both the new and the old codes for the
|
|
816
|
+
* languages whose codes have changed.
|
|
817
|
+
* The Locale class also supports language codes up to
|
|
818
|
+
* 8 characters in length. Therefore, the list returned by this method does
|
|
819
|
+
* not contain ALL valid codes that can be used to create Locales.
|
|
820
|
+
*
|
|
821
|
+
*
|
|
822
|
+
* @return An array of ISO 639 two-letter language codes.
|
|
823
|
+
*/
|
|
824
|
+
static getISOLanguages(): string[];
|
|
825
|
+
/**
|
|
826
|
+
* Returns the language code of this Locale.
|
|
827
|
+
*
|
|
828
|
+
* Note: ISO 639 is not a stable standard— some languages' codes have changed.
|
|
829
|
+
* Locale's constructor recognizes both the new and the old codes for the languages
|
|
830
|
+
* whose codes have changed, but this function always returns the old code. If you
|
|
831
|
+
* want to check for a specific language whose code has changed, don't do
|
|
832
|
+
* * if (locale.getLanguage().equals("he")) // BAD!
|
|
833
|
+
* ...
|
|
834
|
+
*
|
|
835
|
+
* Instead, do
|
|
836
|
+
* * if (locale.getLanguage().equals(new Locale("he").getLanguage()))
|
|
837
|
+
* ...
|
|
838
|
+
*
|
|
839
|
+
* @return The language code, or the empty string if none is defined.
|
|
840
|
+
* @see #getDisplayLanguage
|
|
841
|
+
*/
|
|
842
|
+
getLanguage(): string;
|
|
843
|
+
/**
|
|
844
|
+
* Returns the script for this locale, which should
|
|
845
|
+
* either be the empty string or an ISO 15924 4-letter script
|
|
846
|
+
* code. The first letter is uppercase and the rest are
|
|
847
|
+
* lowercase, for example, 'Latn', 'Cyrl'.
|
|
848
|
+
*
|
|
849
|
+
* @return The script code, or the empty string if none is defined.
|
|
850
|
+
* @see #getDisplayScript
|
|
851
|
+
* @since 1.7
|
|
852
|
+
*/
|
|
853
|
+
getScript(): string;
|
|
854
|
+
/**
|
|
855
|
+
* Returns the country/region code for this locale, which should
|
|
856
|
+
* either be the empty string, an uppercase ISO 3166 2-letter code,
|
|
857
|
+
* or a UN M.49 3-digit code.
|
|
858
|
+
*
|
|
859
|
+
* @return The country/region code, or the empty string if none is defined.
|
|
860
|
+
* @see #getDisplayCountry
|
|
861
|
+
*/
|
|
862
|
+
getCountry(): string;
|
|
863
|
+
/**
|
|
864
|
+
* Returns the variant code for this locale.
|
|
865
|
+
*
|
|
866
|
+
* @return The variant code, or the empty string if none is defined.
|
|
867
|
+
* @see #getDisplayVariant
|
|
868
|
+
*/
|
|
869
|
+
getVariant(): string;
|
|
870
|
+
/**
|
|
871
|
+
* Returns the extension (or private use) value associated with
|
|
872
|
+
* the specified key, or null if there is no extension
|
|
873
|
+
* associated with the key. To be well-formed, the key must be one
|
|
874
|
+
* of [0-9A-Za-z]. Keys are case-insensitive, so
|
|
875
|
+
* for example 'z' and 'Z' represent the same extension.
|
|
876
|
+
*
|
|
877
|
+
* @param key the extension key
|
|
878
|
+
* @return The extension, or null if this locale defines no
|
|
879
|
+
* extension for the specified key.
|
|
880
|
+
* @throws IllegalArgumentException if key is not well-formed
|
|
881
|
+
* @see #PRIVATE_USE_EXTENSION
|
|
882
|
+
* @see #UNICODE_LOCALE_EXTENSION
|
|
883
|
+
* @since 1.7
|
|
884
|
+
*/
|
|
885
|
+
getExtension(key: string): string;
|
|
886
|
+
/**
|
|
887
|
+
* Returns the set of extension keys associated with this locale, or the
|
|
888
|
+
* empty set if it has no extensions. The returned set is unmodifiable.
|
|
889
|
+
* The keys will all be lower-case.
|
|
890
|
+
*
|
|
891
|
+
* @return The set of extension keys, or the empty set if this locale has
|
|
892
|
+
* no extensions.
|
|
893
|
+
* @since 1.7
|
|
894
|
+
*/
|
|
895
|
+
getExtensionKeys(): Set<string>;
|
|
896
|
+
/**
|
|
897
|
+
* Returns the set of unicode locale attributes associated with
|
|
898
|
+
* this locale, or the empty set if it has no attributes. The
|
|
899
|
+
* returned set is unmodifiable.
|
|
900
|
+
*
|
|
901
|
+
* @return The set of attributes.
|
|
902
|
+
* @since 1.7
|
|
903
|
+
*/
|
|
904
|
+
getUnicodeLocaleAttributes(): Set<string>;
|
|
905
|
+
/**
|
|
906
|
+
* Returns the Unicode locale type associated with the specified Unicode locale key
|
|
907
|
+
* for this locale. Returns the empty string for keys that are defined with no type.
|
|
908
|
+
* Returns null if the key is not defined. Keys are case-insensitive. The key must
|
|
909
|
+
* be two alphanumeric characters ([0-9a-zA-Z]), or an IllegalArgumentException is
|
|
910
|
+
* thrown.
|
|
911
|
+
*
|
|
912
|
+
* @param key the Unicode locale key
|
|
913
|
+
* @return The Unicode locale type associated with the key, or null if the
|
|
914
|
+
* locale does not define the key.
|
|
915
|
+
* @throws IllegalArgumentException if the key is not well-formed
|
|
916
|
+
* @throws NullPointerException if key is null
|
|
917
|
+
* @since 1.7
|
|
918
|
+
*/
|
|
919
|
+
getUnicodeLocaleType(key: string): string;
|
|
920
|
+
/**
|
|
921
|
+
* Returns the set of Unicode locale keys defined by this locale, or the empty set if
|
|
922
|
+
* this locale has none. The returned set is immutable. Keys are all lower case.
|
|
923
|
+
*
|
|
924
|
+
* @return The set of Unicode locale keys, or the empty set if this locale has
|
|
925
|
+
* no Unicode locale keywords.
|
|
926
|
+
* @since 1.7
|
|
927
|
+
*/
|
|
928
|
+
getUnicodeLocaleKeys(): Set<string>;
|
|
929
|
+
/**
|
|
930
|
+
* Returns a string representation of this Locale
|
|
931
|
+
* object, consisting of language, country, variant, script,
|
|
932
|
+
* and extensions as below:
|
|
933
|
+
*
|
|
934
|
+
* language + "_" + country + "_" + (variant + "_#" | "#") + script + "_" + extensions
|
|
935
|
+
*
|
|
936
|
+
*
|
|
937
|
+
* Language is always lower case, country is always upper case, script is always title
|
|
938
|
+
* case, and extensions are always lower case. Extensions and private use subtags
|
|
939
|
+
* will be in canonical order as explained in {@link #toLanguageTag}.
|
|
940
|
+
*
|
|
941
|
+
* When the locale has neither script nor extensions, the result is the same as in
|
|
942
|
+
* Java 6 and prior.
|
|
943
|
+
*
|
|
944
|
+
* If both the language and country fields are missing, this function will return
|
|
945
|
+
* the empty string, even if the variant, script, or extensions field is present (you
|
|
946
|
+
* can't have a locale with just a variant, the variant must accompany a well-formed
|
|
947
|
+
* language or country code).
|
|
948
|
+
*
|
|
949
|
+
* If script or extensions are present and variant is missing, no underscore is
|
|
950
|
+
* added before the "#".
|
|
951
|
+
*
|
|
952
|
+
* This behavior is designed to support debugging and to be compatible with
|
|
953
|
+
* previous uses of toString that expected language, country, and variant
|
|
954
|
+
* fields only. To represent a Locale as a String for interchange purposes, use
|
|
955
|
+
* {@link #toLanguageTag}.
|
|
956
|
+
*
|
|
957
|
+
* Examples:
|
|
958
|
+
* `en`
|
|
959
|
+
* `de_DE`
|
|
960
|
+
* `_GB`
|
|
961
|
+
* `en_US_WIN`
|
|
962
|
+
* `de__POSIX`
|
|
963
|
+
* `zh_CN_#Hans`
|
|
964
|
+
* `zh_TW_#Hant_x-java`
|
|
965
|
+
* `th_TH_TH_#u-nu-thai`
|
|
966
|
+
*
|
|
967
|
+
* @return A string representation of the Locale, for debugging.
|
|
968
|
+
* @see #getDisplayName
|
|
969
|
+
* @see #toLanguageTag
|
|
970
|
+
*/
|
|
971
|
+
toString(): string;
|
|
972
|
+
/**
|
|
973
|
+
* Returns a three-letter abbreviation of this locale's language.
|
|
974
|
+
* If the language matches an ISO 639-1 two-letter code, the
|
|
975
|
+
* corresponding ISO 639-2/T three-letter lowercase code is
|
|
976
|
+
* returned. The ISO 639-2 language codes can be found on-line,
|
|
977
|
+
* see "Codes for the Representation of Names of Languages Part 2:
|
|
978
|
+
* Alpha-3 Code". If the locale specifies a three-letter
|
|
979
|
+
* language, the language is returned as is. If the locale does
|
|
980
|
+
* not specify a language the empty string is returned.
|
|
981
|
+
*
|
|
982
|
+
* @return A three-letter abbreviation of this locale's language.
|
|
983
|
+
* @exception MissingResourceException Throws MissingResourceException if
|
|
984
|
+
* three-letter language abbreviation is not available for this locale.
|
|
985
|
+
*/
|
|
986
|
+
getISO3Language(): string;
|
|
987
|
+
/**
|
|
988
|
+
* Returns a three-letter abbreviation for this locale's country.
|
|
989
|
+
* If the country matches an ISO 3166-1 alpha-2 code, the
|
|
990
|
+
* corresponding ISO 3166-1 alpha-3 uppercase code is returned.
|
|
991
|
+
* If the locale doesn't specify a country, this will be the empty
|
|
992
|
+
* string.
|
|
993
|
+
*
|
|
994
|
+
* The ISO 3166-1 codes can be found on-line.
|
|
995
|
+
*
|
|
996
|
+
* @return A three-letter abbreviation of this locale's country.
|
|
997
|
+
* @exception MissingResourceException Throws MissingResourceException if the
|
|
998
|
+
* three-letter country abbreviation is not available for this locale.
|
|
999
|
+
*/
|
|
1000
|
+
getISO3Country(): string;
|
|
1001
|
+
/**
|
|
1002
|
+
* Returns a name for the locale's language that is appropriate for display to the
|
|
1003
|
+
* user.
|
|
1004
|
+
* If possible, the name returned will be localized for the default
|
|
1005
|
+
* {@link Locale.Category#DISPLAY DISPLAY} locale.
|
|
1006
|
+
* For example, if the locale is fr_FR and the default
|
|
1007
|
+
* {@link Locale.Category#DISPLAY DISPLAY} locale
|
|
1008
|
+
* is en_US, getDisplayLanguage() will return "French"; if the locale is en_US and
|
|
1009
|
+
* the default {@link Locale.Category#DISPLAY DISPLAY} locale is fr_FR,
|
|
1010
|
+
* getDisplayLanguage() will return "anglais".
|
|
1011
|
+
* If the name returned cannot be localized for the default
|
|
1012
|
+
* {@link Locale.Category#DISPLAY DISPLAY} locale,
|
|
1013
|
+
* (say, we don't have a Japanese name for Croatian),
|
|
1014
|
+
* this function falls back on the English name, and uses the ISO code as a last-resort
|
|
1015
|
+
* value. If the locale doesn't specify a language, this function returns the empty string.
|
|
1016
|
+
*
|
|
1017
|
+
* @return The name of the display language.
|
|
1018
|
+
*/
|
|
1019
|
+
getDisplayLanguage(): string;
|
|
1020
|
+
/**
|
|
1021
|
+
* Returns a name for the locale's language that is appropriate for display to the
|
|
1022
|
+
* user.
|
|
1023
|
+
* If possible, the name returned will be localized according to inLocale.
|
|
1024
|
+
* For example, if the locale is fr_FR and inLocale
|
|
1025
|
+
* is en_US, getDisplayLanguage() will return "French"; if the locale is en_US and
|
|
1026
|
+
* inLocale is fr_FR, getDisplayLanguage() will return "anglais".
|
|
1027
|
+
* If the name returned cannot be localized according to inLocale,
|
|
1028
|
+
* (say, we don't have a Japanese name for Croatian),
|
|
1029
|
+
* this function falls back on the English name, and finally
|
|
1030
|
+
* on the ISO code as a last-resort value. If the locale doesn't specify a language,
|
|
1031
|
+
* this function returns the empty string.
|
|
1032
|
+
*
|
|
1033
|
+
* @param inLocale The locale for which to retrieve the display language.
|
|
1034
|
+
* @return The name of the display language appropriate to the given locale.
|
|
1035
|
+
* @exception NullPointerException if inLocale is null
|
|
1036
|
+
*/
|
|
1037
|
+
getDisplayLanguage(inLocale: Locale): string;
|
|
1038
|
+
/**
|
|
1039
|
+
* Returns a name for the locale's script that is appropriate for display to
|
|
1040
|
+
* the user. If possible, the name will be localized for the default
|
|
1041
|
+
* {@link Locale.Category#DISPLAY DISPLAY} locale. Returns
|
|
1042
|
+
* the empty string if this locale doesn't specify a script code.
|
|
1043
|
+
*
|
|
1044
|
+
* @return the display name of the script code for the current default
|
|
1045
|
+
* {@link Locale.Category#DISPLAY DISPLAY} locale
|
|
1046
|
+
* @since 1.7
|
|
1047
|
+
*/
|
|
1048
|
+
getDisplayScript(): string;
|
|
1049
|
+
/**
|
|
1050
|
+
* Returns a name for the locale's script that is appropriate
|
|
1051
|
+
* for display to the user. If possible, the name will be
|
|
1052
|
+
* localized for the given locale. Returns the empty string if
|
|
1053
|
+
* this locale doesn't specify a script code.
|
|
1054
|
+
*
|
|
1055
|
+
* @param inLocale The locale for which to retrieve the display script.
|
|
1056
|
+
* @return the display name of the script code for the current default
|
|
1057
|
+
* {@link Locale.Category#DISPLAY DISPLAY} locale
|
|
1058
|
+
* @throws NullPointerException if inLocale is null
|
|
1059
|
+
* @since 1.7
|
|
1060
|
+
*/
|
|
1061
|
+
getDisplayScript(inLocale: Locale): string;
|
|
1062
|
+
/**
|
|
1063
|
+
* Returns a name for the locale's country that is appropriate for display to the
|
|
1064
|
+
* user.
|
|
1065
|
+
* If possible, the name returned will be localized for the default
|
|
1066
|
+
* {@link Locale.Category#DISPLAY DISPLAY} locale.
|
|
1067
|
+
* For example, if the locale is fr_FR and the default
|
|
1068
|
+
* {@link Locale.Category#DISPLAY DISPLAY} locale
|
|
1069
|
+
* is en_US, getDisplayCountry() will return "France"; if the locale is en_US and
|
|
1070
|
+
* the default {@link Locale.Category#DISPLAY DISPLAY} locale is fr_FR,
|
|
1071
|
+
* getDisplayCountry() will return "Etats-Unis".
|
|
1072
|
+
* If the name returned cannot be localized for the default
|
|
1073
|
+
* {@link Locale.Category#DISPLAY DISPLAY} locale,
|
|
1074
|
+
* (say, we don't have a Japanese name for Croatia),
|
|
1075
|
+
* this function falls back on the English name, and uses the ISO code as a last-resort
|
|
1076
|
+
* value. If the locale doesn't specify a country, this function returns the empty string.
|
|
1077
|
+
*
|
|
1078
|
+
* @return The name of the country appropriate to the locale.
|
|
1079
|
+
*/
|
|
1080
|
+
getDisplayCountry(): string;
|
|
1081
|
+
/**
|
|
1082
|
+
* Returns a name for the locale's country that is appropriate for display to the
|
|
1083
|
+
* user.
|
|
1084
|
+
* If possible, the name returned will be localized according to inLocale.
|
|
1085
|
+
* For example, if the locale is fr_FR and inLocale
|
|
1086
|
+
* is en_US, getDisplayCountry() will return "France"; if the locale is en_US and
|
|
1087
|
+
* inLocale is fr_FR, getDisplayCountry() will return "Etats-Unis".
|
|
1088
|
+
* If the name returned cannot be localized according to inLocale.
|
|
1089
|
+
* (say, we don't have a Japanese name for Croatia),
|
|
1090
|
+
* this function falls back on the English name, and finally
|
|
1091
|
+
* on the ISO code as a last-resort value. If the locale doesn't specify a country,
|
|
1092
|
+
* this function returns the empty string.
|
|
1093
|
+
*
|
|
1094
|
+
* @param inLocale The locale for which to retrieve the display country.
|
|
1095
|
+
* @return The name of the country appropriate to the given locale.
|
|
1096
|
+
* @exception NullPointerException if inLocale is null
|
|
1097
|
+
*/
|
|
1098
|
+
getDisplayCountry(inLocale: Locale): string;
|
|
1099
|
+
/**
|
|
1100
|
+
* Returns a name for the locale's variant code that is appropriate for display to the
|
|
1101
|
+
* user. If possible, the name will be localized for the default
|
|
1102
|
+
* {@link Locale.Category#DISPLAY DISPLAY} locale. If the locale
|
|
1103
|
+
* doesn't specify a variant code, this function returns the empty string.
|
|
1104
|
+
*
|
|
1105
|
+
* @return The name of the display variant code appropriate to the locale.
|
|
1106
|
+
*/
|
|
1107
|
+
getDisplayVariant(): string;
|
|
1108
|
+
/**
|
|
1109
|
+
* Returns a name for the locale's variant code that is appropriate for display to the
|
|
1110
|
+
* user. If possible, the name will be localized for inLocale. If the locale
|
|
1111
|
+
* doesn't specify a variant code, this function returns the empty string.
|
|
1112
|
+
*
|
|
1113
|
+
* @param inLocale The locale for which to retrieve the display variant code.
|
|
1114
|
+
* @return The name of the display variant code appropriate to the given locale.
|
|
1115
|
+
* @exception NullPointerException if inLocale is null
|
|
1116
|
+
*/
|
|
1117
|
+
getDisplayVariant(inLocale: Locale): string;
|
|
1118
|
+
/**
|
|
1119
|
+
* Returns a name for the locale that is appropriate for display to the
|
|
1120
|
+
* user. This will be the values returned by getDisplayLanguage(),
|
|
1121
|
+
* getDisplayScript(), getDisplayCountry(), getDisplayVariant() and
|
|
1122
|
+
* optional Unicode extensions
|
|
1123
|
+
* assembled into a single string. The non-empty values are used in order, with
|
|
1124
|
+
* the second and subsequent names in parentheses. For example:
|
|
1125
|
+
*
|
|
1126
|
+
* language (script, country, variant(, extension)*)
|
|
1127
|
+
* language (country(, extension)*)
|
|
1128
|
+
* language (variant(, extension)*)
|
|
1129
|
+
* script (country(, extension)*)
|
|
1130
|
+
* country (extension)*
|
|
1131
|
+
*
|
|
1132
|
+
* depending on which fields are specified in the locale. The field
|
|
1133
|
+
* separator in the above parentheses, denoted as a comma character, may
|
|
1134
|
+
* be localized depending on the locale. If the language, script, country,
|
|
1135
|
+
* and variant fields are all empty, this function returns the empty string.
|
|
1136
|
+
*
|
|
1137
|
+
* @return The name of the locale appropriate to display.
|
|
1138
|
+
*/
|
|
1139
|
+
getDisplayName(): string;
|
|
1140
|
+
/**
|
|
1141
|
+
* Returns a name for the locale that is appropriate for display
|
|
1142
|
+
* to the user. This will be the values returned by
|
|
1143
|
+
* getDisplayLanguage(), getDisplayScript(),getDisplayCountry()
|
|
1144
|
+
* getDisplayVariant(), and optional
|
|
1145
|
+
* Unicode extensions assembled into a single string. The non-empty
|
|
1146
|
+
* values are used in order, with the second and subsequent names in
|
|
1147
|
+
* parentheses. For example:
|
|
1148
|
+
*
|
|
1149
|
+
* language (script, country, variant(, extension)*)
|
|
1150
|
+
* language (country(, extension)*)
|
|
1151
|
+
* language (variant(, extension)*)
|
|
1152
|
+
* script (country(, extension)*)
|
|
1153
|
+
* country (extension)*
|
|
1154
|
+
*
|
|
1155
|
+
* depending on which fields are specified in the locale. The field
|
|
1156
|
+
* separator in the above parentheses, denoted as a comma character, may
|
|
1157
|
+
* be localized depending on the locale. If the language, script, country,
|
|
1158
|
+
* and variant fields are all empty, this function returns the empty string.
|
|
1159
|
+
*
|
|
1160
|
+
* @param inLocale The locale for which to retrieve the display name.
|
|
1161
|
+
* @return The name of the locale appropriate to display.
|
|
1162
|
+
* @throws NullPointerException if inLocale is null
|
|
1163
|
+
*/
|
|
1164
|
+
getDisplayName(inLocale: Locale): string;
|
|
1165
|
+
}
|
|
1166
|
+
/**
|
|
1167
|
+
* An object that maps keys to values. A map cannot contain duplicate keys;
|
|
1168
|
+
* each key can map to at most one value.
|
|
1169
|
+
*
|
|
1170
|
+
* This interface takes the place of the `Dictionary` class, which
|
|
1171
|
+
* was a totally abstract class rather than an interface.
|
|
1172
|
+
*
|
|
1173
|
+
* The `Map` interface provides three collection views, which
|
|
1174
|
+
* allow a map's contents to be viewed as a set of keys, collection of values,
|
|
1175
|
+
* or set of key-value mappings. The order of a map is defined as
|
|
1176
|
+
* the order in which the iterators on the map's collection views return their
|
|
1177
|
+
* elements. Some map implementations, like the `TreeMap` class, make
|
|
1178
|
+
* specific guarantees as to their order; others, like the `HashMap`
|
|
1179
|
+
* class, do not.
|
|
1180
|
+
*
|
|
1181
|
+
* Note: great care must be exercised if mutable objects are used as map
|
|
1182
|
+
* keys. The behavior of a map is not specified if the value of an object is
|
|
1183
|
+
* changed in a manner that affects `equals` comparisons while the
|
|
1184
|
+
* object is a key in the map. A special case of this prohibition is that it
|
|
1185
|
+
* is not permissible for a map to contain itself as a key. While it is
|
|
1186
|
+
* permissible for a map to contain itself as a value, extreme caution is
|
|
1187
|
+
* advised: the `equals` and `hashCode` methods are no longer
|
|
1188
|
+
* well defined on such a map.
|
|
1189
|
+
*
|
|
1190
|
+
* All general-purpose map implementation classes should provide two
|
|
1191
|
+
* "standard" constructors: a void (no arguments) constructor which creates an
|
|
1192
|
+
* empty map, and a constructor with a single argument of type `Map`,
|
|
1193
|
+
* which creates a new map with the same key-value mappings as its argument.
|
|
1194
|
+
* In effect, the latter constructor allows the user to copy any map,
|
|
1195
|
+
* producing an equivalent map of the desired class. There is no way to
|
|
1196
|
+
* enforce this recommendation (as interfaces cannot contain constructors) but
|
|
1197
|
+
* all of the general-purpose map implementations in the JDK comply.
|
|
1198
|
+
*
|
|
1199
|
+
* The "destructive" methods contained in this interface, that is, the
|
|
1200
|
+
* methods that modify the map on which they operate, are specified to throw
|
|
1201
|
+
* `UnsupportedOperationException` if this map does not support the
|
|
1202
|
+
* operation. If this is the case, these methods may, but are not required
|
|
1203
|
+
* to, throw an `UnsupportedOperationException` if the invocation would
|
|
1204
|
+
* have no effect on the map. For example, invoking the {@link #putAll(Map)}
|
|
1205
|
+
* method on an unmodifiable map may, but is not required to, throw the
|
|
1206
|
+
* exception if the map whose mappings are to be "superimposed" is empty.
|
|
1207
|
+
*
|
|
1208
|
+
* Some map implementations have restrictions on the keys and values they
|
|
1209
|
+
* may contain. For example, some implementations prohibit null keys and
|
|
1210
|
+
* values, and some have restrictions on the types of their keys. Attempting
|
|
1211
|
+
* to insert an ineligible key or value throws an unchecked exception,
|
|
1212
|
+
* typically `NullPointerException` or `ClassCastException`.
|
|
1213
|
+
* Attempting to query the presence of an ineligible key or value may throw an
|
|
1214
|
+
* exception, or it may simply return false; some implementations will exhibit
|
|
1215
|
+
* the former behavior and some will exhibit the latter. More generally,
|
|
1216
|
+
* attempting an operation on an ineligible key or value whose completion
|
|
1217
|
+
* would not result in the insertion of an ineligible element into the map may
|
|
1218
|
+
* throw an exception or it may succeed, at the option of the implementation.
|
|
1219
|
+
* Such exceptions are marked as "optional" in the specification for this
|
|
1220
|
+
* interface.
|
|
1221
|
+
*
|
|
1222
|
+
* Many methods in Collections Framework interfaces are defined
|
|
1223
|
+
* in terms of the {@link Object#equals(Object) equals} method. For
|
|
1224
|
+
* example, the specification for the {@link #containsKey(Object)
|
|
1225
|
+
* containsKey(Object key)} method says: "returns `true` if and
|
|
1226
|
+
* only if this map contains a mapping for a key `k` such that
|
|
1227
|
+
* `(key==null ? k==null : key.equals(k))`." This specification should
|
|
1228
|
+
* not be construed to imply that invoking `Map.containsKey`
|
|
1229
|
+
* with a non-null argument `key` will cause `key.equals(k)` to
|
|
1230
|
+
* be invoked for any key `k`. Implementations are free to
|
|
1231
|
+
* implement optimizations whereby the `equals` invocation is avoided,
|
|
1232
|
+
* for example, by first comparing the hash codes of the two keys. (The
|
|
1233
|
+
* {@link Object#hashCode()} specification guarantees that two objects with
|
|
1234
|
+
* unequal hash codes cannot be equal.) More generally, implementations of
|
|
1235
|
+
* the various Collections Framework interfaces are free to take advantage of
|
|
1236
|
+
* the specified behavior of underlying {@link Object} methods wherever the
|
|
1237
|
+
* implementor deems it appropriate.
|
|
1238
|
+
*
|
|
1239
|
+
* Some map operations which perform recursive traversal of the map may fail
|
|
1240
|
+
* with an exception for self-referential instances where the map directly or
|
|
1241
|
+
* indirectly contains itself. This includes the `clone()`,
|
|
1242
|
+
* `equals()`, `hashCode()` and `toString()` methods.
|
|
1243
|
+
* Implementations may optionally handle the self-referential scenario, however
|
|
1244
|
+
* most current implementations do not do so.
|
|
1245
|
+
*
|
|
1246
|
+
* Unmodifiable Maps
|
|
1247
|
+
* The {@link Map#of() Map.of},
|
|
1248
|
+
* {@link Map#ofEntries(Map.Entry...) Map.ofEntries}, and
|
|
1249
|
+
* {@link Map#copyOf Map.copyOf}
|
|
1250
|
+
* static factory methods provide a convenient way to create unmodifiable maps.
|
|
1251
|
+
* The `Map`
|
|
1252
|
+
* instances created by these methods have the following characteristics:
|
|
1253
|
+
*
|
|
1254
|
+
*
|
|
1255
|
+
* They are unmodifiable. Keys and values
|
|
1256
|
+
* cannot be added, removed, or updated. Calling any mutator method on the Map
|
|
1257
|
+
* will always cause `UnsupportedOperationException` to be thrown.
|
|
1258
|
+
* However, if the contained keys or values are themselves mutable, this may cause the
|
|
1259
|
+
* Map to behave inconsistently or its contents to appear to change.
|
|
1260
|
+
* They disallow `null` keys and values. Attempts to create them with
|
|
1261
|
+
* `null` keys or values result in `NullPointerException`.
|
|
1262
|
+
* They are serializable if all keys and values are serializable.
|
|
1263
|
+
* They reject duplicate keys at creation time. Duplicate keys
|
|
1264
|
+
* passed to a static factory method result in `IllegalArgumentException`.
|
|
1265
|
+
* The iteration order of mappings is unspecified and is subject to change.
|
|
1266
|
+
* They are value-based.
|
|
1267
|
+
* Callers should make no assumptions about the identity of the returned instances.
|
|
1268
|
+
* Factories are free to create new instances or reuse existing ones. Therefore,
|
|
1269
|
+
* identity-sensitive operations on these instances (reference equality (`==`),
|
|
1270
|
+
* identity hash code, and synchronization) are unreliable and should be avoided.
|
|
1271
|
+
* They are serialized as specified on the
|
|
1272
|
+
* Serialized Form
|
|
1273
|
+
* page.
|
|
1274
|
+
*
|
|
1275
|
+
*
|
|
1276
|
+
* This interface is a member of the
|
|
1277
|
+
*
|
|
1278
|
+
* Java Collections Framework.
|
|
1279
|
+
*
|
|
1280
|
+
* @param the type of keys maintained by this map
|
|
1281
|
+
* @param the type of mapped values
|
|
1282
|
+
*
|
|
1283
|
+
* @author Josh Bloch
|
|
1284
|
+
* @see HashMap
|
|
1285
|
+
* @see TreeMap
|
|
1286
|
+
* @see Hashtable
|
|
1287
|
+
* @see SortedMap
|
|
1288
|
+
* @see Collection
|
|
1289
|
+
* @see Set
|
|
1290
|
+
* @since 1.2
|
|
1291
|
+
*/
|
|
1292
|
+
export class Map<K, V> {
|
|
1293
|
+
/**
|
|
1294
|
+
* Returns the number of key-value mappings in this map. If the
|
|
1295
|
+
* map contains more than `Integer.MAX_VALUE` elements, returns
|
|
1296
|
+
* `Integer.MAX_VALUE`.
|
|
1297
|
+
*
|
|
1298
|
+
* @return the number of key-value mappings in this map
|
|
1299
|
+
*/
|
|
1300
|
+
size(): number;
|
|
1301
|
+
/**
|
|
1302
|
+
* Returns `true` if this map contains no key-value mappings.
|
|
1303
|
+
*
|
|
1304
|
+
* @return `true` if this map contains no key-value mappings
|
|
1305
|
+
*/
|
|
1306
|
+
isEmpty(): boolean;
|
|
1307
|
+
/**
|
|
1308
|
+
* Returns `true` if this map contains a mapping for the specified
|
|
1309
|
+
* key. More formally, returns `true` if and only if
|
|
1310
|
+
* this map contains a mapping for a key `k` such that
|
|
1311
|
+
* `Objects.equals(key, k)`. (There can be
|
|
1312
|
+
* at most one such mapping.)
|
|
1313
|
+
*
|
|
1314
|
+
* @param key key whose presence in this map is to be tested
|
|
1315
|
+
* @return `true` if this map contains a mapping for the specified
|
|
1316
|
+
* key
|
|
1317
|
+
* @throws ClassCastException if the key is of an inappropriate type for
|
|
1318
|
+
* this map
|
|
1319
|
+
* (optional)
|
|
1320
|
+
* @throws NullPointerException if the specified key is null and this map
|
|
1321
|
+
* does not permit null keys
|
|
1322
|
+
* (optional)
|
|
1323
|
+
*/
|
|
1324
|
+
containsKey(key: any): boolean;
|
|
1325
|
+
/**
|
|
1326
|
+
* Returns the value to which the specified key is mapped,
|
|
1327
|
+
* or `null` if this map contains no mapping for the key.
|
|
1328
|
+
*
|
|
1329
|
+
* More formally, if this map contains a mapping from a key
|
|
1330
|
+
* `k` to a value `v` such that
|
|
1331
|
+
* `Objects.equals(key, k)`,
|
|
1332
|
+
* then this method returns `v`; otherwise
|
|
1333
|
+
* it returns `null`. (There can be at most one such mapping.)
|
|
1334
|
+
*
|
|
1335
|
+
* If this map permits null values, then a return value of
|
|
1336
|
+
* `null` does not necessarily indicate that the map
|
|
1337
|
+
* contains no mapping for the key; it's also possible that the map
|
|
1338
|
+
* explicitly maps the key to `null`. The {@link #containsKey
|
|
1339
|
+
* containsKey} operation may be used to distinguish these two cases.
|
|
1340
|
+
*
|
|
1341
|
+
* @param key the key whose associated value is to be returned
|
|
1342
|
+
* @return the value to which the specified key is mapped, or
|
|
1343
|
+
* `null` if this map contains no mapping for the key
|
|
1344
|
+
* @throws ClassCastException if the key is of an inappropriate type for
|
|
1345
|
+
* this map
|
|
1346
|
+
* (optional)
|
|
1347
|
+
* @throws NullPointerException if the specified key is null and this map
|
|
1348
|
+
* does not permit null keys
|
|
1349
|
+
* (optional)
|
|
1350
|
+
*/
|
|
1351
|
+
get(key: any): V;
|
|
1352
|
+
/**
|
|
1353
|
+
* Associates the specified value with the specified key in this map
|
|
1354
|
+
* (optional operation). If the map previously contained a mapping for
|
|
1355
|
+
* the key, the old value is replaced by the specified value. (A map
|
|
1356
|
+
* `m` is said to contain a mapping for a key `k` if and only
|
|
1357
|
+
* if {@link #containsKey(Object) m.containsKey(k)} would return
|
|
1358
|
+
* `true`.)
|
|
1359
|
+
*
|
|
1360
|
+
* @param key key with which the specified value is to be associated
|
|
1361
|
+
* @param value value to be associated with the specified key
|
|
1362
|
+
* @return the previous value associated with `key`, or
|
|
1363
|
+
* `null` if there was no mapping for `key`.
|
|
1364
|
+
* (A `null` return can also indicate that the map
|
|
1365
|
+
* previously associated `null` with `key`,
|
|
1366
|
+
* if the implementation supports `null` values.)
|
|
1367
|
+
* @throws UnsupportedOperationException if the `put` operation
|
|
1368
|
+
* is not supported by this map
|
|
1369
|
+
* @throws ClassCastException if the class of the specified key or value
|
|
1370
|
+
* prevents it from being stored in this map
|
|
1371
|
+
* @throws NullPointerException if the specified key or value is null
|
|
1372
|
+
* and this map does not permit null keys or values
|
|
1373
|
+
* @throws IllegalArgumentException if some property of the specified key
|
|
1374
|
+
* or value prevents it from being stored in this map
|
|
1375
|
+
*/
|
|
1376
|
+
put(key: K, value: V): V;
|
|
1377
|
+
/**
|
|
1378
|
+
* Copies all of the mappings from the specified map to this map
|
|
1379
|
+
* (optional operation). The effect of this call is equivalent to that
|
|
1380
|
+
* of calling {@link #put(Object,Object) put(k, v)} on this map once
|
|
1381
|
+
* for each mapping from key `k` to value `v` in the
|
|
1382
|
+
* specified map. The behavior of this operation is undefined if the
|
|
1383
|
+
* specified map is modified while the operation is in progress.
|
|
1384
|
+
*
|
|
1385
|
+
* @param m mappings to be stored in this map
|
|
1386
|
+
* @throws UnsupportedOperationException if the `putAll` operation
|
|
1387
|
+
* is not supported by this map
|
|
1388
|
+
* @throws ClassCastException if the class of a key or value in the
|
|
1389
|
+
* specified map prevents it from being stored in this map
|
|
1390
|
+
* @throws NullPointerException if the specified map is null, or if
|
|
1391
|
+
* this map does not permit null keys or values, and the
|
|
1392
|
+
* specified map contains null keys or values
|
|
1393
|
+
* @throws IllegalArgumentException if some property of a key or value in
|
|
1394
|
+
* the specified map prevents it from being stored in this map
|
|
1395
|
+
*/
|
|
1396
|
+
putAll(m: Map<K, V>): void;
|
|
1397
|
+
/**
|
|
1398
|
+
* Returns the value to which the specified key is mapped, or
|
|
1399
|
+
* `defaultValue` if this map contains no mapping for the key.
|
|
1400
|
+
*
|
|
1401
|
+
* @implSpec
|
|
1402
|
+
* The default implementation makes no guarantees about synchronization
|
|
1403
|
+
* or atomicity properties of this method. Any implementation providing
|
|
1404
|
+
* atomicity guarantees must override this method and document its
|
|
1405
|
+
* concurrency properties.
|
|
1406
|
+
*
|
|
1407
|
+
* @param key the key whose associated value is to be returned
|
|
1408
|
+
* @param defaultValue the default mapping of the key
|
|
1409
|
+
* @return the value to which the specified key is mapped, or
|
|
1410
|
+
* `defaultValue` if this map contains no mapping for the key
|
|
1411
|
+
* @throws ClassCastException if the key is of an inappropriate type for
|
|
1412
|
+
* this map
|
|
1413
|
+
* (optional)
|
|
1414
|
+
* @throws NullPointerException if the specified key is null and this map
|
|
1415
|
+
* does not permit null keys
|
|
1416
|
+
* (optional)
|
|
1417
|
+
* @since 1.8
|
|
1418
|
+
*/
|
|
1419
|
+
getOrDefault(key: any, defaultValue: V): V;
|
|
1420
|
+
/**
|
|
1421
|
+
* If the specified key is not already associated with a value (or is mapped
|
|
1422
|
+
* to `null`) associates it with the given value and returns
|
|
1423
|
+
* `null`, else returns the current value.
|
|
1424
|
+
*
|
|
1425
|
+
* @implSpec
|
|
1426
|
+
* The default implementation is equivalent to, for this ` * map`:
|
|
1427
|
+
*
|
|
1428
|
+
* {@code
|
|
1429
|
+
* V v = map.get(key);
|
|
1430
|
+
* if (v == null)
|
|
1431
|
+
* v = map.put(key, value);
|
|
1432
|
+
*
|
|
1433
|
+
* return v;
|
|
1434
|
+
* }
|
|
1435
|
+
*
|
|
1436
|
+
* The default implementation makes no guarantees about synchronization
|
|
1437
|
+
* or atomicity properties of this method. Any implementation providing
|
|
1438
|
+
* atomicity guarantees must override this method and document its
|
|
1439
|
+
* concurrency properties.
|
|
1440
|
+
*
|
|
1441
|
+
* @param key key with which the specified value is to be associated
|
|
1442
|
+
* @param value value to be associated with the specified key
|
|
1443
|
+
* @return the previous value associated with the specified key, or
|
|
1444
|
+
* `null` if there was no mapping for the key.
|
|
1445
|
+
* (A `null` return can also indicate that the map
|
|
1446
|
+
* previously associated `null` with the key,
|
|
1447
|
+
* if the implementation supports null values.)
|
|
1448
|
+
* @throws UnsupportedOperationException if the `put` operation
|
|
1449
|
+
* is not supported by this map
|
|
1450
|
+
* (optional)
|
|
1451
|
+
* @throws ClassCastException if the key or value is of an inappropriate
|
|
1452
|
+
* type for this map
|
|
1453
|
+
* (optional)
|
|
1454
|
+
* @throws NullPointerException if the specified key or value is null,
|
|
1455
|
+
* and this map does not permit null keys or values
|
|
1456
|
+
* (optional)
|
|
1457
|
+
* @throws IllegalArgumentException if some property of the specified key
|
|
1458
|
+
* or value prevents it from being stored in this map
|
|
1459
|
+
* (optional)
|
|
1460
|
+
* @since 1.8
|
|
1461
|
+
*/
|
|
1462
|
+
putIfAbsent(key: K, value: V): V;
|
|
1463
|
+
}
|
|
1464
|
+
export class Set<E> {
|
|
1465
|
+
/**
|
|
1466
|
+
* Returns the number of elements in this set (its cardinality). If this
|
|
1467
|
+
* set contains more than `Integer.MAX_VALUE` elements, returns
|
|
1468
|
+
* `Integer.MAX_VALUE`.
|
|
1469
|
+
*
|
|
1470
|
+
* @return the number of elements in this set (its cardinality)
|
|
1471
|
+
*/
|
|
1472
|
+
size(): number;
|
|
1473
|
+
/**
|
|
1474
|
+
* Returns `true` if this set contains no elements.
|
|
1475
|
+
*
|
|
1476
|
+
* @return `true` if this set contains no elements
|
|
1477
|
+
*/
|
|
1478
|
+
isEmpty(): boolean;
|
|
1479
|
+
/**
|
|
1480
|
+
* Returns `true` if this set contains the specified element.
|
|
1481
|
+
* More formally, returns `true` if and only if this set
|
|
1482
|
+
* contains an element `e` such that
|
|
1483
|
+
* `Objects.equals(o, e)`.
|
|
1484
|
+
*
|
|
1485
|
+
* @param o element whose presence in this set is to be tested
|
|
1486
|
+
* @return `true` if this set contains the specified element
|
|
1487
|
+
* @throws ClassCastException if the type of the specified element
|
|
1488
|
+
* is incompatible with this set
|
|
1489
|
+
* (optional)
|
|
1490
|
+
* @throws NullPointerException if the specified element is null and this
|
|
1491
|
+
* set does not permit null elements
|
|
1492
|
+
* (optional)
|
|
1493
|
+
*/
|
|
1494
|
+
contains(o: any): boolean;
|
|
1495
|
+
/**
|
|
1496
|
+
* Returns an iterator over the elements in this set. The elements are
|
|
1497
|
+
* returned in no particular order (unless this set is an instance of some
|
|
1498
|
+
* class that provides a guarantee).
|
|
1499
|
+
*
|
|
1500
|
+
* @return an iterator over the elements in this set
|
|
1501
|
+
*/
|
|
1502
|
+
iterator(): Iterator<E>;
|
|
1503
|
+
/**
|
|
1504
|
+
* Adds the specified element to this set if it is not already present
|
|
1505
|
+
* (optional operation). More formally, adds the specified element
|
|
1506
|
+
* `e` to this set if the set contains no element `e2`
|
|
1507
|
+
* such that
|
|
1508
|
+
* `Objects.equals(e, e2)`.
|
|
1509
|
+
* If this set already contains the element, the call leaves the set
|
|
1510
|
+
* unchanged and returns `false`. In combination with the
|
|
1511
|
+
* restriction on constructors, this ensures that sets never contain
|
|
1512
|
+
* duplicate elements.
|
|
1513
|
+
*
|
|
1514
|
+
* The stipulation above does not imply that sets must accept all
|
|
1515
|
+
* elements; sets may refuse to add any particular element, including
|
|
1516
|
+
* `null`, and throw an exception, as described in the
|
|
1517
|
+
* specification for {@link Collection#add Collection.add}.
|
|
1518
|
+
* Individual set implementations should clearly document any
|
|
1519
|
+
* restrictions on the elements that they may contain.
|
|
1520
|
+
*
|
|
1521
|
+
* @param e element to be added to this set
|
|
1522
|
+
* @return `true` if this set did not already contain the specified
|
|
1523
|
+
* element
|
|
1524
|
+
* @throws UnsupportedOperationException if the `add` operation
|
|
1525
|
+
* is not supported by this set
|
|
1526
|
+
* @throws ClassCastException if the class of the specified element
|
|
1527
|
+
* prevents it from being added to this set
|
|
1528
|
+
* @throws NullPointerException if the specified element is null and this
|
|
1529
|
+
* set does not permit null elements
|
|
1530
|
+
* @throws IllegalArgumentException if some property of the specified element
|
|
1531
|
+
* prevents it from being added to this set
|
|
1532
|
+
*/
|
|
1533
|
+
add(e: E): boolean;
|
|
1534
|
+
}
|
|
1535
|
+
|
|
1536
|
+
}
|