org.restlet.representation

## Class Variant

- java.lang.Object
- - org.restlet.representation.Variant

Direct Known Subclasses:
  RepresentationInfo, VariantInfo

    public class Variant
    extends java.lang.Object

Descriptor for available representations of a resource. It contains all the important metadata about a representation but is not able to actually serve the representation's content itself.
For this, you need to use the Representation subclass.

Author:
  Jerome Louvel

### Constructor Summary

Constructors
Constructor and Description
`Variant()` Default constructor.
`Variant(MediaType mediaType)` Constructor.
`Variant(MediaType mediaType, Language language)` Constructor.

### Method Summary

Methods
`ClientInfo` `createClientInfo()` Creates a `ClientInfo` instance with preferences matching exactly the current variant.
`boolean` `equals(java.lang.Object other)` Indicates if the current variant is equal to the given variant.
`CharacterSet` `getCharacterSet()` Returns the character set or null if not applicable.
`java.util.List<Encoding>` `getEncodings()` Returns the modifiable list of encodings applied to the entity-body.
`Reference` `getIdentifier()` Deprecated. Use `getLocationRef()` instead.
`java.util.List<Language>` `getLanguages()` Returns the modifiable list of languages.
`Reference` `getLocationRef()` Returns an optional location reference.
`MediaType` `getMediaType()` Returns the media type. Note that when used with HTTP connectors, this property maps to the "Content-Type" header.
`boolean` `includes(Variant other)` Indicates if the current variant includes the given variant.
`boolean` `isCompatible(Variant other)` Indicates if the current variant is compatible with the given variant.
`void` `setCharacterSet(CharacterSet characterSet)` Sets the character set or null if not applicable. Note that when used with HTTP connectors, this property maps to the "Content-Type" header.
`void` `setEncodings(java.util.List<Encoding> encodings)` Sets the list of encodings applied to the entity-body. Note that when used with HTTP connectors, this property maps to the "Content-Encoding" header.
`void` `setIdentifier(Reference identifier)` Deprecated. Use `setLocationRef(Reference)` instead
`void` `setIdentifier(java.lang.String identifierUri)` Deprecated. Use `setLocationRef(String)` instead.
`void` `setLanguages(java.util.List<Language> languages)` Sets the list of languages. Note that when used with HTTP connectors, this property maps to the "Content-Language" header.
`void` `setLocationRef(Reference location)` Sets the optional identifier.
`void` `setLocationRef(java.lang.String locationUri)` Sets the identifier from a URI string. Note that when used with HTTP connectors, this property maps to the "Content-Location" header.
`void` `setMediaType(MediaType mediaType)` Sets the media type. Note that when used with HTTP connectors, this property maps to the "Content-Type" header.
`java.lang.String` `toString()`

### Methods inherited from class java.lang.Object

`clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

### Constructor Detail

#### Variant

    public Variant()

Default constructor.

#### Variant

    public Variant(MediaType mediaType)

Constructor.

Parameters:
  `mediaType` - The media type.

#### Variant

    public Variant(MediaType mediaType,
           Language language)

Constructor.

Parameters:
  `mediaType` - The media type.
  `language` - The language.

### Method Detail

#### createClientInfo

    public ClientInfo createClientInfo()

Creates a `ClientInfo` instance with preferences matching exactly the current variant.

Returns:
  The new `ClientInfo` instance.

#### equals

    public boolean equals(java.lang.Object other)

Indicates if the current variant is equal to the given variant.

Overrides:
  `equals` in class `java.lang.Object`
Parameters:
  `other` - The other variant.
Returns:
  True if the current variant includes the other.

#### getCharacterSet

    public CharacterSet getCharacterSet()

Returns the character set or null if not applicable. Note that when used with HTTP connectors, this property maps to the "Content-Type" header.

Returns:
  The character set or null if not applicable.

#### getEncodings

    public java.util.List<Encoding> getEncodings()

Returns the modifiable list of encodings applied to the entity-body. Creates a new instance if no one has been set. An "IllegalArgumentException" exception is thrown when adding a null encoding to this list.
Note that when used with HTTP connectors, this property maps to the "Content-Encoding" header.

Returns:
  The list of encodings applied to the entity-body.

#### getIdentifier

    @Deprecated
    public Reference getIdentifier()

Deprecated. Use `getLocationRef()` instead.
Returns an optional identifier. This is useful when the representation is accessible from a location separate from the representation's resource URI, for example when content negotiation occurs.
Note that when used with HTTP connectors, this property maps to the "Content-Location" header.

Returns:
  The identifier.

#### getLanguages

    public java.util.List<Language> getLanguages()

Returns the modifiable list of languages. Creates a new instance if no one has been set. An "IllegalArgumentException" exception is thrown when adding a null language to this list.
Note that when used with HTTP connectors, this property maps to the "Content-Language" header.

Returns:
  The list of languages.

#### getLocationRef

    public Reference getLocationRef()

Returns an optional location reference. This is useful when the representation is accessible from a location separate from the representation's resource URI, for example when content negotiation occurs.
Note that when used with HTTP connectors, this property maps to the "Content-Location" header.

Returns:
  The identifier.

#### getMediaType

    public MediaType getMediaType()

Returns the media type.
Note that when used with HTTP connectors, this property maps to the "Content-Type" header.

Returns:
  The media type.

#### includes

    public boolean includes(Variant other)

Indicates if the current variant includes the given variant.

Parameters:
  `other` - The other variant.
Returns:
  True if the current variant includes the other.

#### isCompatible

    public boolean isCompatible(Variant other)

Indicates if the current variant is compatible with the given variant.

Parameters:
  `other` - The other variant.
Returns:
  True if the current variant is compatible with the other.

#### setCharacterSet

    public void setCharacterSet(CharacterSet characterSet)

Sets the character set or null if not applicable.
Note that when used with HTTP connectors, this property maps to the "Content-Type" header.

Parameters:
  `characterSet` - The character set or null if not applicable.

#### setEncodings

    public void setEncodings(java.util.List<Encoding> encodings)

Sets the list of encodings applied to the entity-body.
Note that when used with HTTP connectors, this property maps to the "Content-Encoding" header.

Parameters:
  `encodings` - The list of encodings applied to the entity-body.

#### setIdentifier

    @Deprecated
    public void setIdentifier(Reference identifier)

Deprecated. Use `setLocationRef(Reference)` instead
Sets the optional identifier. This is useful when the representation is accessible from a location separate from the representation's resource URI, for example when content negotiation occurs.
Note that when used with HTTP connectors, this property maps to the "Content-Location" header.

Parameters:
  `identifier` - The identifier.

#### setIdentifier

    @Deprecated
    public void setIdentifier(java.lang.String identifierUri)

Deprecated. Use `setLocationRef(String)` instead.
Sets the identifier from a URI string.
Note that when used with HTTP connectors, this property maps to the "Content-Location" header.

Parameters:
  `identifierUri` - The identifier to parse.
See Also:
  `setIdentifier(Reference)`

#### setLanguages

    public void setLanguages(java.util.List<Language> languages)

Sets the list of languages.
Note that when used with HTTP connectors, this property maps to the "Content-Language" header.

Parameters:
  `languages` - The list of languages.

#### setLocationRef

    public void setLocationRef(Reference location)

Sets the optional identifier. This is useful when the representation is accessible from a location separate from the representation's resource URI, for example when content negotiation occurs.
Note that when used with HTTP connectors, this property maps to the "Content-Location" header.

Parameters:
  `location` - The location reference.

#### setLocationRef

    public void setLocationRef(java.lang.String locationUri)

Sets the identifier from a URI string.
Note that when used with HTTP connectors, this property maps to the "Content-Location" header.

Parameters:
  `locationUri` - The location URI to parse.
See Also:
  `setIdentifier(Reference)`

#### setMediaType

    public void setMediaType(MediaType mediaType)

Sets the media type.
Note that when used with HTTP connectors, this property maps to the "Content-Type" header.

Parameters:
  `mediaType` - The media type.

#### toString

    public java.lang.String toString()

Overrides:
  `toString` in class `java.lang.Object`