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

com.varmateo.yawg.core.CollectiveTemplateService Maven / Gradle / Ivy

/**************************************************************************
 *
 * Copyright (c) 2016-2020 Yawg project contributors.
 *
 **************************************************************************/

package com.varmateo.yawg.core;

import java.util.Optional;
import java.util.function.Function;

import io.vavr.collection.Seq;
import io.vavr.control.Option;

import com.varmateo.yawg.api.YawgException;
import com.varmateo.yawg.spi.Template;
import com.varmateo.yawg.spi.TemplateService;


/**
 * 
 */
/* default */ final class CollectiveTemplateService
        implements TemplateService {


    private final Function> _templateFetcher;


    private CollectiveTemplateService(final Seq services) {

        if ( services.isEmpty() ) {
            _templateFetcher = name -> Optional.empty();
        } else {
            _templateFetcher = name -> prepareTemplateFromServices(services, name);
        }
    }


    /**
     *
     */
    public static TemplateService create(final Seq services) {
        return new CollectiveTemplateService(services);
    }


    /**
     * {@inheritDoc}
     */
    @Override
    public Optional