| 1 | package com.github.dakusui.actionunit.actions; | |
| 2 | ||
| 3 | import com.github.dakusui.actionunit.core.Action; | |
| 4 | import com.github.dakusui.actionunit.core.ActionSupport; | |
| 5 | import com.github.dakusui.actionunit.core.Context; | |
| 6 | ||
| 7 | import java.util.Formatter; | |
| 8 | import java.util.function.Predicate; | |
| 9 | ||
| 10 | import static java.util.Objects.requireNonNull; | |
| 11 | ||
| 12 | public interface When extends Action { | |
| 13 | Predicate<Context> cond(); | |
| 14 | ||
| 15 | Action perform(); | |
| 16 | ||
| 17 | Action otherwise(); | |
| 18 | ||
| 19 | @Override | |
| 20 | default void accept(Visitor visitor) { | |
| 21 |
1
1. accept : removed call to com/github/dakusui/actionunit/core/Action$Visitor::visit → KILLED |
visitor.visit(this); |
| 22 | } | |
| 23 | ||
| 24 | @Override | |
| 25 | default void formatTo(Formatter formatter, int flags, int width, int precision) { | |
| 26 | formatter.format("if [%s]", cond()); | |
| 27 | } | |
| 28 | ||
| 29 | class Builder extends Action.Builder<When> { | |
| 30 | private final Predicate<Context> cond; | |
| 31 | ||
| 32 | private Action otherwise = Named.of("else", ActionSupport.nop()); | |
| 33 | private Action perform; | |
| 34 | ||
| 35 | public Builder(Predicate<Context> cond) { | |
| 36 | this.cond = requireNonNull(cond); | |
| 37 | } | |
| 38 | ||
| 39 | public Builder perform(Action perform) { | |
| 40 | this.perform = Named.of("then", requireNonNull(perform)); | |
| 41 |
1
1. perform : replaced return value with null for com/github/dakusui/actionunit/actions/When$Builder::perform → KILLED |
return this; |
| 42 | } | |
| 43 | ||
| 44 | public Action otherwise(Action otherwise) { | |
| 45 | this.otherwise = Named.of("else", requireNonNull(otherwise)); | |
| 46 |
1
1. otherwise : replaced return value with null for com/github/dakusui/actionunit/actions/When$Builder::otherwise → KILLED |
return this.$(); |
| 47 | } | |
| 48 | ||
| 49 | @Override | |
| 50 | public When build() { | |
| 51 | requireNonNull(this.perform); | |
| 52 |
1
1. build : replaced return value with null for com/github/dakusui/actionunit/actions/When$Builder::build → KILLED |
return new When() { |
| 53 | @Override | |
| 54 | public Predicate<Context> cond() { | |
| 55 |
1
1. cond : replaced return value with null for com/github/dakusui/actionunit/actions/When$Builder$1::cond → KILLED |
return Builder.this.cond; |
| 56 | } | |
| 57 | ||
| 58 | @Override | |
| 59 | public Action perform() { | |
| 60 |
1
1. perform : replaced return value with null for com/github/dakusui/actionunit/actions/When$Builder$1::perform → KILLED |
return Builder.this.perform; |
| 61 | } | |
| 62 | ||
| 63 | @Override | |
| 64 | public Action otherwise() { | |
| 65 |
1
1. otherwise : replaced return value with null for com/github/dakusui/actionunit/actions/When$Builder$1::otherwise → KILLED |
return Builder.this.otherwise; |
| 66 | } | |
| 67 | }; | |
| 68 | } | |
| 69 | } | |
| 70 | } | |
Mutations | ||
| 21 |
1.1 |
|
| 41 |
1.1 |
|
| 46 |
1.1 |
|
| 52 |
1.1 |
|
| 55 |
1.1 |
|
| 60 |
1.1 |
|
| 65 |
1.1 |