mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-26 14:24:46 +02:00
8282319: java.util.Locale method to stream available Locales
Reviewed-by: stsypanov, naoto, lancea, rriggs
This commit is contained in:
parent
881517586d
commit
7e47d51e10
3 changed files with 115 additions and 3 deletions
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 1996, 2022, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1996, 2023, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
|
@ -48,6 +48,7 @@ import java.io.Serializable;
|
|||
import java.text.MessageFormat;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.spi.LocaleNameProvider;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import jdk.internal.vm.annotation.Stable;
|
||||
|
||||
|
@ -1210,6 +1211,24 @@ public final class Locale implements Cloneable, Serializable {
|
|||
return LocaleServiceProviderPool.getAllAvailableLocales();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a stream of all installed locales.
|
||||
* The returned stream represents the union of locales supported
|
||||
* by the Java runtime environment and by installed
|
||||
* {@link java.util.spi.LocaleServiceProvider LocaleServiceProvider}
|
||||
* implementations. At a minimum, the returned stream must contain a
|
||||
* {@code Locale} instance equal to {@link Locale#ROOT Locale.ROOT} and
|
||||
* a {@code Locale} instance equal to {@link Locale#US Locale.US}.
|
||||
*
|
||||
* @implNote Unlike {@code getAvailableLocales()}, this method does
|
||||
* not create a defensive copy of the Locale array.
|
||||
* @return A stream of installed locales.
|
||||
* @since 21
|
||||
*/
|
||||
public static Stream<Locale> availableLocales() {
|
||||
return LocaleServiceProviderPool.streamAllAvailableLocales();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of all 2-letter country codes defined in ISO 3166.
|
||||
* Can be used to obtain Locales.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue