Package org.springframework.hateoas
Class Link
java.lang.Object
org.springframework.hateoas.Link
- All Implemented Interfaces:
Serializable
- Direct Known Subclasses:
DefaultCurieProvider.Curie
,LinkMixin
Value object for links.
- Author:
- Oliver Gierke, Greg Turnquist, Jens Schauder, Viliam Durina
- See Also:
-
Field Summary
-
Constructor Summary
ModifierConstructorDescriptionprotected
Link()
Empty constructor required by the marshaling framework.protected
Link
(String href, LinkRelation rel) Creates a newLink
to the given URI with the given rel.protected
Link
(UriTemplate template, LinkRelation rel) Creates a new Link from the givenUriTemplate
and rel. -
Method Summary
Modifier and TypeMethodDescriptionandAffordance
(Affordance affordance) Create newLink
with an additionalAffordance
.andAffordances
(List<Affordance> affordances) Create newLink
with additionalAffordance
s.boolean
Turns the current template into aLink
by expanding it using the given parameters.Turns the current template into aLink
by expanding it using the given parameters.Returns safe copy ofAffordance
s.getHref()
getMedia()
getName()
getRel()
getTitle()
getType()
Returns the variable names contained in the template.Returns allTemplateVariables
contained in theLink
.int
hashCode()
boolean
Returns whether the currentLink
has the given link relation.boolean
hasRel
(LinkRelation rel) Returns whether theLink
has the givenLinkRelation
.boolean
Returns whether or not the link is templated.static Link
Creates a new link to the given URI with the self relation.static Link
Creates a newLink
to the given href with the given relation.static Link
of
(String href, LinkRelation relation) Creates a newLink
to the given href andLinkRelation
.static Link
of
(UriTemplate template, String relation) Creates a newLink
to the givenUriTemplate
and link relation.static Link
of
(UriTemplate template, LinkRelation relation) toString()
toUri()
Returns the current href as URI after expanding the links without any arguments, i.e. all optional URITemplateVariable
s will be dropped.static Link
withAffordances
(List<Affordance> affordances) Creates a newLink
with the givenAffordance
s.withDeprecation
(String deprecation) Create a newLink
by copying all attributes and applying the new deprecation.Create a newLink
by copying all attributes and applying the new href.withHreflang
(String hreflang) Create a newLink
by copying all attributes and applying the new hreflang.Create a newLink
by copying all attributes and applying the new media.Create a newLink
by copying all attributes and applying the new name.withProfile
(String profile) Create a newLink
by copying all attributes and applying the new profile.Creates a newLink
with the same href but givenLinkRelation
.withRel
(LinkRelation relation) Creates a newLink
with the same href but givenLinkRelation
.Returns aLink
pointing to the same URI but with theself
relation.Create a newLink
by copying all attributes and applying the new title.Create a newLink
by copying all attributes and applying the new type.
-
Field Details
-
ATOM_NAMESPACE
- See Also:
-
-
Constructor Details
-
Link
Creates a newLink
to the given URI with the given rel.- Parameters:
href
- must not be null or empty.rel
- must not be null or empty.
-
Link
Creates a new Link from the givenUriTemplate
and rel.- Parameters:
template
- must not be null.rel
- must not be null or empty.
-
Link
protected Link()Empty constructor required by the marshaling framework.
-
-
Method Details
-
of
Creates a new link to the given URI with the self relation.- Parameters:
href
- must not be null or empty.- Returns:
- Since:
- 1.1
- See Also:
-
of
Creates a newLink
to the given href with the given relation.- Parameters:
href
- must not be null or empty.relation
- must not be null or empty.- Returns:
- Since:
- 1.1
-
of
Creates a newLink
to the given href andLinkRelation
.- Parameters:
href
- must not be null or empty.relation
- must not be null.- Returns:
- Since:
- 1.1
-
of
Creates a newLink
to the givenUriTemplate
and link relation.- Parameters:
template
- must not be null.relation
- must not be null or empty.- Returns:
- Since:
- 1.1
-
of
- Parameters:
template
- must not be null.relation
- must not be null.- Returns:
- Since:
- 1.1
-
getAffordances
Returns safe copy ofAffordance
s.- Returns:
-
withSelfRel
Returns aLink
pointing to the same URI but with theself
relation.- Returns:
-
andAffordance
Create newLink
with an additionalAffordance
.- Parameters:
affordance
- must not be null.- Returns:
-
andAffordances
Create newLink
with additionalAffordance
s.- Parameters:
affordances
- must not be null.- Returns:
-
withAffordances
Creates a newLink
with the givenAffordance
s.- Parameters:
affordances
- must not be null.- Returns:
- will never be null.
-
getVariableNames
Returns the variable names contained in the template.- Returns:
-
getVariables
Returns allTemplateVariables
contained in theLink
.- Returns:
-
isTemplated
public boolean isTemplated()Returns whether or not the link is templated.- Returns:
-
expand
Turns the current template into aLink
by expanding it using the given parameters.- Parameters:
arguments
-- Returns:
-
expand
Turns the current template into aLink
by expanding it using the given parameters.- Parameters:
arguments
- must not be null.- Returns:
-
withRel
Creates a newLink
with the same href but givenLinkRelation
.- Parameters:
relation
- must not be null.- Returns:
- will never be null.
-
withRel
Creates a newLink
with the same href but givenLinkRelation
.- Parameters:
relation
- must not be null or empty.- Returns:
- will never be null.
-
hasRel
Returns whether the currentLink
has the given link relation.- Parameters:
rel
- must not be null or empty.- Returns:
-
hasRel
Returns whether theLink
has the givenLinkRelation
.- Parameters:
rel
- must not be null.- Returns:
-
toUri
Returns the current href as URI after expanding the links without any arguments, i.e. all optional URITemplateVariable
s will be dropped. If the href contains mandatoryTemplateVariable
s, the URI creation will fail with anIllegalStateException
.- Returns:
- will never be null.
- Throws:
IllegalStateException
- in case the href contains mandatory URITemplateVariable
s.
-
valueOf
Factory method to easily createLink
instances from RFC-8288 compatibleString
representations of a link.- Parameters:
source
- an RFC-8288 compatible representation of a link.- Returns:
- will never be null.
- Throws:
IllegalArgumentException
- if aString
was given that does not adhere to RFC-8288.IllegalArgumentException
- if norel
attribute could be found.
-
withHref
Create a newLink
by copying all attributes and applying the new href.- Parameters:
href
- can be null- Returns:
- will never be null.
-
withHreflang
Create a newLink
by copying all attributes and applying the new hreflang.- Parameters:
hreflang
- can be null- Returns:
- will never be null.
-
withMedia
Create a newLink
by copying all attributes and applying the new media.- Parameters:
media
- can be null- Returns:
- will never be null.
-
withTitle
Create a newLink
by copying all attributes and applying the new title.- Parameters:
title
- can be null- Returns:
- will never be null.
-
withType
Create a newLink
by copying all attributes and applying the new type.- Parameters:
type
- can be null- Returns:
- will never be null.
-
withDeprecation
Create a newLink
by copying all attributes and applying the new deprecation.- Parameters:
deprecation
- can be null- Returns:
- will never be null.
-
withProfile
Create a newLink
by copying all attributes and applying the new profile.- Parameters:
profile
- can be null- Returns:
- will never be null.
-
withName
Create a newLink
by copying all attributes and applying the new name.- Parameters:
name
- can be null- Returns:
- will never be null.
-
getRel
-
getHref
-
getHreflang
-
getMedia
-
getTitle
-
getType
-
getDeprecation
-
getProfile
-
getName
-
getTemplate
-
equals
-
hashCode
public int hashCode() -
toString
-