8282319: java.util.Locale method to stream available Locales

Reviewed-by: stsypanov, naoto, lancea, rriggs
This commit is contained in:
Justin Lu 2023-03-01 00:36:22 +00:00 committed by Naoto Sato
parent 881517586d
commit 7e47d51e10
3 changed files with 115 additions and 3 deletions

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2005, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2005, 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
@ -38,6 +38,7 @@ import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.spi.LocaleServiceProvider;
import java.util.stream.Stream;
/**
* An instance of this class holds a set of the third party implementations of a particular
@ -138,7 +139,6 @@ public final class LocaleServiceProviderPool {
LocaleServiceProviderPool.getPool(c);
all.addAll(pool.getAvailableLocaleSet());
}
allAvailableLocales = all.toArray(new Locale[0]);
}
@ -147,6 +147,17 @@ public final class LocaleServiceProviderPool {
}
}
/**
* Returns a stream of the available locales for all the provider classes.
* This stream is constructed from all the locales
* that are provided by each provider, including the JRE.
*
* @return a stream of the available locales for all provider classes
*/
public static Stream<Locale> streamAllAvailableLocales() {
return Arrays.stream(AllAvailableLocales.allAvailableLocales);
}
/**
* Returns an array of available locales for all the provider classes.
* This array is a merged array of all the locales that are provided by each