package helloworld;

import static org.requirementsascode.UseCaseModelBuilder.newBuilder;

import java.util.function.Consumer;
import java.util.function.Predicate;

import org.requirementsascode.UseCaseModel;
import org.requirementsascode.UseCaseModelBuilder;
import org.requirementsascode.UseCaseModelRunner;

public class HelloWorld02_PrintHelloUserAndHipHipHoorayThreeTimesExample {	
	
	int hoorayCounter = 0;
	
	public UseCaseModel buildWith(UseCaseModelBuilder modelBuilder) {
		UseCaseModel useCaseModel = 
			modelBuilder.useCase("Get greeted")
				.basicFlow()
					.step("S1").system(greetUser())
					.step("S2").system(printHooray())
						.reactWhile(lessThanThreeHooraysHaveBeenPrinted())
			.build();
		
		return useCaseModel;
	}

	private Consumer<UseCaseModelRunner> greetUser() {
		return r -> System.out.println("Hello, User.");
	}
	
	private Predicate<UseCaseModelRunner> lessThanThreeHooraysHaveBeenPrinted() {
		return r -> hoorayCounter < 3; 
	}
	
	private Consumer<UseCaseModelRunner> printHooray() {
		return r -> {
			System.out.println("Hip, hip, hooray!");
			hoorayCounter++;
		};
	}
	
	public static void main(String[] args){		
		HelloWorld02_PrintHelloUserAndHipHipHoorayThreeTimesExample example = new HelloWorld02_PrintHelloUserAndHipHipHoorayThreeTimesExample();
		example.start();
	}

	private void start() {
		UseCaseModelRunner useCaseModelRunner = new UseCaseModelRunner();
		UseCaseModel useCaseModel = buildWith(newBuilder());
		useCaseModelRunner.run(useCaseModel);
	}
}
@@ -88,82 +88,8 @@
 r;%0A%0A
-import java.util.function.Consumer;%0Aimport java.util.function.Predicate;%0A%0A
 impo
@@ -512,16 +512,22 @@
 .system(
+this::
 greetUse
@@ -527,18 +527,16 @@
 reetUser
-()
 )%0A%09%09%09%09%09.
@@ -553,16 +553,22 @@
 .system(
+this::
 printHoo
@@ -570,18 +570,16 @@
 ntHooray
-()
 )%0A%09%09%09%09%09%09
@@ -590,16 +590,22 @@
 ctWhile(
+this::
 lessThan
@@ -631,18 +631,16 @@
 nPrinted
-()
 )%0A%09%09%09.bu
@@ -681,33 +681,39 @@
 %7D%0A%0A%09private 
-Consumer%3C
+void greetUser(
 UseCaseModel
@@ -722,38 +722,21 @@
 nner
-%3E greetUs
+ runn
 er
-(
 ) %7B%0A%09%09
-return r -%3E 
 Syst
@@ -785,37 +785,15 @@
 ate 
-Predicate%3CUseCaseModelRunner%3E
+boolean
  les
@@ -825,16 +825,41 @@
 Printed(
+UseCaseModelRunner runner
 ) %7B%0A%09%09re
@@ -862,21 +862,16 @@
 %09%09return
- r -%3E
  hoorayC
@@ -901,17 +901,25 @@
 ate 
-Consumer%3C
+void printHooray(
 UseC
@@ -936,43 +936,19 @@
 nner
-%3E printHooray() %7B%0A%09%09return r -%3E
+ runner)
  %7B%0A
-%09
 %09%09Sy
@@ -988,17 +988,16 @@
 y!%22);%0A%09%09
-%09
 hoorayCo
@@ -1009,13 +1009,8 @@
 ++;%0A
-%09%09%7D;%0A
 %09%7D%0A%09

Refactor to use method references