com.github.dakusui.actionunit.actions.cmd.CommanderFactoryManager Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of actionunit Show documentation
Show all versions of actionunit Show documentation
A library to build 'action' structure for testing
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