#671 - Polishing.
Introduced Link.hasRel(…) and use that to filter link lookups in ResourceSupport.
This commit is contained in:
@@ -168,6 +168,19 @@ public class Link implements Serializable {
|
||||
return new Link(getUriTemplate().expand(arguments).toString(), getRel());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the current {@link Link} has the given link relation.
|
||||
*
|
||||
* @param rel must not be {@literal null} or empty.
|
||||
* @return
|
||||
*/
|
||||
public boolean hasRel(String rel) {
|
||||
|
||||
Assert.hasText(rel, "Link relation must not be null or empty!");
|
||||
|
||||
return this.rel.equals(rel);
|
||||
}
|
||||
|
||||
private UriTemplate getUriTemplate() {
|
||||
|
||||
if (template == null) {
|
||||
|
||||
@@ -126,7 +126,7 @@ public class ResourceSupport implements Identifiable<Link> {
|
||||
public Optional<Link> getLink(String rel) {
|
||||
|
||||
return links.stream() //
|
||||
.filter(link -> link.getRel().equals(rel)) //
|
||||
.filter(link -> link.hasRel(rel)) //
|
||||
.findFirst();
|
||||
}
|
||||
|
||||
@@ -151,7 +151,7 @@ public class ResourceSupport implements Identifiable<Link> {
|
||||
public List<Link> getLinks(String rel) {
|
||||
|
||||
return links.stream() //
|
||||
.filter(link -> link.getRel().equals(rel)) //
|
||||
.filter(link -> link.hasRel(rel)) //
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user