package org.requirementsascode;

import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.function.Predicate;

public class UseCase extends UseCaseModelElement{
	private Map<String, UseCaseFlow> nameToFlowMap;
	private Map<String, UseCaseStep> nameToStepMap;
	private UseCaseFlow basicFlow;

	UseCase(String name, UseCaseModel useCaseModel) {
		super(name, useCaseModel);
		this.nameToFlowMap = new LinkedHashMap<>();
		this.nameToStepMap = new LinkedHashMap<>();
		this.basicFlow = newFlow("Basic Flow");
	} 

	public UseCaseFlow basicFlow() {
		return basicFlow;
	}
	
	public boolean hasFlow(String flowName) {		
		boolean hasFlow = UseCaseModel.hasModelElement(flowName, nameToFlowMap);
		return hasFlow;
	}
	
	public UseCaseFlow newFlow(String flowName) {
		Objects.requireNonNull(flowName);
 
		UseCaseFlow flow = new UseCaseFlow(flowName, this);
		UseCaseModel.saveModelElement(flow, nameToFlowMap);
		return flow;
	}
	
	public Optional<UseCaseFlow> findFlow(String flowName) {
		Optional<UseCaseFlow> flow = UseCaseModel.findModelElement(flowName, nameToFlowMap);
		return flow;
	}
	
	public List<UseCaseFlow> getFlows() {
		return UseCaseModel.getModelElements(nameToFlowMap);
	}
	
	public boolean hasStep(String stepName) {
		boolean hasStep = UseCaseModel.hasModelElement(stepName, nameToStepMap);		
		return hasStep;
	}
	
	public Optional<UseCaseStep> findStep(String stepName) {
		Optional<UseCaseStep> step = UseCaseModel.findModelElement(stepName, nameToStepMap);
		return step;
	}
	
	UseCaseStep newStep(String stepName, UseCaseFlow flow, Optional<UseCaseStep> previousStep, Predicate<UseCaseRunner> predicate) {
		UseCaseStep newStep = new UseCaseStep(stepName, flow, previousStep, predicate);
		UseCaseModel.saveModelElement(newStep, nameToStepMap);
		return newStep;
	}

	public List<UseCaseStep> getSteps() {
		return UseCaseModel.getModelElements(nameToStepMap);
	}
}
@@ -107,34 +107,8 @@
 ap;%0A
-import java.util.Objects;%0A
 impo
@@ -762,32 +762,175 @@
 n hasFlow;%0A%09%7D%0A%09%0A
+%09public boolean hasStep(String stepName) %7B%0A%09%09boolean hasStep = UseCaseModel.hasModelElement(stepName, nameToStepMap);%09%09%0A%09%09return hasStep;%0A%09%7D%0A%09%0A
 %09public UseCaseF
@@ -964,46 +964,8 @@
 ) %7B%0A
-%09%09Objects.requireNonNull(flowName);%0A %0A
 %09%09Us
@@ -1093,76 +1093,45 @@
 %0A%09%0A%09
-public Optional%3CUseCaseFlow%3E findFlow(String flowName) %7B%0A%09%09Optional%3C
+UseCaseStep newStep(String stepName, 
 UseC
@@ -1141,141 +1141,170 @@
 Flow
-%3E
  flow
- = UseCaseModel.findModelElement(flowName, nameToFlowMap);%0A%09%09return flow;%0A%09%7D%0A%09%0A%09public List%3CUseCaseFlow%3E getFlows() %7B%0A%09%09return 
+, Optional%3CUseCaseStep%3E previousStep, Predicate%3CUseCaseRunner%3E predicate) %7B%0A%09%09UseCaseStep step = new UseCaseStep(stepName, flow, previousStep, predicate);%0A%09%09
 UseC
@@ -1304,35 +1304,36 @@
 %0A%09%09UseCaseModel.
-get
+save
 ModelElements(na
@@ -1332,62 +1332,97 @@
 ment
-s
 (
+step, 
 nameTo
-Flow
+Step
 Map);%0A%09
-%7D%0A%09%0A%09public boolean hasStep
+%09return step;%0A%09%7D%0A%09%0A%09public Optional%3CUseCaseFlow%3E findFlow
 (String 
 step
@@ -1409,36 +1409,36 @@
 findFlow(String 
-step
+flow
 Name) %7B%0A%09%09boolea
@@ -1427,39 +1427,50 @@
 owName) %7B%0A%09%09
-boolean hasStep
+Optional%3CUseCaseFlow%3E flow
  = UseCaseMo
@@ -1465,35 +1465,36 @@
  = UseCaseModel.
-has
+find
 ModelElement(ste
@@ -1482,36 +1482,36 @@
 indModelElement(
-step
+flow
 Name, nameToStep
@@ -1502,35 +1502,33 @@
 Name, nameTo
-Step
+Flow
 Map);
-%09%09
 %0A%09%09return ha
@@ -1517,39 +1517,36 @@
 wMap);%0A%09%09return 
-hasStep
+flow
 ;%0A%09%7D%0A%09%0A%09public O
@@ -1706,221 +1706,55 @@
 %0A%09%0A%09
-UseCaseStep newStep(String stepName, UseCaseFlow flow, Optional%3CUseCaseStep%3E previousStep, Predicate%3CUseCaseRunner%3E predicate) %7B%0A%09%09UseCaseStep newStep = new UseCaseStep(stepName, flow, previousStep, predicate);%0A%09%09
+public List%3CUseCaseFlow%3E getFlows() %7B%0A%09%09return 
 UseC
@@ -1754,36 +1754,35 @@
 rn UseCaseModel.
-save
+get
 ModelElement(new
@@ -1781,55 +1781,30 @@
 ment
+s
 (n
-ewStep, nameToStepMap);%0A%09%09return newStep
+ameToFlowMap)
 ;%0A%09%7D%0A
+%09
 %0A%09pu

Restructure Use Case