Interface Headers.AcceptLanguage.LanguageRange
- Enclosing interface:
Headers.AcceptLanguage
Accept language HTTP header language range as defined by RFC 7231 Section 5.3.5.
- Since:
- 1.0
- Author:
- Jeremy Kuhn
-
Field Summary
Modifier and TypeFieldDescriptionstatic final Comparator
<Headers.AcceptLanguage.LanguageRange> The language range comparator based on language range scores. -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> Optional
<Headers.AcceptMatch<T, Headers.AcceptLanguage.LanguageRange>> findFirstMatch
(Headers.AcceptLanguage.LanguageRange languageRange, Collection<T> items, Function<T, Headers.AcceptLanguage.LanguageRange> languageRangeExtractor) Returns the first item in the specified collection whose language range matches the specified language range.static Optional
<Headers.AcceptMatch<Headers.AcceptLanguage.LanguageRange, Headers.AcceptLanguage.LanguageRange>> findFirstMatch
(Headers.AcceptLanguage.LanguageRange languageRange, List<Headers.AcceptLanguage.LanguageRange> languageRanges) Returns the first language range in the specified list that matches the specified language range.Returns the language range tag.Returns the language range primary sub-tag.default int
getScore()
Calculates and returns the score or the language range used for sorting.Returns the language range secondary sub-tag.float
Returns the language range quality value as defined by RFC 7231 Section 5.3.1.default boolean
matches
(Headers.AcceptLanguage.LanguageRange languageRange) Determines whether the specified language range matches the language range.
-
Field Details
-
COMPARATOR
The language range comparator based on language range scores.
-
-
Method Details
-
getLanguageTag
String getLanguageTag()Returns the language range tag.
- Returns:
- the language range tag
-
getPrimarySubTag
String getPrimarySubTag()Returns the language range primary sub-tag.
- Returns:
- the language range primary sub-tag
-
getSecondarySubTag
String getSecondarySubTag()Returns the language range secondary sub-tag.
- Returns:
- the language range secondary sub-tag
-
getWeight
float getWeight()Returns the language range quality value as defined by RFC 7231 Section 5.3.1.
- Returns:
- the language range quality value
-
matches
Determines whether the specified language range matches the language range.
- Parameters:
languageRange
- the language range to test- Returns:
- true if the language range matches the range, false otherwise
-
getScore
default int getScore()Calculates and returns the score or the language range used for sorting.
The score is calculated by assigning a score to the media range part and add all:
- the range quality value is multiplied by 1000
- * is worth 0
- xx is worth 10
- xx-xx is worth 20
- Returns:
- the score of the language range
-
findFirstMatch
static Optional<Headers.AcceptMatch<Headers.AcceptLanguage.LanguageRange,Headers.AcceptLanguage.LanguageRange>> findFirstMatch(Headers.AcceptLanguage.LanguageRange languageRange, List<Headers.AcceptLanguage.LanguageRange> languageRanges) Returns the first language range in the specified list that matches the specified language range.
- Parameters:
languageRange
- a language rangelanguageRanges
- a list of language ranges- Returns:
- an optional returning the first match or an empty optional if no match was found
-
findFirstMatch
static <T> Optional<Headers.AcceptMatch<T,Headers.AcceptLanguage.LanguageRange>> findFirstMatch(Headers.AcceptLanguage.LanguageRange languageRange, Collection<T> items, Function<T, Headers.AcceptLanguage.LanguageRange> languageRangeExtractor) Returns the first item in the specified collection whose language range matches the specified language range.
- Type Parameters:
T
- the type of the item- Parameters:
languageRange
- a language rangeitems
- a collection of itemslanguageRangeExtractor
- a function that extracts the language range of an item- Returns:
- an optional returning the first match or an empty optional if no match was found
-