Interface Headers.Accept.MediaRange

Enclosing interface:
Headers.Accept

public static interface Headers.Accept.MediaRange

Accept HTTP header media range as defined by RFC 7231 Section 5.3.2.

Since:
1.0
Author:
Jeremy Kuhn
  • Field Details

  • Method Details

    • getMediaType

      String getMediaType()

      Returns the media range raw value.

      Returns:
      the raw media range
    • getType

      String getType()

      Returns the media range type.

      Returns:
      the media range type
    • getSubType

      String getSubType()

      Returns the media range sub-type.

      Returns:
      the media range sub-type
    • getWeight

      float getWeight()

      Returns the media range quality value as defined by RFC 7231 Section 5.3.1.

      Returns:
      the media range quality value
    • getParameters

      Map<String,String> getParameters()

      Returns media range parameters.

      Returns:
      the media range parameters
    • matches

      default boolean matches(Headers.ContentType contentType)

      Determines whether the specified content type matches the media range.

      Parameters:
      contentType - the content type to test
      Returns:
      true if the content type matches the range, false otherwise
    • getScore

      default int getScore()

      Calculates and returns the score or the media range used for sorting.

      The score is calculated by assigning a score to the media range part and add all:

      • the range quality value is multiplied by 1000
      • */* is worth 0
      • */x is worth 10
      • x/* is worth 20
      • x/x is worth 30
      • a null parameter is worth 1
      • a non-null parameter is worth 2
      Returns:
      the score of the media range
    • findFirstMatch

      Returns the first media range in the specified list that matches the specified content type.

      Parameters:
      contentType - a content type
      mediaRanges - a list of media ranges
      Returns:
      an optional returning the first match or an empty optional if no match was found
    • findFirstMatch

      static <T> Optional<Headers.AcceptMatch<T,Headers.ContentType>> findFirstMatch(Headers.ContentType contentType, Collection<T> items, Function<T,Headers.Accept.MediaRange> mediaRangeExtractor)

      Returns the first item in the specified collection whose media range matches the specified content type.

      Type Parameters:
      T - the type of the item
      Parameters:
      contentType - a content type
      items - a collection of items
      mediaRangeExtractor - a function that extracts the media type of an item
      Returns:
      an optional returning the first match or an empty optional if no match was found