org.glassfish.jersey.message.internal
Class AcceptableMediaType

java.lang.Object
  extended by javax.ws.rs.core.MediaType
      extended by org.glassfish.jersey.message.internal.AcceptableMediaType
All Implemented Interfaces:
Qualified

public class AcceptableMediaType
extends MediaType
implements Qualified

An acceptable media type.

Author:
Paul Sandoz, Marek Potociar (marek.potociar at oracle.com)

Field Summary
 
Fields inherited from class javax.ws.rs.core.MediaType
APPLICATION_ATOM_XML, APPLICATION_ATOM_XML_TYPE, APPLICATION_FORM_URLENCODED, APPLICATION_FORM_URLENCODED_TYPE, APPLICATION_JSON, APPLICATION_JSON_TYPE, APPLICATION_OCTET_STREAM, APPLICATION_OCTET_STREAM_TYPE, APPLICATION_SVG_XML, APPLICATION_SVG_XML_TYPE, APPLICATION_XHTML_XML, APPLICATION_XHTML_XML_TYPE, APPLICATION_XML, APPLICATION_XML_TYPE, CHARSET_PARAMETER, MEDIA_TYPE_WILDCARD, MULTIPART_FORM_DATA, MULTIPART_FORM_DATA_TYPE, TEXT_HTML, TEXT_HTML_TYPE, TEXT_PLAIN, TEXT_PLAIN_TYPE, TEXT_XML, TEXT_XML_TYPE, WILDCARD, WILDCARD_TYPE
 
Fields inherited from interface org.glassfish.jersey.message.internal.Qualified
QUALITY_PARAMETER_NAME
 
Constructor Summary
AcceptableMediaType(String type, String subtype)
          Create new acceptable media type instance with a default quality factor value.
AcceptableMediaType(String type, String subtype, int quality, Map<String,String> parameters)
          Create new acceptable media type instance.
 
Method Summary
 boolean equals(Object obj)
          Compares obj to this media type to see if they are the same by comparing type, subtype and parameters.
 int getQuality()
          Get quality factor value (in [ppt]).
 int hashCode()
          Generate a hash code from the type, subtype and parameters.
static AcceptableMediaType valueOf(HttpHeaderReader reader)
          Create new acceptable media type instance from the supplied HTTP header reader.
 
Methods inherited from class javax.ws.rs.core.MediaType
getParameters, getSubtype, getType, isCompatible, isWildcardSubtype, isWildcardType, toString, valueOf, withCharset
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

AcceptableMediaType

public AcceptableMediaType(String type,
                           String subtype)
Create new acceptable media type instance with a default quality factor value.

Parameters:
type - the primary type, null is equivalent to MediaType.MEDIA_TYPE_WILDCARD
subtype - the subtype, null is equivalent to MediaType.MEDIA_TYPE_WILDCARD

AcceptableMediaType

public AcceptableMediaType(String type,
                           String subtype,
                           int quality,
                           Map<String,String> parameters)
Create new acceptable media type instance.

Parameters:
type - the primary type, null is equivalent to MediaType.MEDIA_TYPE_WILDCARD
subtype - the subtype, null is equivalent to MediaType.MEDIA_TYPE_WILDCARD
quality - quality factor value in [ppt]. See Qualified.
parameters - a map of media type parameters, null is the same as an empty map.
Method Detail

getQuality

public int getQuality()
Description copied from interface: Qualified
Get quality factor value (in [ppt]).

Specified by:
getQuality in interface Qualified
Returns:
quality factor value.

valueOf

public static AcceptableMediaType valueOf(HttpHeaderReader reader)
                                   throws ParseException
Create new acceptable media type instance from the supplied HTTP header reader.

Parameters:
reader - HTTP header reader.
Returns:
new acceptable media type instance.
Throws:
ParseException - in case the input data parsing failed.

equals

public boolean equals(Object obj)
Description copied from class: MediaType
Compares obj to this media type to see if they are the same by comparing type, subtype and parameters. Note that the case-sensitivity of parameter values is dependent on the semantics of the parameter name, see HTTP/1.1. This method assumes that values are case-sensitive.

Note that the equals(...) implementation does not perform a class equality check (this.getClass() == obj.getClass()). Therefore any class that extends from MediaType class and needs to override one of the equals(...) and MediaType.hashCode() methods must always override both methods to ensure the contract between Object.equals(java.lang.Object) and Object.hashCode() does not break.

Overrides:
equals in class MediaType
Parameters:
obj - the object to compare to.
Returns:
true if the two media types are the same, false otherwise.

hashCode

public int hashCode()
Description copied from class: MediaType
Generate a hash code from the type, subtype and parameters.

Note that the MediaType.equals(java.lang.Object) implementation does not perform a class equality check (this.getClass() == obj.getClass()). Therefore any class that extends from MediaType class and needs to override one of the MediaType.equals(Object) and hashCode() methods must always override both methods to ensure the contract between Object.equals(java.lang.Object) and Object.hashCode() does not break.

Overrides:
hashCode in class MediaType
Returns:
a generated hash code.


Copyright © 2007-2014, Oracle and/or its affiliates. All Rights Reserved. Use is subject to license terms.