com.github.hal4j.resources.ResourceBuilderSupport Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of hal4j-api Show documentation
Show all versions of hal4j-api Show documentation
HAL API specification for Java
package com.github.hal4j.resources;
import com.github.hal4j.resources.curie.CurieResolver;
import com.github.hal4j.uritemplate.URIBuilder;
import com.github.hal4j.uritemplate.URITemplate;
import java.net.URI;
import java.util.*;
import java.util.function.Predicate;
import java.util.function.Supplier;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import static com.github.hal4j.resources.curie.CurieResolver.REL_CURIES;
import static com.github.hal4j.resources.HALLink.REL_SELF;
import static java.util.Arrays.asList;
public abstract class ResourceBuilderSupport> {
private final CurieResolver resolver;
protected Map> _links;
protected Map> _embedded;
protected Set resolvedNamespaces;
private BindingContext context;
protected ResourceBuilderSupport(CurieResolver resolver) {
this.resolver = resolver;
}
protected abstract B _this();
public final R asResource() {
return build();
}
public B in(BindingContext ctx) {
this.context = ctx;
return _this();
}
public BindingContext context() {
return context;
}
protected Map> links() {
if (_links == null) {
_links = new HashMap<>();
}
return _links;
}
protected Map> embedded() {
if (_embedded == null) {
_embedded = new HashMap<>();
}
return _embedded;
}
public Linker linkSelf() {
return new Linker(URI.create(REL_SELF));
}
public B to(String uri) {
return linkSelf().to(uri);
}
public B to(URIBuilder builder) {
return linkSelf().to(builder);
}
public Linker link(URI rel) {
return new Linker(rel);
}
public Linker link(String rel) {
return new Linker(URI.create(rel));
}
private List mutableLinks(URI rel) {
resolve(rel);
return this.links().computeIfAbsent(rel.toString(), any -> new ArrayList<>());
}
public B embed(String rel, Object... objects) {
return embed(URI.create(rel), objects);
}
public B embed(URI rel, Object... objects) {
return embedAll(rel, asList(objects));
}
public B embedAll(String rel, Collection> objects) {
return embedAll(URI.create(rel), objects);
}
public B embedAll(URI rel, Collection> objects) {
resolve(rel);
List