Top Description Inners Fields Constructors Methods
javax.ws.rs.core

public Class Variant

extends Object
Class Inheritance
Imports
java.io.StringWriter, java.util.List, .Locale, javax.ws.rs.ext.RuntimeDelegate

Abstraction for a resource representation variant. Contains information about media type, language and encoding of the resource representation.
Authors
Paul Sandoz, Marc Hadley
Since
1.0

Nested and Inner Type Summary

Modifier and TypeClass and Description
public abstract static class
Variant.VariantListBuilder

A builder for a list of representation variants.

Field Summary

Modifier and TypeField and Description
private String
private Locale
private MediaType

Constructor Summary

AccessConstructor and Description
public
Variant(MediaType
the media type of the variant - may be null.
mediaType
,
String
the language of the variant (two-letter ISO-639 code); may be null.
language
,
String
the content encoding of the variant - may be null.
encoding
)

Create a new instance of Variant.

public
Variant(MediaType
the media type of the variant - may be null.
mediaType
,
String
the language of the variant (two-letter ISO-639 code); may be null.
language
,
String
uppercase two-letter ISO-3166 language code of the variant; may be null provided language is null too.
country
,
String
the content encoding of the variant - may be null.
encoding
)

Create a new instance of Variant.

public
Variant(MediaType
the media type of the variant - may be null.
mediaType
,
String
the language of the variant (two-letter ISO-639 code); may be null.
language
,
String
uppercase two-letter ISO-3166 language code of the variant; may be null provided language is null too.
country
,
String
vendor and browser specific language code of the variant (see also Locale class description); may be null provided language and country are null too.
languageVariant
,
String
the content encoding of the variant - may be null.
encoding
)

Create a new instance of Variant.

public
Variant(MediaType
the media type of the variant - may be null.
mediaType
,
Locale
the language of the variant - may be null.
language
,
String
the content encoding of the variant - may be null.
encoding
)

Create a new instance of Variant.

Method Summary

Modifier and TypeMethod and Description
public static Variant.VariantListBuilder

Returns:

the initialized builder.
encodings
(String...
the available encodings.
encodings
)

Create a VariantListBuilder initialized with a set of supported encodings.

public boolean

Returns:

true if the two variants are the same, false otherwise.
equals
(Object
the object to compare to.
obj
)

Overrides java.lang.Object.equals.

Compares obj to this variant to see if they are the same considering all property values.
public String

Returns:

the encoding or null if none set.
getEncoding
()

Get the encoding of the variant.

public Locale

Returns:

the language or null if none set.
getLanguage
()

Get the language of the variant.

public String

Returns:

the string representing variant language or null if none set.
getLanguageString
()

Get the string representation of the variant language, or null if no language has been set.

public MediaType

Returns:

the media type or null if none set.
getMediaType
()

Get the media type of the variant.

public int

Returns:

the hash code.
hashCode
()

Overrides java.lang.Object.hashCode.

Generate hash code from variant properties.
public static Variant.VariantListBuilder

Returns:

the initialized builder.
languages
(Locale...
the available languages.
languages
)

Create a VariantListBuilder initialized with a set of supported languages.

public static Variant.VariantListBuilder

Returns:

the initialized builder.
mediaTypes
(MediaType...
the available mediaTypes. If specific char-sets are supported they should be included as parameters of the respective media type.
mediaTypes
)

Create a VariantListBuilder initialized with a set of supported media types.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait

Field Detail

encodingback to summary
private String encoding
languageback to summary
private Locale language
mediaTypeback to summary
private MediaType mediaType

Constructor Detail

Variantback to summary
public Variant(MediaType mediaType, String language, String encoding)

Create a new instance of Variant.

Parameters
mediaType:MediaType

the media type of the variant - may be null.

language:String

the language of the variant (two-letter ISO-639 code); may be null.

encoding:String

the content encoding of the variant - may be null.

Exceptions
IllegalArgumentException:
if all the parameters are null.
Since
2.0
Variantback to summary
public Variant(MediaType mediaType, String language, String country, String encoding)

Create a new instance of Variant.

Parameters
mediaType:MediaType

the media type of the variant - may be null.

language:String

the language of the variant (two-letter ISO-639 code); may be null.

country:String

uppercase two-letter ISO-3166 language code of the variant; may be null provided language is null too.

encoding:String

the content encoding of the variant - may be null.

Exceptions
IllegalArgumentException:
if all the parameters are null.
Since
2.0
Variantback to summary
public Variant(MediaType mediaType, String language, String country, String languageVariant, String encoding)

Create a new instance of Variant.

Parameters
mediaType:MediaType

the media type of the variant - may be null.

language:String

the language of the variant (two-letter ISO-639 code); may be null.

country:String

uppercase two-letter ISO-3166 language code of the variant; may be null provided language is null too.

languageVariant:String

vendor and browser specific language code of the variant (see also Locale class description); may be null provided language and country are null too.

encoding:String

the content encoding of the variant - may be null.

Exceptions
IllegalArgumentException:
if all the parameters are null.
Since
2.0
Variantback to summary
public Variant(MediaType mediaType, Locale language, String encoding)

Create a new instance of Variant.

Parameters
mediaType:MediaType

the media type of the variant - may be null.

language:Locale

the language of the variant - may be null.

encoding:String

the content encoding of the variant - may be null.

Exceptions
IllegalArgumentException:
if all the parameters are null.

Method Detail

encodingsback to summary
public static Variant.VariantListBuilder encodings(String... encodings)

Create a VariantListBuilder initialized with a set of supported encodings.

Parameters
encodings:String[]

the available encodings.

Returns:Variant.VariantListBuilder

the initialized builder.

Exceptions
IllegalArgumentException:
if encodings is null or contains no elements.
equalsback to summary
public boolean equals(Object obj)

Overrides java.lang.Object.equals.

Compares obj to this variant to see if they are the same considering all property values.

Parameters
obj:Object

the object to compare to.

Returns:boolean

true if the two variants are the same, false otherwise.

Annotations
@Override
getEncodingback to summary
public String getEncoding()

Get the encoding of the variant.

Returns:String

the encoding or null if none set.

getLanguageback to summary
public Locale getLanguage()

Get the language of the variant.

Returns:Locale

the language or null if none set.

getLanguageStringback to summary
public String getLanguageString()

Get the string representation of the variant language, or null if no language has been set.

Returns:String

the string representing variant language or null if none set.

Since
2.0
getMediaTypeback to summary
public MediaType getMediaType()

Get the media type of the variant.

Returns:MediaType

the media type or null if none set.

hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Generate hash code from variant properties.

Returns:int

the hash code.

Annotations
@Override
languagesback to summary
public static Variant.VariantListBuilder languages(Locale... languages)

Create a VariantListBuilder initialized with a set of supported languages.

Parameters
languages:Locale[]

the available languages.

Returns:Variant.VariantListBuilder

the initialized builder.

Exceptions
IllegalArgumentException:
if languages is null or contains no elements.
mediaTypesback to summary
public static Variant.VariantListBuilder mediaTypes(MediaType... mediaTypes)

Create a VariantListBuilder initialized with a set of supported media types.

Parameters
mediaTypes:MediaType[]

the available mediaTypes. If specific char-sets are supported they should be included as parameters of the respective media type.

Returns:Variant.VariantListBuilder

the initialized builder.

Exceptions
IllegalArgumentException:
if mediaTypes is null or contains no elements.
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object.

Annotations
@Override
javax.ws.rs.core back to summary

public abstract Class Variant.VariantListBuilder

extends Object
Class Inheritance

A builder for a list of representation variants.

Constructor Summary

AccessConstructor and Description
protected
VariantListBuilder()

Protected constructor, use the static newInstance method to obtain an instance.

Method Summary

Modifier and TypeMethod and Description
public abstract Variant.VariantListBuilder

Returns:

the updated builder.
add
()

Add the current combination of metadata to the list of supported variants, after this method is called the current combination of metadata is emptied.

public abstract List<Variant>

Returns:

a list of representation variants.
build
()

Add the current combination of metadata to the list of supported variants (provided the current combination of metadata is not empty) and build a list of representation variants from the current state of the builder.

public abstract Variant.VariantListBuilder

Returns:

the updated builder.
encodings
(String...
the available encodings.
encodings
)

Set the encoding(s) for this variant.

public abstract Variant.VariantListBuilder

Returns:

the updated builder.
languages
(Locale...
the available languages.
languages
)

Set the language(s) for this variant.

public abstract Variant.VariantListBuilder

Returns:

the updated builder.
mediaTypes
(MediaType...
the available mediaTypes. If specific charsets are supported they should be included as parameters of the respective media type.
mediaTypes
)

Set the media type(s) for this variant.

public static Variant.VariantListBuilder

Returns:

a new builder instance.
newInstance
()

Create a new builder instance.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

VariantListBuilderback to summary
protected VariantListBuilder()

Protected constructor, use the static newInstance method to obtain an instance.

Method Detail

addback to summary
public abstract Variant.VariantListBuilder add()

Add the current combination of metadata to the list of supported variants, after this method is called the current combination of metadata is emptied.

If more than one value is supplied for one or more of the variant properties then a variant will be generated for each possible combination. E.g. in the following list would have five (4 + 1) members:

List list = VariantListBuilder.newInstance()
        .languages(Locale.ENGLISH, Locale.FRENCH).encodings("zip", "identity").add()
        .languages(Locale.GERMAN).mediaTypes(MediaType.TEXT_PLAIN_TYPE).add()
        .build()

Note that it is not necessary to call the add() method immediately before the build method is called. E.g. the resulting list produced in the example above would be identical to the list produced by the following code:

List list = VariantListBuilder.newInstance()
        .languages(Locale.ENGLISH, Locale.FRENCH).encodings("zip", "identity").add()
        .languages(Locale.GERMAN).mediaTypes(MediaType.TEXT_PLAIN_TYPE)
        .build()
Returns:Variant.VariantListBuilder

the updated builder.

Exceptions
IllegalStateException:
if there is not at least one mediaType, language or encoding set for the current variant.
buildback to summary
public abstract List<Variant> build()

Add the current combination of metadata to the list of supported variants (provided the current combination of metadata is not empty) and build a list of representation variants from the current state of the builder. After this method is called the builder is reset to an empty state.

Returns:List<Variant>

a list of representation variants.

encodingsback to summary
public abstract Variant.VariantListBuilder encodings(String... encodings)

Set the encoding(s) for this variant.

Parameters
encodings:String[]

the available encodings.

Returns:Variant.VariantListBuilder

the updated builder.

languagesback to summary
public abstract Variant.VariantListBuilder languages(Locale... languages)

Set the language(s) for this variant.

Parameters
languages:Locale[]

the available languages.

Returns:Variant.VariantListBuilder

the updated builder.

mediaTypesback to summary
public abstract Variant.VariantListBuilder mediaTypes(MediaType... mediaTypes)

Set the media type(s) for this variant.

Parameters
mediaTypes:MediaType[]

the available mediaTypes. If specific charsets are supported they should be included as parameters of the respective media type.

Returns:Variant.VariantListBuilder

the updated builder.

newInstanceback to summary
public static Variant.VariantListBuilder newInstance()

Create a new builder instance.

Returns:Variant.VariantListBuilder

a new builder instance.