Skip to content

Commit 7527d2e

Browse files
committed
GH-2336 - Enhance logical Link comparability.
1 parent 9d4096d commit 7527d2e

File tree

1 file changed

+24
-1
lines changed
  • src/main/java/org/springframework/hateoas

1 file changed

+24
-1
lines changed

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

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,16 @@ public Link withAffordances(List<Affordance> affordances) {
251251
this.profile, this.name, this.template, affordances);
252252
}
253253

254+
/**
255+
* Returns a new {@link Link} without any {@link Affordance}s.
256+
*
257+
* @return will never be {@literal null}.
258+
* @since 3.0
259+
*/
260+
public Link withoutAffordances() {
261+
return withAffordances(Collections.emptyList());
262+
}
263+
254264
/**
255265
* Returns the variable names contained in the template.
256266
*
@@ -289,13 +299,26 @@ public boolean isTemplated() {
289299
return template == null ? false : !template.getVariables().isEmpty();
290300
}
291301

302+
/**
303+
* Returns whether the links are logically the same, i.e. share all link characteristics but might have different
304+
* affordances attached.
305+
*
306+
* @param other must not be {@literal null}.
307+
* @since 3.0
308+
*/
309+
public boolean isSameAs(Link other) {
310+
311+
Assert.notNull(other, "Link must not be null!");
312+
313+
return withoutAffordances().equals(other.withoutAffordances());
314+
}
315+
292316
/**
293317
* Turns the current template into a {@link Link} by expanding it using the given parameters.
294318
*
295319
* @param arguments
296320
* @return
297321
*/
298-
@SuppressWarnings("null")
299322
public Link expand(Object... arguments) {
300323

301324
UriTemplate template = this.template;

0 commit comments

Comments
 (0)