com.powsybl.computation.CommandExecution Maven / Gradle / Ivy
/**
* Copyright (c) 2016, All partners of the iTesla project (http://www.itesla-project.eu/consortium)
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
package com.powsybl.computation;
import com.google.common.collect.ImmutableMap;
import java.util.Map;
import java.util.Objects;
/**
*
* A command execution essentially defines how a {@link Command} should be executed.
* In particular, an execution number defines how many times the underlying command should be executed.
*
* For each execution, the {@link ComputationManager} should increment an execution index and request
* the corresponding argument values.
* This mechanism may be used to easily submit a number of commands which differ only by their argument.
*
* @author Geoffroy Jamgotchian
*/
public class CommandExecution {
public static Map getExecutionVariables(Map variables, CommandExecution commandExecution) {
Objects.requireNonNull(variables);
Objects.requireNonNull(commandExecution);
if (commandExecution.getOverloadedVariables() != null) {
return ImmutableMap.builder()
.putAll(variables)
.putAll(commandExecution.getOverloadedVariables())
.build();
}
return variables;
}
private final Command command;
private final int executionCount;
private final int priority;
private final Map tags;
private final Map overloadedVariables; // variables overloaded for this execution
public CommandExecution(Command command, int executionCount) {
this(command, executionCount, Integer.MAX_VALUE);
}
public CommandExecution(Command command, int executionCount, int priority) {
this(command, executionCount, priority, null);
}
public CommandExecution(Command command, int executionCount, int priority, Map tags) {
this(command, executionCount, priority, tags, null);
}
public CommandExecution(Command command, int executionCount, int priority, Map tags, Map overloadedVariables) {
this.command = Objects.requireNonNull(command, "command is null");
if (executionCount < 1) {
throw new IllegalArgumentException("execution count must be > 0");
}
this.executionCount = executionCount;
this.priority = priority;
this.tags = tags;
this.overloadedVariables = overloadedVariables;
}
public Command getCommand() {
return command;
}
public int getExecutionCount() {
return executionCount;
}
public int getPriority() {
return priority;
}
public Map getTags() {
return tags;
}
public Map getOverloadedVariables() {
return overloadedVariables;
}
}