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

com.cookingfox.lapasse.impl.facade.LaPasseFacadeDelegate Maven / Gradle / Ivy

There is a newer version: 0.5.6
Show newest version
package com.cookingfox.lapasse.impl.facade;

import com.cookingfox.lapasse.api.command.Command;
import com.cookingfox.lapasse.api.command.handler.CommandHandler;
import com.cookingfox.lapasse.api.command.logging.CommandLogger;
import com.cookingfox.lapasse.api.event.Event;
import com.cookingfox.lapasse.api.event.handler.EventHandler;
import com.cookingfox.lapasse.api.event.logging.EventLogger;
import com.cookingfox.lapasse.api.facade.Facade;
import com.cookingfox.lapasse.api.logging.CombinedLogger;
import com.cookingfox.lapasse.api.state.State;
import com.cookingfox.lapasse.api.state.observer.OnStateChanged;

import java.util.Objects;
import java.util.concurrent.ExecutorService;

/**
 * Delegates all {@link Facade} operations to a provided instance.
 */
public class LaPasseFacadeDelegate implements Facade {

    /**
     * The facade instance to use as delegate.
     */
    protected final Facade facade;

    //----------------------------------------------------------------------------------------------
    // CONSTRUCTOR
    //----------------------------------------------------------------------------------------------

    public LaPasseFacadeDelegate(Facade facade) {
        this.facade = Objects.requireNonNull(facade, "Facade can not be null");
    }

    //----------------------------------------------------------------------------------------------
    // COMBINED LOGGER AWARE
    //----------------------------------------------------------------------------------------------

    @Override
    public void addLogger(CombinedLogger logger) {
        facade.addLogger(logger);
    }

    @Override
    public void removeLogger(CombinedLogger logger) {
        facade.removeLogger(logger);
    }

    //----------------------------------------------------------------------------------------------
    // COMMAND BUS
    //----------------------------------------------------------------------------------------------

    @Override
    public void addCommandLogger(CommandLogger logger) {
        facade.addCommandLogger(logger);
    }

    @Override
    public void handleCommand(Command command) {
        facade.handleCommand(command);
    }

    @Override
    public  void mapCommandHandler(Class commandClass, CommandHandler commandHandler) {
        facade.mapCommandHandler(commandClass, commandHandler);
    }

    @Override
    public void removeCommandLogger(CommandLogger logger) {
        facade.removeCommandLogger(logger);
    }

    @Override
    public void setCommandHandlerExecutor(ExecutorService executor) {
        facade.setCommandHandlerExecutor(executor);
    }

    //----------------------------------------------------------------------------------------------
    // DISPOSABLE
    //----------------------------------------------------------------------------------------------

    @Override
    public void dispose() {
        facade.dispose();
    }

    //----------------------------------------------------------------------------------------------
    // EVENT BUS
    //----------------------------------------------------------------------------------------------

    @Override
    public void addEventLogger(EventLogger logger) {
        facade.addEventLogger(logger);
    }

    @Override
    public void handleEvent(Event event) {
        facade.handleEvent(event);
    }

    @Override
    public  void mapEventHandler(Class eventClass, EventHandler eventHandler) {
        facade.mapEventHandler(eventClass, eventHandler);
    }

    @Override
    public void removeEventLogger(EventLogger logger) {
        facade.removeEventLogger(logger);
    }

    //----------------------------------------------------------------------------------------------
    // STATE OBSERVER
    //----------------------------------------------------------------------------------------------

    @Override
    public void addStateChangedListener(OnStateChanged listener) {
        facade.addStateChangedListener(listener);
    }

    @Override
    public S getCurrentState() {
        return facade.getCurrentState();
    }

    @Override
    public void removeStateChangedListener(OnStateChanged listener) {
        facade.removeStateChangedListener(listener);
    }

}