<commit_before>package org.requirementsascode.flowposition;

import java.util.ArrayList;
import java.util.List;
import java.util.function.Predicate;

import org.requirementsascode.FlowStep;
import org.requirementsascode.ModelRunner;
import org.requirementsascode.Step;
import org.requirementsascode.UseCase;

public abstract class FlowPosition implements Predicate<ModelRunner>{
  private UseCase useCase;
	private FlowStep step;
  private String stepName;
  private List<FlowStep> mergeSteps;

	protected abstract boolean isRunnerAtRightPositionFor(FlowStep step, ModelRunner modelRunner);

	public FlowPosition(String stepName, UseCase useCase) {
	  this.stepName = stepName;
	  this.useCase = useCase;
	  this.mergeSteps = new ArrayList<>();
  }

  @Override
	public final boolean test(ModelRunner modelRunner) {
    if(step == null) {
      this.step = resolveStep();
    }
    
		boolean isRunnerAtRightPositionForStepOrAfterAnyMergedStep = isRunnerAtRightPositionFor(step, modelRunner)
			|| afterAnyMergedStep(modelRunner);
		return isRunnerAtRightPositionForStepOrAfterAnyMergedStep;
	}

  public FlowStep resolveStep() {
    FlowStep flowStep = null;
    if(useCase != null && stepName != null) {
      flowStep = (FlowStep) useCase.findStep(stepName);
    }
    return flowStep;
  }

	private boolean afterAnyMergedStep(ModelRunner modelRunner) {
		boolean isAfterStep = false;
		for (FlowStep mergeStep : mergeSteps) {
			After isAfterMergeStep = new After(mergeStep.getName(), mergeStep.getUseCase());
      if(isAfterMergeStep.test(modelRunner)) {
				isAfterStep = true;
				break;
			}
		}<commit_msg>Resolve steps permanently<commit_after>package org.requirementsascode.flowposition;

import java.util.ArrayList;
import java.util.List;
import java.util.function.Predicate;

import org.requirementsascode.FlowStep;
import org.requirementsascode.ModelRunner;
import org.requirementsascode.Step;
import org.requirementsascode.UseCase;

public abstract class FlowPosition implements Predicate<ModelRunner>{
  private UseCase useCase;
	private FlowStep step;
  private String stepName;
  private List<FlowStep> mergeSteps;

	protected abstract boolean isRunnerAtRightPositionFor(FlowStep step, ModelRunner modelRunner);

	public FlowPosition(String stepName, UseCase useCase) {
	  this.stepName = stepName;
	  this.useCase = useCase;
	  this.mergeSteps = new ArrayList<>();
  }

  @Override
	public final boolean test(ModelRunner modelRunner) {
    if(step == null) {
      resolveStep();
    }
    
		boolean isRunnerAtRightPositionForStepOrAfterAnyMergedStep = isRunnerAtRightPositionFor(step, modelRunner)
			|| afterAnyMergedStep(modelRunner);
		return isRunnerAtRightPositionForStepOrAfterAnyMergedStep;
	}

  public FlowStep resolveStep() {
    FlowStep flowStep = null;
    if(useCase != null && stepName != null) {
      this.step = (FlowStep) useCase.findStep(stepName);
    }
    return flowStep;
  }

	private boolean afterAnyMergedStep(ModelRunner modelRunner) {
		boolean isAfterStep = false;
		for (FlowStep mergeStep : mergeSteps) {
			After isAfterMergeStep = new After(mergeStep.getName(), mergeStep.getUseCase());
      if(isAfterMergeStep.test(modelRunner)) {
				isAfterStep = true;
				break;
			}
		}
{'fraction_non_alphanumeric': 0.08629755644911846, 'fraction_numerical': 0.0, 'mean_word_length': 4.955801104972376, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1570521', 'n_tokens_mistral': 996, 'n_tokens_neox': 953, 'n_words': 211}