Class 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 Details

  • Method Details

    • of

      public static BasicMediaRangesHeader of(String name, String value)
      Static creator.
      Parameters:
      name - The header name.
      value - The header value.
      Must be parsable by MediaRanges.of(String).
      Can be null.
      Returns:
      A new header bean, or null if the value is null.
      Throws:
      IllegalArgumentException - If name is null or empty.
    • of

      public static BasicMediaRangesHeader of(String name, MediaRanges value)
      Static creator.
      Parameters:
      name - The header name.
      value - The header value.
      Can be null.
      Returns:
      A new header bean, or null if the value is null.
      Throws:
      IllegalArgumentException - If name is null or empty.
    • asMediaRanges

      Returns the header value as a MediaRanges wrapped in an Optional.
      Returns:
      The header value as a MediaRanges wrapped in an Optional. Never null.
    • toMediaRanges

      Returns the header value as a MediaRanges.
      Returns:
      The header value as a MediaRanges. Can be null.
    • match

      public int match(List<? extends MediaType> mediaTypes)
      Given a list of media types, returns the best match for this Accept 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 an Accept 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 as id properties are present in the header.

      See ActivityPub / Retrieving Objects

      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

      public MediaRange getRange(int index)
      Returns the MediaRange at the specified index.
      Parameters:
      index - The index position of the media range.
      Returns:
      The MediaRange at the specified index or null if the index is out of range.
    • hasSubtypePart

      public 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.

      For example, given the header "text/json+activity", calling hasSubtypePart("activity") returns true.

      Parameters:
      part - The media type subtype fragment.
      Returns:
      true if subtype fragment exists.
    • getValue

      public String getValue()
      Specified by:
      getValue in interface NameValuePair
      Overrides:
      getValue in class BasicStringHeader
    • orElse

      public MediaRanges orElse(MediaRanges other)
      Return the value if present, otherwise return other.

      This is a shortened form for calling asMediaRanges().orElse(other).

      Parameters:
      other - The value to be returned if there is no value present, can be null.
      Returns:
      The value, if present, otherwise other.