Package org.springframework.hateoas
Class RepresentationModel<T extends RepresentationModel<? extends T>>
java.lang.Object
org.springframework.hateoas.RepresentationModel<T>
- Direct Known Subclasses:
CollectionModel
,EntityModel
,RepresentationModelMixin
,VndErrors.VndError
Base class for DTOs to collect links.
- Author:
- Oliver Gierke, Johhny Lim, Greg Turnquist
-
Constructor Summary
ConstructorDescriptionRepresentationModel
(Iterable<Link> initialLinks) RepresentationModel
(Link initialLink) -
Method Summary
Modifier and TypeMethodDescriptionAdds all givenLink
s to the resource.Adds the given link to the resource.Adds all givenLink
s to the resource.Adds allLink
s produced by the given Supplier if the guard is true.Adds theLink
produced by the given Supplier if the guard is true.boolean
Returns the link with the given relation.getLink
(LinkRelation relation) Returns the link with the givenLinkRelation
.getLinks()
Returns allLink
s contained in this resource.Returns allLink
s with the given relation.getLinks
(LinkRelation relation) Returns allLink
s with the given relation.getRequiredLink
(String relation) Returns the link with the given relation.getRequiredLink
(LinkRelation relation) Returns the link with the given relation.int
hashCode()
boolean
Returns whether the resource contains aLink
with the given rel.boolean
hasLink
(LinkRelation rel) boolean
hasLinks()
Returns whether the resource containsLink
s at all.mapLink
(LinkRelation relation, Function<Link, Link> mapper) Replaces the link(s) with the givenLinkRelation
with the mapper applied to each of the links.mapLinkIf
(boolean condition, LinkRelation relation, Function<Link, Link> mapper) Replaces the link(s) with the givenLinkRelation
with the mapper applied to each of the links if the given condition is true.static <T> RepresentationModel<?>
of
(T object) Creates a newRepresentationModel
for the given content object and no links.static <T> RepresentationModel<?>
Creates a newRepresentationModel
for the given content object and links.Removes allLink
s added to the resource so far.toString()
-
Constructor Details
-
RepresentationModel
public RepresentationModel() -
RepresentationModel
-
RepresentationModel
-
-
Method Details
-
of
Creates a newRepresentationModel
for the given content object and no links.- Parameters:
object
- can be null.- Returns:
- See Also:
-
of
Creates a newRepresentationModel
for the given content object and links. Will return a simpleRepresentationModel
if the content is null, aCollectionModel
in case the given content object is aCollection
or anEntityModel
otherwise.- Parameters:
object
- can be null.links
- must not be null.- Returns:
-
add
Adds the given link to the resource.- Parameters:
link
-
-
add
Adds all givenLink
s to the resource.- Parameters:
links
- must not be null.- See Also:
-
add
Adds all givenLink
s to the resource.- Parameters:
links
- must not be null.
-
addIf
Adds theLink
produced by the given Supplier if the guard is true. -
addAllIf
Adds allLink
s produced by the given Supplier if the guard is true. -
hasLinks
public boolean hasLinks()Returns whether the resource containsLink
s at all.- Returns:
-
hasLink
Returns whether the resource contains aLink
with the given rel.- Parameters:
rel
-- Returns:
-
hasLink
-
getLinks
Returns allLink
s contained in this resource.- Returns:
-
removeLinks
Removes allLink
s added to the resource so far. -
getLink
Returns the link with the given relation.- Parameters:
relation
- must not be null or empty.- Returns:
- the link with the given relation or
Optional.empty()
if none found.
-
getLink
Returns the link with the givenLinkRelation
.- Parameters:
relation
-- Returns:
-
getRequiredLink
Returns the link with the given relation.- Parameters:
relation
- must not be null or empty.- Returns:
- the link with the given relation.
- Throws:
IllegalArgumentException
- in case no link with the given relation can be found.
-
getRequiredLink
Returns the link with the given relation.- Parameters:
relation
- must not be null.- Returns:
- the link with the given relation.
- Throws:
IllegalArgumentException
- in case no link with the given relation can be found.
-
getLinks
Returns allLink
s with the given relation.- Parameters:
relation
- must not be null.- Returns:
- the links in a
List
-
getLinks
Returns allLink
s with the given relation.- Parameters:
relation
- must not be null.- Returns:
- the links in a
List
-
mapLink
Replaces the link(s) with the givenLinkRelation
with the mapper applied to each of the links.- Parameters:
relation
- theLinkRelation
to select the source link(s), must not be null.mapper
- theFunction
to apply to the current link, must not be null.- Returns:
- will never be null.
- Since:
- 1.3
-
mapLinkIf
Replaces the link(s) with the givenLinkRelation
with the mapper applied to each of the links if the given condition is true.- Parameters:
condition
- the condition that needs to be true to apply the mapping.relation
- theLinkRelation
to select the source link(s), must not be null.mapper
- theFunction
to apply to the current link, must not be null.- Returns:
- will never be null.
- Since:
- 1.3
-
toString
-
equals
-
hashCode
public int hashCode()
-