diff options
| author | 2020-09-09 20:33:10 +0000 | |
|---|---|---|
| committer | 2020-09-09 20:33:10 +0000 | |
| commit | 8b4cd9aef3b12dddf158bf2c6fdc2781236e2bc1 (patch) | |
| tree | 228c02b3d342300a7424d1d522695ef0a6a4472b | |
| parent | dfc8abb1ffc7bf6c7d7b47cf2e9e14bf6422f95c (diff) | |
| parent | 41b1674f775c9b3d941f78525dcfc804ef2e047a (diff) | |
Accept repeated locale as an input of LocaleList construction. am: 41b1674f77
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/12540040
Change-Id: I69509d7ddadb1787f56ce31f0ff2fb617537b2ce
| -rw-r--r-- | core/java/android/os/LocaleList.java | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/core/java/android/os/LocaleList.java b/core/java/android/os/LocaleList.java index ab4bb0b9f2cd..9c0bc45a346e 100644 --- a/core/java/android/os/LocaleList.java +++ b/core/java/android/os/LocaleList.java @@ -25,6 +25,7 @@ import android.icu.util.ULocale; import com.android.internal.annotations.GuardedBy; +import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.HashSet; @@ -151,18 +152,18 @@ public final class LocaleList implements Parcelable { /** * Creates a new {@link LocaleList}. * + * If two or more same locales are passed, the repeated locales will be dropped. * <p>For empty lists of {@link Locale} items it is better to use {@link #getEmptyLocaleList()}, * which returns a pre-constructed empty list.</p> * * @throws NullPointerException if any of the input locales is <code>null</code>. - * @throws IllegalArgumentException if any of the input locales repeat. */ public LocaleList(@NonNull Locale... list) { if (list.length == 0) { mList = sEmptyList; mStringRepresentation = ""; } else { - final Locale[] localeList = new Locale[list.length]; + final ArrayList<Locale> localeList = new ArrayList<>(); final HashSet<Locale> seenLocales = new HashSet<Locale>(); final StringBuilder sb = new StringBuilder(); for (int i = 0; i < list.length; i++) { @@ -170,10 +171,10 @@ public final class LocaleList implements Parcelable { if (l == null) { throw new NullPointerException("list[" + i + "] is null"); } else if (seenLocales.contains(l)) { - throw new IllegalArgumentException("list[" + i + "] is a repetition"); + // Dropping duplicated locale entries. } else { final Locale localeClone = (Locale) l.clone(); - localeList[i] = localeClone; + localeList.add(localeClone); sb.append(localeClone.toLanguageTag()); if (i < list.length - 1) { sb.append(','); @@ -181,7 +182,7 @@ public final class LocaleList implements Parcelable { seenLocales.add(localeClone); } } - mList = localeList; + mList = localeList.toArray(new Locale[localeList.size()]); mStringRepresentation = sb.toString(); } } |