Class MediaRangeList
- All Implemented Interfaces:
Serializable
,Cloneable
,Iterable<MediaRangeList.MediaRange>
,Collection<MediaRangeList.MediaRange>
,NavigableSet<MediaRangeList.MediaRange>
,Set<MediaRangeList.MediaRange>
,SortedSet<MediaRangeList.MediaRange>
Facilitates parsing of the Accept HTTP request header.
See RFC 2616 section 14.1
- See Also:
-
Nested Class Summary
Modifier and TypeClassDescriptionclass
A codeMediaRange
represents an entry in aMediaRangeList
. -
Field Summary
-
Constructor Summary
ConstructorDescriptionMediaRangeList
(String listStr) Constructs aMediaRangeList
using a list of media ranges specified in ajava.lang.String
.MediaRangeList
(javax.servlet.http.HttpServletRequest request) Constructs aMediaRangeList
using information from the suppliedHttpServletRequest
. -
Method Summary
Modifier and TypeMethodDescriptionboolean
Determines if this MediaRangeList contains a given media type.Determines which of themediaRanges
specifications is preferred by thisMediaRangeList
.prefer
(Set<MediaRangeList.MediaRange> mediaRanges) Given a list of media types, returns the one is preferred by thisMediaRangeList
.Methods inherited from class java.util.TreeSet
add, addAll, ceiling, clear, clone, comparator, contains, descendingIterator, descendingSet, first, floor, headSet, headSet, higher, isEmpty, iterator, last, lower, pollFirst, pollLast, remove, size, spliterator, subSet, subSet, tailSet, tailSet
Methods inherited from class java.util.AbstractSet
equals, hashCode, removeAll
Methods inherited from class java.util.AbstractCollection
containsAll, retainAll, toArray, toArray, toString
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArray
-
Field Details
-
HEADER_ACCEPT
- See Also:
-
PARAM_ACCEPT
- See Also:
-
WILDCARD
- See Also:
-
-
Constructor Details
-
MediaRangeList
public MediaRangeList(javax.servlet.http.HttpServletRequest request) Constructs aMediaRangeList
using information from the suppliedHttpServletRequest
. if the request contains aPARAM_ACCEPT
query parameter, the query parameter value overrides anyHEADER_ACCEPT
header value. If the request contains noPARAM_ACCEPT
parameter, or the parameter value is empty, the value of theHEADER_ACCEPT
is used. If both values are missing, it is assumed that the client accepts all media types, as per the RFC. See alsoMediaRangeList(java.lang.String)
- Parameters:
request
- TheHttpServletRequest
to extract aMediaRangeList
from
-
MediaRangeList
Constructs aMediaRangeList
using a list of media ranges specified in ajava.lang.String
. The string is a comma-separated list of media ranges, as specified by the RFC.
Examples:text/*;q=0.3, text/html;q=0.7, text/html;level=1, text/html;level=2;q=0.4, */*;q=0.5
text/html;q=0.8, application/json
- Parameters:
listStr
- The list of media range specifications
-
-
Method Details
-
contains
Determines if this MediaRangeList contains a given media type.- Parameters:
mediaType
- A string on the formtype/subtype
. Neithertype
orsubtype
should be wildcard (*
).- Returns:
true
if thisMediaRangeList
contains a media type that matchesmediaType
,false
otherwise- Throws:
IllegalArgumentException
- ifmediaType
is not on an accepted formNullPointerException
- ifmediaType
isnull
-
prefer
Given a list of media types, returns the one is preferred by thisMediaRangeList
.- Parameters:
mediaRanges
- An array of possibleMediaRangeList.MediaRange
s- Returns:
- One of the
mediaRanges
that thisMediaRangeList
prefers; ornull
if thisMediaRangeList
does not contain any of themediaRanges
- Throws:
NullPointerException
- ifmediaRanges
isnull
or contains anull
value
-
prefer
Determines which of themediaRanges
specifications is preferred by thisMediaRangeList
.- Parameters:
mediaRanges
- String representations ofMediaRange
s. The strings must be on the form required byMediaRange(String)
- Returns:
- the
toString()
representation of the preferredMediaRange
, ornull
if thisMediaRangeList
does not contain any of themediaRanges
- See Also:
-