| 1 | package com.github.dakusui.actionunit.core.context.multiparams; | |
| 2 | ||
| 3 | import com.github.dakusui.actionunit.actions.ContextVariable; | |
| 4 | import com.github.dakusui.actionunit.core.Action; | |
| 5 | import com.github.dakusui.actionunit.core.Action.Visitor; | |
| 6 | import com.github.dakusui.actionunit.core.Context; | |
| 7 | ||
| 8 | import java.util.LinkedHashMap; | |
| 9 | import java.util.List; | |
| 10 | import java.util.Map; | |
| 11 | ||
| 12 | import static com.github.dakusui.actionunit.utils.Checks.requireArgument; | |
| 13 | import static com.github.dakusui.printables.PrintableFunctionals.isKeyOf; | |
| 14 | import static java.lang.String.format; | |
| 15 | import static java.util.Arrays.asList; | |
| 16 | import static java.util.Objects.requireNonNull; | |
| 17 | import static java.util.stream.Collectors.joining; | |
| 18 | ||
| 19 | /** | |
| 20 | * An interface that represents multiple-parameters as a single object for functions/predicates/consumers | |
| 21 | * that take multiple parameters in the actionunit's model. | |
| 22 | * | |
| 23 | * This interface is instantiated during the action processing procedure launched by | |
| 24 | * calling {@link com.github.dakusui.actionunit.core.Action#accept(Visitor)}. | |
| 25 | * | |
| 26 | * @see Action#accept(Visitor) | |
| 27 | * @see Visitor | |
| 28 | */ | |
| 29 | public interface Params { | |
| 30 | ||
| 31 | /** | |
| 32 | * Returns a {@link Context} object from which this object is created. | |
| 33 | * | |
| 34 | * @return A context. | |
| 35 | */ | |
| 36 | Context context(); | |
| 37 | ||
| 38 | List<ContextVariable> parameters(); | |
| 39 | ||
| 40 | /** | |
| 41 | * Throws an {@link java.util.NoSuchElementException}, if this object doesn't | |
| 42 | * hold the given `contextVariable` in it. | |
| 43 | * | |
| 44 | * @param contextVariable A variable to resolve its current value. | |
| 45 | * @param <T> The type of the variable. | |
| 46 | * @return The resolved value. | |
| 47 | */ | |
| 48 | <T> T valueOf(ContextVariable contextVariable); | |
| 49 | ||
| 50 | /** | |
| 51 | * Creates an instance of {@link Params} interface. | |
| 52 | * | |
| 53 | * @param context A context on which the variables are evaluated. | |
| 54 | * @param contextVariables Context variables. | |
| 55 | * @return An instance of this interface. | |
| 56 | */ | |
| 57 | static Params create(Context context, ContextVariable... contextVariables) { | |
| 58 |
1
1. create : replaced return value with null for com/github/dakusui/actionunit/core/context/multiparams/Params::create → KILLED |
return new Params() { |
| 59 | final Map<ContextVariable, Object> values = new LinkedHashMap<ContextVariable, Object>() {{ | |
| 60 | for (ContextVariable each : contextVariables) { | |
| 61 | this.put(each, each.resolve(context)); | |
| 62 | } | |
| 63 | }}; | |
| 64 | ||
| 65 | @Override | |
| 66 | public Context context() { | |
| 67 |
1
1. context : replaced return value with null for com/github/dakusui/actionunit/core/context/multiparams/Params$1::context → KILLED |
return context; |
| 68 | } | |
| 69 | ||
| 70 | @Override | |
| 71 | public List<ContextVariable> parameters() { | |
| 72 |
1
1. parameters : replaced return value with Collections.emptyList for com/github/dakusui/actionunit/core/context/multiparams/Params$1::parameters → KILLED |
return asList(contextVariables); |
| 73 | } | |
| 74 | ||
| 75 | @SuppressWarnings("unchecked") | |
| 76 | @Override | |
| 77 | public <T> T valueOf(ContextVariable parameterName) { | |
| 78 |
1
1. valueOf : replaced return value with null for com/github/dakusui/actionunit/core/context/multiparams/Params$1::valueOf → KILLED |
return (T) values.get(requireArgument(isKeyOf(values), requireNonNull(parameterName))); |
| 79 | } | |
| 80 | ||
| 81 | @Override | |
| 82 | public String toString() { | |
| 83 |
1
1. toString : replaced return value with "" for com/github/dakusui/actionunit/core/context/multiparams/Params$1::toString → NO_COVERAGE |
return parameters().stream() // printing purpose |
| 84 |
1
1. lambda$toString$0 : replaced return value with "" for com/github/dakusui/actionunit/core/context/multiparams/Params$1::lambda$toString$0 → NO_COVERAGE |
.map(each -> format("%s=%s", each, valueOf(each))) |
| 85 | .collect(joining(",", "[", "]")); | |
| 86 | } | |
| 87 | }; | |
| 88 | } | |
| 89 | } | |
Mutations | ||
| 58 |
1.1 |
|
| 67 |
1.1 |
|
| 72 |
1.1 |
|
| 78 |
1.1 |
|
| 83 |
1.1 |
|
| 84 |
1.1 |