java.util.Comparator<MediaType>public final class AcceptHeader extends java.lang.Object implements java.util.Comparator<MediaType>
Instances of this class implement a Comparator that represents the order of preference of media
types specified by an accept header. Note that this implementation of Comparator is inconsistent
with equals.
A static method is provided to straightforwardly determine given a particular set of available media types, which, if any, is most preferred by a given accept header.
| Constructor | Description |
|---|---|
AcceptHeader(java.lang.Iterable<java.lang.String> headers) |
Constructs an
AcceptHeader representing the normalised form of the given RFC 2616 accept header Strings. |
AcceptHeader(java.lang.String header) |
| Modifier and Type | Method | Description |
|---|---|---|
java.util.Collection<AcceptAllMediaRange> |
acceptAllMediaRanges() |
|
boolean |
accepts(MediaType mediaType) |
|
int |
compare(MediaType o1,
MediaType o2) |
|
java.util.Collection<FullySpecifiedMediaRange> |
fullySpecifiedMediaRanges() |
|
static java.util.List<MediaType> |
sortedByAcceptHeaderPreference(java.lang.Iterable<java.lang.String> acceptHeaders,
java.lang.Iterable<MediaType> availableMediaTypes) |
Determines which of the given
MediaTypes satisfy the given accept header Strings, and the order of preference defined by those Strings. |
static java.util.List<MediaType> |
sortedByAcceptHeaderPreference(java.lang.String acceptHeader,
java.lang.Iterable<MediaType> availableMediaTypes) |
Determines which of the given
MediaTypes satisfy the given accept header String, and the order of preference defined by that String. |
java.util.Collection<TypeAndSubtypeWithAnyParametersMediaRange> |
typeAndSubtypeWithAnyParametersMediaRanges() |
|
java.util.Collection<TypeWithAnySubtypeMediaRange> |
typeWithAnySubtypeMediaRanges() |
public AcceptHeader(java.lang.Iterable<java.lang.String> headers)
throws MalformedAcceptHeaderException
AcceptHeader representing the normalised form of the given RFC 2616 accept header Strings.headers - an Iterable of Strings representating of an RFC 2616 accept headers.MalformedAcceptHeaderException - if the given Strings do not conform to RFC 2616.public AcceptHeader(java.lang.String header)
throws MalformedAcceptHeaderException
header - an String representation of a RFC 2616 accept header.MalformedAcceptHeaderException - if the given String does not conform to RFC 2616.public static java.util.List<MediaType> sortedByAcceptHeaderPreference(java.lang.Iterable<java.lang.String> acceptHeaders, java.lang.Iterable<MediaType> availableMediaTypes) throws MalformedAcceptHeaderException
MediaTypes satisfy the given accept header Strings, and the order of preference defined by those Strings.
Allows a server that is capable of generating responses with a known set of media types to determine which to generate when presented with any sequence of accept headers.
In the event that the accept headers permit more than one of the available media types with the same degree of preference, the order in which this method returns those media types is determined by the order they were provided to the method.
In the event that none of the available media types are permissible according to a given accept headers, this method returns an empty List.
acceptHeaders - an Iterable of String representations of an RFC 2616 accept header.availableMediaTypes - an Iterable of MediaTypes to filter and sort according to the given accept header Strings.MediaTypes that are permissible according to the given accept headers, in the order of preference indicated by the headers.MalformedAcceptHeaderException - if the given accept header Strings do not conform to RFC 2616.public static java.util.List<MediaType> sortedByAcceptHeaderPreference(java.lang.String acceptHeader, java.lang.Iterable<MediaType> availableMediaTypes) throws MalformedAcceptHeaderException
MediaTypes satisfy the given accept header String, and the order of preference defined by that String.
Allows a server that is capable of generating responses with a known set of media types to determine which to generate when presented with any accept header.
In the event that an accept header permits more than one of the available media types with the same degree of preference, the order in which this method returns those media types is determined by the order they were provided to the method.
In the event that none of the available media types are permissible according to a given accept header, this method returns an empty List.
acceptHeader - an String representation of an RFC 2616 accept header.availableMediaTypes - an Iterable of MediaTypes to filter and sort according to the given accept header String.MediaTypes that are permissible according to the given accept header, in the order of preference indicated by the header.MalformedAcceptHeaderException - if the given accept header String does not conform to RFC 2616.public int compare(MediaType o1, MediaType o2)
compare in interface java.util.Comparator<MediaType>public boolean accepts(MediaType mediaType)
public java.util.Collection<AcceptAllMediaRange> acceptAllMediaRanges()
public java.util.Collection<TypeWithAnySubtypeMediaRange> typeWithAnySubtypeMediaRanges()
public java.util.Collection<TypeAndSubtypeWithAnyParametersMediaRange> typeAndSubtypeWithAnyParametersMediaRanges()
public java.util.Collection<FullySpecifiedMediaRange> fullySpecifiedMediaRanges()