public final class LocaleList
extends Object implements Parcelable
| java.lang.Object | |
| android.os.LocaleList | |
LocaleList是Locales的一个不可变列表,通常用于保持语言环境的用户首选项的有序列表。
Inherited constants |
|---|
android.os.Parcelable
|
Fields |
|
|---|---|
public static final Creator<LocaleList> |
CREATOR |
Public constructors |
|
|---|---|
LocaleList(Locale... list) 创建一个新的 |
|
公共方法(Public methods) |
|
|---|---|
int |
describeContents() 描述此Parcelable实例的封送表示中包含的特殊对象的种类。 |
boolean |
equals(Object other) 指示其他某个对象是否“等于”这一个。 |
static LocaleList |
forLanguageTags(String list) 用给定的语言标签生成一个新的LocaleList。 |
Locale |
get(int index) 检索指定索引处的 |
static LocaleList |
getAdjustedDefault() 返回默认语言环境列表,通过将默认语言环境移动到其第一个位置进行调整。 |
static LocaleList |
getDefault() 结果保证包含由Locale.getDefault()返回的默认Locale,但不一定在列表顶部。 |
static LocaleList |
getEmptyLocaleList() 检索一个 |
Locale |
getFirstMatch(String[] supportedLocales) 给定BCP 47格式的受支持语言环境的无序数组,返回区域设置列表中的第一个匹配项。 |
int |
hashCode() 返回对象的哈希码值。 |
int |
indexOf(Locale locale) 搜索这 |
boolean |
isEmpty() 返回 |
static void |
setDefault(LocaleList locales) 还通过调用Locale.setDefault()和列表中的第一个语言环境来设置默认语言环境。 |
int |
size() 返回的数量 |
String |
toLanguageTags() 检索此列表中语言标记的字符串表示形式。 |
String |
toString() 返回对象的字符串表示形式。 |
void |
writeToParcel(Parcel dest, int parcelableFlags) 将此对象平铺到一个包裹中。 |
继承方法(Inherited methods) |
|
|---|---|
java.lang.Object
|
|
android.os.Parcelable
|
|
LocaleList (Locale... list)
创建一个新的 LocaleList 。
对于 Locale项目的空列表,最好使用 getEmptyLocaleList() ,它返回一个预先构建的空列表。
| 参数(Parameters) | |
|---|---|
list |
Locale
|
| 抛出异常(Throws) | |
|---|---|
NullPointerException |
if any of the input locales is null. |
IllegalArgumentException |
if any of the input locales repeat. |
int describeContents ()
描述此Parcelable实例的封送表示中包含的特殊对象的种类。 例如,如果对象将在writeToParcel(Parcel, int)的输出中包含writeToParcel(Parcel, int) ,则此方法的返回值必须包含CONTENTS_FILE_DESCRIPTOR位。
| 返回(Returns) | |
|---|---|
int |
a bitmask indicating the set of special object types marshaled by this Parcelable object instance. |
boolean equals (Object other)
指示其他某个对象是否“等于”这一个。
equals方法在非空对象引用上实现等价关系:
x, x.equals(x) should return true. x and y, x.equals(y) should return true if and only if y.equals(x) returns true. x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true. x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified. x, x.equals(null) should return false. 类Object的equals方法实现了对象上最可能的等价关系; 也就是说,对于任何非空参考值x和y ,当且仅当x和y引用同一对象( x == y的值为true )时,此方法返回true 。
请注意,无论何时覆盖此方法,通常都必须覆盖 hashCode方法,以维护 hashCode方法的常规协定,该 hashCode声明相等对象必须具有相同的哈希代码。
| 参数(Parameters) | |
|---|---|
other |
Object: the reference object with which to compare. |
| 返回(Returns) | |
|---|---|
boolean |
true if this object is the same as the obj argument; false otherwise. |
LocaleList forLanguageTags (String list)
用给定的语言标签生成一个新的LocaleList。
| 参数(Parameters) | |
|---|---|
list |
String: The language tags to be included as a single String separated by commas. |
| 返回(Returns) | |
|---|---|
LocaleList |
A new instance with the Locale items identified by the given tags. |
Locale get (int index)
检索指定索引处的 Locale 。
| 参数(Parameters) | |
|---|---|
index |
int: The position to retrieve. |
| 返回(Returns) | |
|---|---|
Locale |
The Locale in the given index. |
LocaleList getAdjustedDefault ()
返回默认语言环境列表,通过将默认语言环境移动到其第一个位置进行调整。
| 返回(Returns) | |
|---|---|
LocaleList |
|
LocaleList getDefault ()
结果保证包含由Locale.getDefault()返回的默认Locale,但不一定在列表顶部。 不在列表顶部的默认语言环境表示系统已将默认语言环境设置为用户的其他首选语言环境之一,并得出结论认为主要首选项不受支持,但次要首选项为。
请注意,如果调用Locale.setDefault(),默认的LocaleList将会更改。 此方法通过始终检查Locale.getDefault()的输出并在需要时重新计算默认的LocaleList来考虑这一点。
| 返回(Returns) | |
|---|---|
LocaleList |
|
LocaleList getEmptyLocaleList ()
检索 LocaleList的空实例。
| 返回(Returns) | |
|---|---|
LocaleList |
|
Locale getFirstMatch (String[] supportedLocales)
给定BCP 47格式的受支持语言环境的无序数组,返回区域设置列表中的第一个匹配项。
| 参数(Parameters) | |
|---|---|
supportedLocales |
String
|
| 返回(Returns) | |
|---|---|
Locale |
The first Locale from this list that appears in the given array, or null if the LocaleList is empty. |
int hashCode ()
返回对象的哈希码值。 这种方法支持散列表的好处,例如HashMap提供的HashMap 。
hashCode的总合同是:
hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application. equals(Object) method, then calling the hashCode method on each of the two objects must produce the same integer result. equals(java.lang.Object) method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables. 尽可能合理实用,类Object定义的hashCode方法确实为不同的对象返回不同的整数。 (这通常通过将对象的内部地址转换为整数来实现,但Java TM编程语言不需要此实现技术。)
| 返回(Returns) | |
|---|---|
int |
a hash code value for this object. |
int indexOf (Locale locale)
搜索这 LocaleList指定的 Locale并返回第一次出现的索引。
| 参数(Parameters) | |
|---|---|
locale |
Locale: The Locale to search for. |
| 返回(Returns) | |
|---|---|
int |
The index of the first occurrence of the Locale or -1 if the item wasn't found. |
boolean isEmpty ()
返回 LocaleList是否 LocaleList包含 Locale项目。
| 返回(Returns) | |
|---|---|
boolean |
true if this LocaleList has no Locale items, false otherwise. |
void setDefault (LocaleList locales)
还通过调用Locale.setDefault()和列表中的第一个语言环境来设置默认语言环境。
| 参数(Parameters) | |
|---|---|
locales |
LocaleList
|
| 抛出异常(Throws) | |
|---|---|
NullPointerException |
if the input is null. |
IllegalArgumentException |
if the input is empty. |
String toLanguageTags ()
检索此列表中语言标记的字符串表示形式。
| 返回(Returns) | |
|---|---|
String |
|
String toString ()
返回对象的字符串表示形式。 通常, toString方法返回一个“文本表示”此对象的字符串。 结果应该是一个简洁但内容丰富的表述,对于一个人来说很容易阅读。 建议所有子类重写此方法。
类Object的toString方法返回一个字符串,其中包含对象为实例的类的名称,符号字符“ @ ”以及对象的哈希代码的无符号十六进制表示形式。 换句话说,这个方法返回一个字符串,其值等于:
getClass().getName() + '@' + Integer.toHexString(hashCode())
| 返回(Returns) | |
|---|---|
String |
a string representation of the object. |
void writeToParcel (Parcel dest, int parcelableFlags)
将此对象平铺到一个包裹中。
| 参数(Parameters) | |
|---|---|
dest |
Parcel: The Parcel in which the object should be written. |
parcelableFlags |
int: Additional flags about how the object should be written. May be 0 or PARCELABLE_WRITE_RETURN_VALUE. |