Spring for Android

org.springframework.http
Class ContentCodingType

java.lang.Object
  extended by org.springframework.http.ContentCodingType
All Implemented Interfaces:
java.lang.Comparable<ContentCodingType>

public class ContentCodingType
extends java.lang.Object
implements java.lang.Comparable<ContentCodingType>

Represents a Compression Type, as defined in the HTTP specification.

Since:
1.0
Author:
Roy Clarkson

Field Summary
static ContentCodingType ALL
          Public constant encoding type for *.
static java.lang.String ALL_VALUE
          A String equivalent of ALL.
static ContentCodingType GZIP
          Public constant encoding type for gzip.
static java.lang.String GZIP_VALUE
          A String equivalent of GZIP.
static ContentCodingType IDENTITY
          Public constant encoding type for identity.
static java.lang.String IDENTITY_VALUE
          A String equivalent of IDENTITY.
static java.util.Comparator<ContentCodingType> QUALITY_VALUE_COMPARATOR
          Comparator used by sortByQualityValue(List).
 
Constructor Summary
ContentCodingType(java.lang.String type)
          Create a new ContentCodingType for the given type.
ContentCodingType(java.lang.String type, double qualityValue)
          Create a new ContentCodingType for the given type and quality value.
ContentCodingType(java.lang.String type, java.util.Map<java.lang.String,java.lang.String> parameters)
          Create a new ContentCodingType for the given type, and parameters.
 
Method Summary
 int compareTo(ContentCodingType other)
          Compares this ContentCodingType to another alphabetically.
 boolean equals(java.lang.Object other)
           
 java.lang.String getParameter(java.lang.String name)
          Return a generic parameter value, given a parameter name.
 double getQualityValue()
          Return the quality value, as indicated by a q parameter, if any.
 java.lang.String getType()
          Return the primary type.
 int hashCode()
           
 boolean includes(ContentCodingType other)
          Indicate whether this ContentCodingType includes the given coding type.
 boolean isCompatibleWith(ContentCodingType other)
          Indicate whether this ContentCodingType is compatible with the given coding type.
 boolean isWildcardType()
          Indicates whether the type is the wildcard character * or not.
static ContentCodingType parseCodingType(java.lang.String codingType)
          Parse the given String into a single ContentCodingType.
static java.util.List<ContentCodingType> parseCodingTypes(java.lang.String codingTypes)
          Parse the given, comma-separated string into a list of ContentCodingType objects.
static void sortByQualityValue(java.util.List<ContentCodingType> codingTypes)
          Sorts the given list of ContentCodingType objects by quality value.
 java.lang.String toString()
           
static java.lang.String toString(java.util.Collection<ContentCodingType> codingTypes)
          Return a string representation of the given list of ContentCodingType objects.
static ContentCodingType valueOf(java.lang.String value)
          Parse the given String value into a ContentCodingType object.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

ALL

public static final ContentCodingType ALL
Public constant encoding type for *.


ALL_VALUE

public static final java.lang.String ALL_VALUE
A String equivalent of ALL.

See Also:
Constant Field Values

IDENTITY

public static final ContentCodingType IDENTITY
Public constant encoding type for identity.


IDENTITY_VALUE

public static final java.lang.String IDENTITY_VALUE
A String equivalent of IDENTITY.

See Also:
Constant Field Values

GZIP

public static final ContentCodingType GZIP
Public constant encoding type for gzip.


GZIP_VALUE

public static final java.lang.String GZIP_VALUE
A String equivalent of GZIP.

See Also:
Constant Field Values

QUALITY_VALUE_COMPARATOR

public static final java.util.Comparator<ContentCodingType> QUALITY_VALUE_COMPARATOR
Comparator used by sortByQualityValue(List).

Constructor Detail

ContentCodingType

public ContentCodingType(java.lang.String type)
Create a new ContentCodingType for the given type.

Parameters:
type - the type

ContentCodingType

public ContentCodingType(java.lang.String type,
                         double qualityValue)
Create a new ContentCodingType for the given type and quality value.

Parameters:
type - the primary type
qualityValue - the quality value
Throws:
java.lang.IllegalArgumentException - if any of the parameters contain illegal characters

ContentCodingType

public ContentCodingType(java.lang.String type,
                         java.util.Map<java.lang.String,java.lang.String> parameters)
Create a new ContentCodingType for the given type, and parameters.

Parameters:
type - the primary type
parameters - the parameters, may be null
Throws:
java.lang.IllegalArgumentException - if any of the parameters contain illegal characters
Method Detail

getType

public java.lang.String getType()
Return the primary type.


isWildcardType

public boolean isWildcardType()
Indicates whether the type is the wildcard character * or not.


getQualityValue

public double getQualityValue()
Return the quality value, as indicated by a q parameter, if any. Defaults to 1.0.

Returns:
the quality factory

getParameter

public java.lang.String getParameter(java.lang.String name)
Return a generic parameter value, given a parameter name.

Parameters:
name - the parameter name
Returns:
the parameter value; or null if not present

includes

public boolean includes(ContentCodingType other)
Indicate whether this ContentCodingType includes the given coding type.

For instance, * includes gzip and deflate

Parameters:
other - the reference coding type with which to compare
Returns:
true if this coding type includes the given coding type; false otherwise

isCompatibleWith

public boolean isCompatibleWith(ContentCodingType other)
Indicate whether this ContentCodingType is compatible with the given coding type.

For instance, * is compatible with gzip, deflate, and vice versa. In effect, this method is similar to includes(ContentCodingType), except that it is symmetric.

Parameters:
other - the reference coding type with which to compare
Returns:
true if this coding type is compatible with the given coding type; false otherwise

compareTo

public int compareTo(ContentCodingType other)
Compares this ContentCodingType to another alphabetically.

Specified by:
compareTo in interface java.lang.Comparable<ContentCodingType>
Parameters:
other - content coding type to compare to

equals

public boolean equals(java.lang.Object other)
Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

valueOf

public static ContentCodingType valueOf(java.lang.String value)
Parse the given String value into a ContentCodingType object.

See Also:
parseCodingType(String)

parseCodingType

public static ContentCodingType parseCodingType(java.lang.String codingType)
Parse the given String into a single ContentCodingType.

Parameters:
codingType - the string to parse
Returns:
the content coding type
Throws:
java.lang.IllegalArgumentException - if the string cannot be parsed

parseCodingTypes

public static java.util.List<ContentCodingType> parseCodingTypes(java.lang.String codingTypes)
Parse the given, comma-separated string into a list of ContentCodingType objects.

This method can be used to parse an Accept-Encoding.

Parameters:
codingTypes - the string to parse
Returns:
the list of content coding types
Throws:
java.lang.IllegalArgumentException - if the string cannot be parsed

toString

public static java.lang.String toString(java.util.Collection<ContentCodingType> codingTypes)
Return a string representation of the given list of ContentCodingType objects.

Parameters:
codingTypes - the string to parse
Returns:
the list of content coding types
Throws:
java.lang.IllegalArgumentException - if the String cannot be parsed

sortByQualityValue

public static void sortByQualityValue(java.util.List<ContentCodingType> codingTypes)
Sorts the given list of ContentCodingType objects by quality value.

Given two content coding types:

  1. if the two coding types have different quality value, then the coding type with the highest quality value is ordered before the other.
  2. if either coding type has a wildcard type, then the coding type without the wildcard is ordered before the other.
  3. if the two coding types have different types, then they are considered equal and remain their current order.

Parameters:
codingTypes - the list of coding types to be sorted
See Also:
getQualityValue()

Spring for Android