public class LocalePriorityList extends Object implements Iterable<ULocale>
In theory, Accept-Language indicates the relative 'quality' of each item, but in practice, all of the browsers just take an ordered list, like "en, fr, de", and synthesize arbitrary quality values that put these in the right order, like: "en, fr;q=0.7, de;q=0.3". The quality values in these de facto semantics thus have nothing to do with the relative qualities of the original. Accept-Language also doesn't specify the interpretation of multiple instances, eg what "en, fr, en;q=.5" means.
There are various ways to build a LanguagePriorityList, such as using the following equivalent patterns:
list = LanguagePriorityList.add("af, en, fr;q=0.9").build();
list2 = LanguagePriorityList
.add(ULocale.forString("af"))
.add(ULocale.ENGLISH)
.add(ULocale.FRENCH, 0.9d)
.build();
When the list is built, the internal values are sorted in descending order by
weight, and then by input order. That is, if two languages have the same weight, the first one in the original order
comes first. If exactly the same language tag appears multiple times,
the last one wins.
There are two options when building. If preserveWeights are on, then "de;q=0.3, ja;q=0.3, en, fr;q=0.7, de " would result in the following:
en;q=1.0 de;q=1.0 fr;q=0.7 ja;q=0.3If it is off (the default), then all weights are reset to 1.0 after reordering. This is to match the effect of the Accept-Language semantics as used in browsers, and results in the following: *
en;q=1.0 de;q=1.0 fr;q=1.0 ja;q=1.0
| Modifier and Type | Class and Description |
|---|---|
static class |
LocalePriorityList.Builder
Class used for building LanguagePriorityLists
|
| Modifier and Type | Method and Description |
|---|---|
static LocalePriorityList.Builder |
add(LocalePriorityList languagePriorityList)
Add a language priority list.
|
static LocalePriorityList.Builder |
add(String acceptLanguageString)
Add language codes to the list being built, using a string in rfc2616
(lenient) format, where each language is a valid
ULocale. |
static LocalePriorityList.Builder |
add(ULocale... languageCode)
Add a language code to the list being built, with weight 1.0.
|
static LocalePriorityList.Builder |
add(ULocale languageCode,
double weight)
Add a language code to the list being built, with specified weight.
|
boolean |
equals(Object o)
Compares this instance with the specified object and indicates if they
are equal.
|
Double |
getWeight(ULocale language)
Return the weight for a given language, or null if there is none.
|
int |
hashCode()
Returns an integer hash code for this object.
|
Iterator<ULocale> |
iterator()
Returns an iterator over elements of type
T. |
String |
toString()
Returns a string containing a concise, human-readable description of this
object.
|
clone, finalize, getClass, notify, notifyAll, wait, wait, waitforEach, spliteratorpublic static LocalePriorityList.Builder add(ULocale... languageCode)
languageCode - locale/language to be addedpublic static LocalePriorityList.Builder add(ULocale languageCode, double weight)
languageCode - locale/language to be addedweight - value from 0.0 to 1.0public static LocalePriorityList.Builder add(LocalePriorityList languagePriorityList)
languagePriorityList - list to add all the members ofpublic static LocalePriorityList.Builder add(String acceptLanguageString)
ULocale.acceptLanguageString - String in rfc2616 format (but leniently parsed)public Double getWeight(ULocale language)
language - to get weight ofpublic String toString()
getClass().getName() + '@' + Integer.toHexString(hashCode())
See Writing a useful
toString method
if you intend implementing your own toString method.
public boolean equals(Object o)
o must represent the same object
as this instance using a class-specific comparison. The general contract
is that this comparison should be reflexive, symmetric, and transitive.
Also, no object reference other than null is equal to null.
The default implementation returns true only if this ==
o. See Writing a correct
equals method
if you intend implementing your own equals method.
The general contract for the equals and Object.hashCode() methods is that if equals returns true for
any two objects, then hashCode() must return the same value for
these objects. This means that subclasses of Object usually
override either both methods or neither of them.
equals in class Objecto - the object to compare this instance with.true if the specified object is equal to this Object; false otherwise.Object.hashCode()public int hashCode()
Object.equals(java.lang.Object) returns true must return
the same hash code value. This means that subclasses of Object
usually override both methods or neither method.
Note that hash values must not change over time unless information used in equals comparisons also changes.
See Writing a correct
hashCode method
if you intend implementing your own hashCode method.
hashCode in class ObjectObject.equals(java.lang.Object)