public class RepresentationModel<T extends RepresentationModel<? extends T>> extends Object
| Constructor and Description |
|---|
RepresentationModel() |
RepresentationModel(Iterable<Link> initialLinks) |
RepresentationModel(Link initialLink) |
| Modifier and Type | Method and Description |
|---|---|
T |
add(Iterable<Link> links)
Adds all given
Links to the resource. |
T |
add(Link... links)
Adds all given
Links to the resource. |
T |
add(Link link)
Adds the given link to the resource.
|
T |
addAllIf(boolean guard,
Supplier<? extends Iterable<Link>> links)
Adds all
Links produced by the given Supplier if the guard is true. |
T |
addIf(boolean guard,
Supplier<Link> link)
Adds the
Link produced by the given Supplier if the guard is true. |
boolean |
equals(Object obj) |
Optional<Link> |
getLink(LinkRelation relation)
Returns the link with the given
LinkRelation. |
Optional<Link> |
getLink(String relation)
Returns the link with the given relation.
|
Links |
getLinks()
Returns all
Links contained in this resource. |
List<Link> |
getLinks(LinkRelation relation)
Returns all
Links with the given relation. |
List<Link> |
getLinks(String relation)
Returns all
Links with the given relation. |
Link |
getRequiredLink(LinkRelation relation)
Returns the link with the given relation.
|
Link |
getRequiredLink(String relation)
Returns the link with the given relation.
|
int |
hashCode() |
boolean |
hasLink(LinkRelation rel) |
boolean |
hasLink(String rel)
Returns whether the resource contains a
Link with the given rel. |
boolean |
hasLinks()
Returns whether the resource contains
Links at all. |
T |
mapLink(LinkRelation relation,
Function<Link,Link> mapper)
Replaces the link(s) with the given
LinkRelation with the mapper applied to each of the links. |
T |
mapLinkIf(boolean condition,
LinkRelation relation,
Function<Link,Link> mapper)
Replaces the link(s) with the given
LinkRelation with the mapper applied to each of the links if the given
condition is true. |
static <T> RepresentationModel<?> |
of(T object)
Creates a new
RepresentationModel for the given content object and no links. |
static <T> RepresentationModel<?> |
of(T object,
Iterable<Link> links)
Creates a new
RepresentationModel for the given content object and links. |
T |
removeLinks()
Removes all
Links added to the resource so far. |
String |
toString() |
public RepresentationModel()
public RepresentationModel(Link initialLink)
public static <T> RepresentationModel<?> of(@Nullable T object)
RepresentationModel for the given content object and no links.object - can be null.of(Object, Iterable)public static <T> RepresentationModel<?> of(@Nullable T object, Iterable<Link> links)
RepresentationModel for the given content object and links. Will return a simple
RepresentationModel if the content is null, a CollectionModel in case the given content
object is a Collection or an EntityModel otherwise.object - can be null.links - must not be null.public T add(Iterable<Link> links)
Links to the resource.links - must not be null.Linkspublic T add(Link... links)
Links to the resource.links - must not be null.public T addIf(boolean guard, Supplier<Link> link)
Link produced by the given Supplier if the guard is true.public T addAllIf(boolean guard, Supplier<? extends Iterable<Link>> links)
Links produced by the given Supplier if the guard is true.public boolean hasLinks()
Links at all.public boolean hasLink(String rel)
Link with the given rel.rel - public boolean hasLink(LinkRelation rel)
public Optional<Link> getLink(String relation)
relation - must not be null or empty.Optional.empty() if none found.public Optional<Link> getLink(LinkRelation relation)
LinkRelation.relation - public Link getRequiredLink(String relation)
relation - must not be null or empty.IllegalArgumentException - in case no link with the given relation can be found.public Link getRequiredLink(LinkRelation relation)
relation - must not be null.IllegalArgumentException - in case no link with the given relation can be found.public List<Link> getLinks(String relation)
Links with the given relation.relation - must not be null.Listpublic List<Link> getLinks(LinkRelation relation)
Links with the given relation.relation - must not be null.Listpublic T mapLink(LinkRelation relation, Function<Link,Link> mapper)
LinkRelation with the mapper applied to each of the links.relation - the LinkRelation to select the source link(s), must not be null.mapper - the Function to apply to the current link, must not be null.public T mapLinkIf(boolean condition, LinkRelation relation, Function<Link,Link> mapper)
LinkRelation with the mapper applied to each of the links if the given
condition is true.condition - the condition that needs to be true to apply the mapping.relation - the LinkRelation to select the source link(s), must not be null.mapper - the Function to apply to the current link, must not be null.Copyright © 2011–2021 Pivotal, Inc.. All rights reserved.