Package org.apache.sling.api.request.header

# Class JakartaMediaRangeList

java.lang.Object
java.util.AbstractCollection<E>
java.util.AbstractSet<E>
java.util.TreeSet<JakartaMediaRangeList.MediaRange>
org.apache.sling.api.request.header.JakartaMediaRangeList

All Implemented Interfaces:
  `Serializable`, `Cloneable`, `Iterable<JakartaMediaRangeList.MediaRange>`, `Collection<JakartaMediaRangeList.MediaRange>`, `NavigableSet<JakartaMediaRangeList.MediaRange>`, `Set<JakartaMediaRangeList.MediaRange>`, `SortedSet<JakartaMediaRangeList.MediaRange>`

@ConsumerType public class JakartaMediaRangeList extends TreeSet<JakartaMediaRangeList.MediaRange>
Facilitates parsing of the Accept HTTP request header. See RFC 2616 section 14.1

Since:
  1.1.0
See Also:
  - Serialized Form

## Nested Class Summary

Nested Classes
Modifier and Type
Class
Description
`class`
`JakartaMediaRangeList.MediaRange`
A code `MediaRange` represents an entry in a `MediaRangeList`.

## Field Summary

Fields
Modifier and Type
Field
Description
`static final String`
`HEADER_ACCEPT`
`static final String`
`PARAM_ACCEPT`
`static final String`
`WILDCARD`

## Constructor Summary

Constructors
Constructor
Description
`JakartaMediaRangeList(jakarta.servlet.http.HttpServletRequest request)`
Constructs a `MediaRangeList` using information from the supplied `HttpServletRequest`.
`JakartaMediaRangeList(String listStr)`
Constructs a `MediaRangeList` using a list of media ranges specified in a `java.lang.String`.

## Method Summary

Modifier and Type
Method
Description
`boolean`
`contains(String mediaType)`
Determines if this MediaRangeList contains a given media type.
`String`
`prefer(String... mediaRanges)`
Determines which of the `mediaRanges` specifications is preferred by this `MediaRangeList`.
`JakartaMediaRangeList.MediaRange`
`prefer(Set<JakartaMediaRangeList.MediaRange> mediaRanges)`
Given a list of media types, returns the one is preferred by this `MediaRangeList`.

### 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`

### Methods inherited from interface java.lang.Iterable

`forEach`

### Methods inherited from interface java.util.Set

`containsAll, equals, hashCode, removeAll, retainAll, toArray, toArray`

## Field Details

### HEADER_ACCEPT

public static final String HEADER_ACCEPT

See Also:
  - Constant Field Values

### PARAM_ACCEPT

public static final String PARAM_ACCEPT

See Also:
  - Constant Field Values

### WILDCARD

public static final String WILDCARD

See Also:
  - Constant Field Values

## Constructor Details

### JakartaMediaRangeList

public JakartaMediaRangeList(jakarta.servlet.http.HttpServletRequest request)
Constructs a `MediaRangeList` using information from the supplied `HttpServletRequest`. if the request contains a `PARAM_ACCEPT` query parameter, the query parameter value overrides any `HEADER_ACCEPT` header value. If the request contains no `PARAM_ACCEPT` parameter, or the parameter value is empty, the value of the `HEADER_ACCEPT` is used. If both values are missing, it is assumed that the client accepts all media types, as per the RFC. See also `JakartaMediaRangeList(java.lang.String)`

Parameters:
  `request` - The `HttpServletRequest` to extract a `MediaRangeList` from

### JakartaMediaRangeList

public JakartaMediaRangeList(String listStr)
Constructs a `MediaRangeList` using a list of media ranges specified in a `java.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

public boolean contains(String mediaType)
Determines if this MediaRangeList contains a given media type.

Parameters:
  `mediaType` - A string on the form `type/subtype`. Neither `type` or `subtype` should be wildcard (`*`).
Returns:
  `true` if this `MediaRangeList` contains a media type that matches `mediaType`, `false` otherwise
Throws:
  `IllegalArgumentException` - if `mediaType` is not on an accepted form
  `NullPointerException` - if `mediaType` is `null`

### prefer

public JakartaMediaRangeList.MediaRange prefer(Set<JakartaMediaRangeList.MediaRange> mediaRanges)
Given a list of media types, returns the one is preferred by this `MediaRangeList`.

Parameters:
  `mediaRanges` - An array of possible `JakartaMediaRangeList.MediaRange`s
Returns:
  One of the `mediaRanges` that this `MediaRangeList` prefers; or `null` if this `MediaRangeList` does not contain any of the `mediaRanges`
Throws:
  `NullPointerException` - if `mediaRanges` is `null` or contains a `null` value

### prefer

public String prefer(String... mediaRanges)
Determines which of the `mediaRanges` specifications is preferred by this `MediaRangeList`.

Parameters:
  `mediaRanges` - String representations of `MediaRange`s. The strings must be on the form required by `MediaRange(String)`
Returns:
  the `toString()` representation of the preferred `MediaRange`, or `null` if this `MediaRangeList` does not contain any of the `mediaRanges`
See Also:
  - `prefer(java.util.Set)`