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

com.github.hal4j.resources.ResourcesBuilder 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.Collection;
import java.util.List;
import java.util.function.Function;

import static java.util.stream.Collectors.toList;

public class ResourcesBuilder
        extends ResourceBuilderSupport, ResourcesBuilder>
        implements Builder> {

    private final Class elementType;
    private final Collection elements;
    private Function> binding;

    public ResourcesBuilder(Class elementType,
                            Collection elements,
                            CurieResolver resolver) {
        super(resolver);
        this.elementType = elementType;
        this.elements = elements;
    }

    public ResourcesBuilder as(Function> bindingFunction) {
        this.binding = bindingFunction;
        return this;
    }

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

    @Override
    public Resources build() {
        List> model = elements.stream().map(binding).collect(toList());
        return new Resources(_links, _embedded, elementType, model, context());
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy