package org.requirementsascode;

import java.util.Optional;
import java.util.function.Predicate;

import org.requirementsascode.predicate.Anytime;

public class ConditionalStep extends Step {
    private static final long serialVersionUID = 7204738737376844201L;

    ConditionalStep(String stepName, UseCase useCase, Flow useCaseFlow) {
	super(stepName, useCase, useCaseFlow);
    }

    public Predicate<UseCaseModelRunner> getPredicate() {
	Predicate<UseCaseModelRunner> predicate;
	Predicate<UseCaseModelRunner> reactWhile = getReactWhile();

	if (reactWhile != null) {
	    predicate = reactWhile;
	} else {
	    predicate = getFlowPredicate().get();
	}

	return predicate;
    }

    public Optional<Predicate<UseCaseModelRunner>> getFlowPredicate() {
	Anytime anytime = new Anytime();

	Predicate<UseCaseModelRunner> flowPosition = getFlowPosition().orElse(anytime);
	Predicate<UseCaseModelRunner> when = getWhen().orElse(anytime);

	Optional<Predicate<UseCaseModelRunner>> flowPredicate = Optional
		.of(isRunnerInDifferentFlow().and(flowPosition).and(when));
	return flowPredicate;
    }

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

@@ -30,35 +30,8 @@
 e;%0A%0A
-import java.util.Optional;%0A
 impo
@@ -618,16 +618,10 @@
 te()
-.get()
 ;%0A
+
 %09%7D%0A%0A
@@ -657,25 +657,16 @@
  public 
-Optional%3C
 Predicat
@@ -686,17 +686,16 @@
 lRunner%3E
-%3E
  getFlow
@@ -895,17 +895,8 @@
 ;%0A%0A%09
-Optional%3C
 Pred
@@ -920,17 +920,16 @@
 lRunner%3E
-%3E
  flowPre
@@ -941,23 +941,8 @@
 e = 
-Optional%0A%09%09.of(
 isRu
@@ -990,17 +990,16 @@
 nd(when)
-)
 ;%0A%09retur

Remove unneccesary Optional