Skip to content

Commit d40bda2

Browse files
izeyegregturn
authored andcommitted
#671 - Remove list creation in ResourceSupport.getLink().
Since `ResourceSupport` has direct access to the list of links, no need to build up an intermedia `List` and then filter on it. Simply filter on the internal list of links. Also did some minor polishing.
1 parent ad801e9 commit d40bda2

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/main/java/org/springframework/hateoas/ResourceSupport.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
* Base class for DTOs to collect links.
3333
*
3434
* @author Oliver Gierke
35+
* @author Johhny Lim
3536
*/
3637
public class ResourceSupport implements Identifiable<Link> {
3738

@@ -123,7 +124,10 @@ public void removeLinks() {
123124
* @return the link with the given rel or {@link Optional#empty()} if none found.
124125
*/
125126
public Optional<Link> getLink(String rel) {
126-
return getLinks(rel).stream().findFirst();
127+
128+
return links.stream() //
129+
.filter(link -> link.getRel().equals(rel)) //
130+
.findFirst();
127131
}
128132

129133
/**

0 commit comments

Comments
 (0)