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
Base class for DTOs to collect links.
- Author:
- Oliver Gierke, Johhny Lim, Greg Turnquist
-
Constructor Summary
ConstructorsConstructorDescriptionRepresentationModel(Iterable<Link> initialLinks) RepresentationModel(Link initialLink) -
Method Summary
Modifier and TypeMethodDescriptionAdds all givenLinks to the resource.Adds the given link to the resource.Adds all givenLinks to the resource.Adds allLinks produced by the given Supplier if the guard is true.Adds theLinkproduced by the given Supplier if the guard is true.booleanReturns the link with the given relation.getLink(LinkRelation relation) Returns the link with the givenLinkRelation.getLinks()Returns allLinks contained in this resource.Returns allLinks with the given relation.getLinks(LinkRelation relation) Returns allLinks with the given relation.getRequiredLink(String relation) Returns the link with the given relation.getRequiredLink(LinkRelation relation) Returns the link with the given relation.inthashCode()booleanReturns whether the resource contains aLinkwith the given rel.booleanhasLink(LinkRelation rel) booleanhasLinks()Returns whether the resource containsLinks at all.mapLink(LinkRelation relation, Function<Link, Link> mapper) Replaces the link(s) with the givenLinkRelationwith the mapper applied to each of the links.mapLinkIf(boolean condition, LinkRelation relation, Function<Link, Link> mapper) Replaces the link(s) with the givenLinkRelationwith the mapper applied to each of the links if the given condition is true.static <T> RepresentationModel<?>of(@Nullable T object) Creates a newRepresentationModelfor the given content object and no links.static <T> RepresentationModel<?>Creates a newRepresentationModelfor the given content object and links.Removes allLinks added to the resource so far.toString()
-
Constructor Details
-
RepresentationModel
public RepresentationModel() -
RepresentationModel
-
RepresentationModel
-
-
Method Details
-
of
Creates a newRepresentationModelfor the given content object and no links.- Parameters:
object- can be null.- Returns:
- See Also:
-
of
Creates a newRepresentationModelfor the given content object and links. Will return a simpleRepresentationModelif the content is null, aCollectionModelin case the given content object is aCollectionor anEntityModelotherwise.- Parameters:
object- can be null.links- must not be null.- Returns:
-
add
Adds the given link to the resource.- Parameters:
link-
-
add
Adds all givenLinks to the resource.- Parameters:
links- must not be null.- See Also:
-
add
Adds all givenLinks to the resource.- Parameters:
links- must not be null.
-
addIf
Adds theLinkproduced by the given Supplier if the guard is true. -
addAllIf
Adds allLinks produced by the given Supplier if the guard is true. -
hasLinks
public boolean hasLinks()Returns whether the resource containsLinks at all.- Returns:
-
hasLink
Returns whether the resource contains aLinkwith the given rel.- Parameters:
rel-- Returns:
-
hasLink
-
getLinks
Returns allLinks contained in this resource.- Returns:
-
removeLinks
Removes allLinks 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 allLinks with the given relation.- Parameters:
relation- must not be null.- Returns:
- the links in a
List
-
getLinks
Returns allLinks with the given relation.- Parameters:
relation- must not be null.- Returns:
- the links in a
List
-
mapLink
Replaces the link(s) with the givenLinkRelationwith the mapper applied to each of the links.- Parameters:
relation- theLinkRelationto select the source link(s), must not be null.mapper- theFunctionto apply to the current link, must not be null.- Returns:
- will never be null.
- Since:
- 1.3
-
mapLinkIf
Replaces the link(s) with the givenLinkRelationwith 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- theLinkRelationto select the source link(s), must not be null.mapper- theFunctionto apply to the current link, must not be null.- Returns:
- will never be null.
- Since:
- 1.3
-
toString
-
equals
-
hashCode
public int hashCode()
-