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

org.requirementsascode.InterruptingFlowStep Maven / Gradle / Ivy

There is a newer version: 2.0
Show newest version
package org.requirementsascode;

import java.util.function.Predicate;

import org.requirementsascode.flowposition.FlowPosition;

public class InterruptingFlowStep extends FlowStep {
	private static final long serialVersionUID = 7204738737376844201L;

	InterruptingFlowStep(String stepName, Flow useCaseFlow, FlowPosition flowPosition, Condition condition) {
		super(stepName, useCaseFlow, condition);
		setFlowPosition(flowPosition);
	}

	public Predicate getPredicate() {
		Predicate predicate;
		Condition reactWhile = getReactWhile();

		predicate = isFlowConditionTrueAndRunnerInDifferentFlow();
		if (reactWhile != null) {
			predicate = predicate.and(toPredicate(reactWhile));
		}

		return predicate;
	}

	private Predicate isFlowConditionTrueAndRunnerInDifferentFlow() {
		Predicate flowPosition = getFlowPosition();
		Condition conditionOrElseTrue = getCondition().orElse(() -> true);

		Predicate flowCondition = isRunnerInDifferentFlow().and(flowPosition)
				.and(toPredicate(conditionOrElseTrue));
		return flowCondition;
	}

	private Predicate isRunnerInDifferentFlow() {
		Predicate isRunnerInDifferentFlow = runner -> runner.getLatestFlow()
				.map(runnerFlow -> !runnerFlow.equals(getFlow())).orElse(true);
		return isRunnerInDifferentFlow;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy