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

dev.aurelium.slate.builder.TemplateBuilder Maven / Gradle / Ivy

The newest version!
package dev.aurelium.slate.builder;

import dev.aurelium.slate.action.trigger.ClickTrigger;
import dev.aurelium.slate.info.TemplateInfo;
import dev.aurelium.slate.function.*;

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

public class TemplateBuilder {

    private final Class contextType;
    private final Map> replacers = new HashMap<>();
    private TemplateReplacer anyReplacer = p -> null;
    private final Map> clickers = new HashMap<>();
    private TemplateModifier modifier = TemplateInfo::item;
    private DefinedContexts definedContexts = m -> new HashSet<>();
    private TemplateSlot slotProvider = t -> null;
    private MenuListener initListener = m -> {};
    private ContextListener contextListener = t -> {};

    public TemplateBuilder(Class contextType) {
        this.contextType = contextType;
    }

    public static  TemplateBuilder builder(Class type) {
        return new TemplateBuilder<>(type);
    }

    public TemplateBuilder replace(String from, TemplateReplacer replacer) {
        replacers.put(from, replacer);
        return this;
    }

    public TemplateBuilder replaceAny(TemplateReplacer replacer) {
        anyReplacer = replacer;
        return this;
    }

    public TemplateBuilder onClick(TemplateClicker clicker) {
        clickers.put(ClickTrigger.ANY, clicker);
        return this;
    }

    public TemplateBuilder onClick(ClickTrigger action, TemplateClicker clicker) {
        clickers.put(action, clicker);
        return this;
    }

    public TemplateBuilder modify(TemplateModifier modifier) {
        this.modifier = modifier;
        return this;
    }

    public TemplateBuilder definedContexts(DefinedContexts context) {
        this.definedContexts = context;
        return this;
    }

    public TemplateBuilder slotPos(TemplateSlot slot) {
        this.slotProvider = slot;
        return this;
    }

    public TemplateBuilder initialize(MenuListener listener) {
        this.initListener = listener;
        return this;
    }

    public TemplateBuilder initializeContext(ContextListener listener) {
        this.contextListener = listener;
        return this;
    }

    public BuiltTemplate build() {
        return new BuiltTemplate<>(contextType, replacers, anyReplacer, clickers, modifier, definedContexts,
                slotProvider, initListener, contextListener);
    }
    
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy