com.github.dakusui.actionunit.actions.Composite 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;
import com.github.dakusui.actionunit.core.Action;
import java.util.Collections;
import java.util.Formatter;
import java.util.List;
import static java.util.Objects.requireNonNull;
public interface Composite extends Action {
List children();
boolean isParallel();
@Override
default void formatTo(Formatter formatter, int flags, int width, int precision) {
formatter.format(
"do %s",
isParallel()
? "parallelly"
: "sequentially"
);
}
class Builder {
private boolean parallel;
private final List actions;
public Builder(List actions) {
this.actions = actions;
this.sequential();
}
public Builder parallel() {
this.parallel = true;
return this;
}
public Builder sequential() {
this.parallel = false;
return this;
}
@SuppressWarnings("unchecked")
public Composite build() {
return new Impl(actions, parallel);
}
}
class Impl implements Composite {
private final List actions;
private final boolean parallel;
protected Impl(List actions, boolean parallel) {
this.actions = requireNonNull(actions);
this.parallel = parallel;
}
@Override
public List children() {
return Collections.unmodifiableList(actions);
}
@Override
public void accept(Visitor visitor) {
visitor.visit(this);
}
@Override
public boolean isParallel() {
return this.parallel;
}
}
}