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

com.github.dakusui.actionunit.actions.cmd.CommanderFactoryManager Maven / Gradle / Ivy

There is a newer version: 6.0.1
Show newest version
package com.github.dakusui.actionunit.actions.cmd;

import java.util.function.BiFunction;
import java.util.function.Function;

import static java.util.Objects.requireNonNull;

public interface CommanderFactoryManager {
  C local();

  C remote(String host);

  class Base, C extends CommanderFactory>
      implements CommanderFactoryManager {
    final private Function           localCommanderFactory;
    final private BiFunction remoteCommanderFactory;

    public Base(Function localCommanderFactory, BiFunction remoteCommanderFactory) {
      this.localCommanderFactory = localCommanderFactory;
      this.remoteCommanderFactory = remoteCommanderFactory;
    }

    @SuppressWarnings("unchecked")
    @Override
    public C local() {
      return this.localCommanderFactory.apply((M) this);
    }

    @SuppressWarnings("unchecked")
    @Override
    public C remote(String host) {
      return this.remoteCommanderFactory.apply((M) this, host);
    }
  }

  abstract class Builder<
      B extends Builder,
      M extends CommanderFactoryManager,
      C extends CommanderFactory> {

    private Function           localCommanderFactory;
    private BiFunction remoteCommanderFactory;

    @SuppressWarnings("unchecked")
    public B localCommanderFactory(Function func) {
      this.localCommanderFactory = requireNonNull(func);
      return (B) this;
    }

    @SuppressWarnings("unchecked")
    public B remoteCommanderFactory(BiFunction func) {
      this.remoteCommanderFactory = requireNonNull(func);
      return (B) this;
    }

    public M build() {
      return createCommanderFactoryManager(localCommanderFactory, remoteCommanderFactory);
    }

    abstract protected M createCommanderFactoryManager(
        Function localCommanderFactory,
        BiFunction remoteCommanderFactory);
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy