io.automatiko.engine.workflow.bpmn2.BpmnVariables Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of automatiko-workflow-bpmn2 Show documentation
Show all versions of automatiko-workflow-bpmn2 Show documentation
BPMN2 Workflow support for Automatiko Engine
The newest version!
package io.automatiko.engine.workflow.bpmn2;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import io.automatiko.engine.api.Model;
import io.automatiko.engine.workflow.base.core.context.variable.Variable;
public class BpmnVariables implements Model {
public static final Predicate OUTPUTS_ONLY = v -> v.hasTag(Variable.OUTPUT_TAG);
public static final Predicate INPUTS_ONLY = v -> v.hasTag(Variable.INPUT_TAG);
public static final Predicate INTERNAL_ONLY = v -> v.hasTag(Variable.INTERNAL_TAG);
private final Map variables = new HashMap<>();
private List definitions = new ArrayList<>();
protected BpmnVariables() {
}
protected BpmnVariables(Map variables) {
this.variables.putAll(variables);
}
protected BpmnVariables(List definitions, Map variables) {
this.definitions = definitions;
this.variables.putAll(variables);
}
public static BpmnVariables create() {
return new BpmnVariables();
}
public static BpmnVariables create(Map variables) {
return new BpmnVariables(variables);
}
public Object get(String v) {
return variables.get(v);
}
public BpmnVariables set(String v, Object o) {
variables.put(v, o);
return this;
}
public void fromMap(Map vs) {
variables.putAll(vs);
}
public List definitions() {
return definitions;
}
@Override
public Map toMap() {
return Collections.unmodifiableMap(variables);
}
public Map toMap(Predicate filter) {
return definitions.stream().filter(filter).filter(v -> variables.containsKey(v.getName()))
.collect(Collectors.toMap(v -> v.getName(), v -> variables.get(v.getName())));
}
}