All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.hal4j.resources.GenericResourceBuilder Maven / Gradle / Ivy

There is a newer version: 1.1.0
Show newest version
package com.github.hal4j.resources;

import com.github.hal4j.resources.curie.CurieResolver;

import java.util.HashMap;
import java.util.Map;

public class GenericResourceBuilder
        extends ResourceBuilderSupport
        implements Builder {

    private Map model = new HashMap<>();

    public GenericResourceBuilder(CurieResolver resolver) {
        super(resolver);
    }

    @Override
    protected GenericResourceBuilder _this() {
        return this;
    }

    public GenericResourceBuilder add(String key, Object value) {
        this.model.put(key, value);
        return this;
    }

    @Override
    public GenericResource build() {
        return new GenericResource(model.isEmpty() ? null : model, _links, _embedded, context());
    }

    public GenericResourceBuilder from(GenericResource resource, MergeStrategy strategy) {
        if (resource.model != null) {
            this.model.putAll(resource.model);
        }
        return merge(resource, strategy);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy