All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.automatiko.engine.workflow.bpmn2.BpmnVariables Maven / Gradle / Ivy

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())));
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy