#845 - Polished Link, UriTemplate, TemplateVariables and IanaLinkRelations.

Added Link.toURI() to conveniently create URIs from Link instances.
This commit is contained in:
Oliver Drotbohm
2019-03-01 15:53:45 +01:00
parent 23c0a34c66
commit 5f772e30c5
5 changed files with 88 additions and 35 deletions

View File

@@ -22,6 +22,7 @@ import lombok.Getter;
import lombok.experimental.Wither;
import java.io.Serializable;
import java.net.URI;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
@@ -391,6 +392,23 @@ public class Link implements Serializable {
return this.template;
}
/**
* Returns the current href as URI after expanding the links without any arguments, i.e. all optional URI
* {@link TemplateVariable}s will be dropped. If the href contains mandatory {@link TemplateVariable}s, the URI
* creation will fail with an {@link IllegalStateException}.
*
* @return will never be {@literal null}.
* @throws IllegalStateException in case the href contains mandatory URI {@link TemplateVariable}s.
*/
public URI toUri() {
try {
return URI.create(expand().getHref());
} catch (IllegalArgumentException o_O) {
throw new IllegalStateException(o_O);
}
}
/*
* (non-Javadoc)
* @see java.lang.Object#toString()