Class MediaRangeList.MediaRange
java.lang.Object
org.apache.sling.api.request.header.MediaRangeList.MediaRange
- All Implemented Interfaces:
Comparable<MediaRangeList.MediaRange>
- Enclosing class:
MediaRangeList
public class MediaRangeList.MediaRange
extends Object
implements Comparable<MediaRangeList.MediaRange>
A code
MediaRange represents an entry in a MediaRangeList.
The MediaRange consists of a supertype and a subtype,
optionally a quality factor parameter q and other arbitrary parameters.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintbooleanbooleanCompares the type and subtype with a string, ignoring parameters.@Nullable StringgetParameter(@Nullable String key) Returns a parameter value using a case-insensitive name lookup.Returns the parameters with parsed names normalized to lowercase.doublegetQ()Get the value of the quality factor parameter (q).Returns the subtype component of this media range.Returns the type component of this media range.booleanReturnstrueif this is a catch-all media range (*/*).toString()
-
Constructor Details
-
MediaRange
Constructs aMediaRangefrom aStringexpression.- Parameters:
exp- TheStringto construct theMediaRangefrom. The string is expected to be on the form ( "*/*" | ( type "/" "*" ) | ( type "/" subtype ) ) *( ";" parameter )
as specified by RFC 2616, section 14.1.Examples:
text/html;q=0.8text/htmltext/html;level=3text/html;level=3;q=0.7text/**/*
*), then the subtype component must also be wildcard.The quality factor parameter must be between
0and1, inclusive (see RFC 2616 section 3.9). If the expression does not contain aqparameter, theMediaRangeis given a default quality factor of1.- Throws:
IllegalArgumentException- ifexpcan not be parsed to a valid media rangeNullPointerException- ifexpisnull
-
-
Method Details
-
matchesAll
public boolean matchesAll()Returnstrueif this is a catch-all media range (*/*).- Returns:
trueif this range is a catch-all media range,falseotherwise
-
getParameter
Returns a parameter value using a case-insensitive name lookup.- Parameters:
key- The parameter name, ornull- Returns:
- The parameter value, or
nullif no parameter matches
-
getSupertype
Returns the type component of this media range.- Returns:
- The type, or
MediaRangeList.WILDCARD
-
getSubtype
Returns the subtype component of this media range.- Returns:
- The subtype, or
MediaRangeList.WILDCARD
-
getQ
public double getQ()Get the value of the quality factor parameter (q).- Returns:
- the quality factor
-
getParameters
Returns the parameters with parsed names normalized to lowercase. Parameter values retain their original casing.- Returns:
- The parameter map, or an empty map if there are no parameters
-
compareTo
- Specified by:
compareToin interfaceComparable<MediaRangeList.MediaRange>
-
equals
-
equals
Compares the type and subtype with a string, ignoring parameters.- Parameters:
s- The string intype/subtypeform- Returns:
- Whether the string exactly matches the type and subtype
-
toString
-