#841 - Added builder API to HalLinkRelation.

This allows more convenient setup of multiple HalLinkRelation instances for the same curie.

Additional unit tests.
This commit is contained in:
Oliver Drotbohm
2019-02-28 17:23:59 +01:00
parent 81af032810
commit 33f22e8bc9
2 changed files with 135 additions and 0 deletions

View File

@@ -105,6 +105,16 @@ public class HalLinkRelation implements LinkRelation, MessageSourceResolvable {
return new HalLinkRelation(null, rel);
}
/**
* Creates a new {@link HalLinkRelationBuilder} for the given curie.
*
* @param curie must not be {@literal null} or empty.
* @return will never be {@literal null}.
*/
public static HalLinkRelationBuilder curieBuilder(String curie) {
return relation -> new HalLinkRelation(curie, relation);
}
/**
* Creates a new {@link HalLinkRelation} curied to the given value.
*
@@ -162,6 +172,22 @@ public class HalLinkRelation implements LinkRelation, MessageSourceResolvable {
.toArray(String[]::new);
}
/**
* Simple builder interface to easily create multiple {@link HalLinkRelation}s for a single curie.
*
* @author Oliver Drotbohm
*/
public interface HalLinkRelationBuilder {
/**
* Creates a new {@link HalLinkRelation} based on the current curie settings.
*
* @param relation must not be {@literal null} or empty.
* @return will never be {@literal null}.
*/
HalLinkRelation relation(String relation);
}
/*
* (non-Javadoc)
* @see java.lang.Object#toString()