Module io.inverno.mod.http.base
Package io.inverno.mod.http.base.header
Interface Headers.Accept.MediaRange
- Enclosing interface:
Headers.Accept
public static interface Headers.Accept.MediaRange
Accept HTTP header media range as defined by RFC 7231 Section 5.3.2.
- Since:
- 1.0
- Author:
- Jeremy Kuhn
-
Field Summary
Modifier and TypeFieldDescriptionstatic final Comparator
<Headers.Accept.MediaRange> The media range comparator based on media range scores. -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> Optional
<Headers.AcceptMatch<T, Headers.ContentType>> findFirstMatch
(Headers.ContentType contentType, Collection<T> items, Function<T, Headers.Accept.MediaRange> mediaRangeExtractor) Returns the first item in the specified collection whose media range matches the specified content type.findFirstMatch
(Headers.ContentType contentType, List<Headers.Accept.MediaRange> mediaRanges) Returns the first media range in the specified list that matches the specified content type.Returns the media range raw value.Returns media range parameters.default int
getScore()
Calculates and returns the score or the media range used for sorting.Returns the media range sub-type.getType()
Returns the media range type.float
Returns the media range quality value as defined by RFC 7231 Section 5.3.1.default boolean
matches
(Headers.ContentType contentType) Determines whether the specified content type matches the media range.
-
Field Details
-
COMPARATOR
The media range comparator based on media range scores.
-
-
Method Details
-
getMediaType
String getMediaType()Returns the media range raw value.
- Returns:
- the raw media range
-
getType
String getType()Returns the media range type.
- Returns:
- the media range type
-
getSubType
String getSubType()Returns the media range sub-type.
- Returns:
- the media range sub-type
-
getWeight
float getWeight()Returns the media range quality value as defined by RFC 7231 Section 5.3.1.
- Returns:
- the media range quality value
-
getParameters
Returns media range parameters.
- Returns:
- the media range parameters
-
matches
Determines whether the specified content type matches the media range.
- Parameters:
contentType
- the content type to test- Returns:
- true if the content type matches the range, false otherwise
-
getScore
default int getScore()Calculates and returns the score or the media 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
- */x is worth 10
- x/* is worth 20
- x/x is worth 30
- a null parameter is worth 1
- a non-null parameter is worth 2
- Returns:
- the score of the media range
-
findFirstMatch
static Optional<Headers.AcceptMatch<Headers.Accept.MediaRange,Headers.ContentType>> findFirstMatch(Headers.ContentType contentType, List<Headers.Accept.MediaRange> mediaRanges) Returns the first media range in the specified list that matches the specified content type.
- Parameters:
contentType
- a content typemediaRanges
- a list of media 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.ContentType>> findFirstMatch(Headers.ContentType contentType, Collection<T> items, Function<T, Headers.Accept.MediaRange> mediaRangeExtractor) Returns the first item in the specified collection whose media range matches the specified content type.
- Type Parameters:
T
- the type of the item- Parameters:
contentType
- a content typeitems
- a collection of itemsmediaRangeExtractor
- a function that extracts the media type of an item- Returns:
- an optional returning the first match or an empty optional if no match was found
-