Package org.apache.juneau.http.header
Class BasicMediaRangesHeader
java.lang.Object
org.apache.juneau.http.header.BasicHeader
org.apache.juneau.http.header.BasicStringHeader
org.apache.juneau.http.header.BasicMediaRangesHeader
- All Implemented Interfaces:
Serializable
,Cloneable
,Header
,NameValuePair
- Direct Known Subclasses:
Accept
Category of headers that consist of multiple parameterized string values.
Example
Accept: application/json;q=0.9,text/xml;q=0.1
See Also:
-
Constructor Summary
ConstructorDescriptionBasicMediaRangesHeader
(String name, String value) Constructor.BasicMediaRangesHeader
(String name, Supplier<MediaRanges> value) Constructor with delayed value.BasicMediaRangesHeader
(String name, MediaRanges value) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionReturns the header value as aMediaRanges
wrapped in anOptional
.getRange
(int index) Returns theMediaRange
at the specified index.getValue()
boolean
hasSubtypePart
(String part) Convenience method for searching through all of the subtypes of all the media ranges in this header for the presence of a subtype fragment.int
Given a list of media types, returns the best match for thisAccept header.static BasicMediaRangesHeader
Static creator.static BasicMediaRangesHeader
of
(String name, MediaRanges value) Static creator.orElse
(MediaRanges other) Return the value if present, otherwise returnother .Returns the header value as aMediaRanges
.Methods inherited from class org.apache.juneau.http.header.BasicStringHeader
assertString, asString, of, ofPair, orElse
Methods inherited from class org.apache.juneau.http.header.BasicHeader
assertName, assertStringValue, equals, equalsIgnoreCase, get, getElements, getName, hashCode, isNotEmpty, isPresent, of, of, toString
-
Constructor Details
-
BasicMediaRangesHeader
Constructor.- Parameters:
name
- The header name.value
- The header value.
Must be parsable byMediaRanges.of(String)
.
Can benull .- Throws:
IllegalArgumentException
- If name isnull or empty.
-
BasicMediaRangesHeader
Constructor.- Parameters:
name
- The header name.value
- The header value.
Can benull .- Throws:
IllegalArgumentException
- If name isnull or empty.
-
BasicMediaRangesHeader
Constructor with delayed value.Header value is re-evaluated on each call to
getValue()
.- Parameters:
name
- The header name.value
- The supplier of the header value.
Can benull .- Throws:
IllegalArgumentException
- If name isnull or empty.
-
-
Method Details
-
of
Static creator.- Parameters:
name
- The header name.value
- The header value.
Must be parsable byMediaRanges.of(String)
.
Can benull .- Returns:
- A new header bean, or
null if the value isnull . - Throws:
IllegalArgumentException
- If name isnull or empty.
-
of
Static creator.- Parameters:
name
- The header name.value
- The header value.
Can benull .- Returns:
- A new header bean, or
null if the value isnull . - Throws:
IllegalArgumentException
- If name isnull or empty.
-
asMediaRanges
Returns the header value as aMediaRanges
wrapped in anOptional
.- Returns:
- The header value as a
MediaRanges
wrapped in anOptional
. Nevernull .
-
toMediaRanges
Returns the header value as aMediaRanges
.- Returns:
- The header value as a
MediaRanges
. Can benull .
-
match
Given a list of media types, returns the best match for thisAccept header.Note that fuzzy matching is allowed on the media types where the
Accept header may contain additional subtype parts.
For example, given identical q-values and anAccept value of"text/json+activity" , the media type"text/json" will match if"text/json+activity" or"text/activity+json" isn't found.
The purpose for this is to allow serializers to match when artifacts such asid properties are present in the header.- Parameters:
mediaTypes
- The media types to match against.- Returns:
- The index into the array of the best match, or
-1 if no suitable matches could be found.
-
getRange
Returns theMediaRange
at the specified index.- Parameters:
index
- The index position of the media range.- Returns:
- The
MediaRange
at the specified index ornull if the index is out of range.
-
hasSubtypePart
Convenience method for searching through all of the subtypes of all the media ranges in this header for the presence of a subtype fragment.For example, given the header
"text/json+activity" , callinghasSubtypePart(
returns"activity" )true .- Parameters:
part
- The media type subtype fragment.- Returns:
true if subtype fragment exists.
-
getValue
- Specified by:
getValue
in interfaceNameValuePair
- Overrides:
getValue
in classBasicStringHeader
-
orElse
Return the value if present, otherwise returnother .This is a shortened form for calling
asMediaRanges().orElse( .other )- Parameters:
other
- The value to be returned if there is no value present, can benull .- Returns:
- The value, if present, otherwise
other .
-