From 39dbf2d08c82121fcbbdadc3c86e9f987f233e65 Mon Sep 17 00:00:00 2001
From: Daniel Schmidt <dschmidt@weluse.de>
Date: Thu, 26 Nov 2015 13:18:48 +0100
Subject: [PATCH] added demo code

---
 NeoSuit/src/main/java/ui/MainScene.java | 25 +++++++++++++++++++++++--
 1 file changed, 23 insertions(+), 2 deletions(-)

diff --git a/NeoSuit/src/main/java/ui/MainScene.java b/NeoSuit/src/main/java/ui/MainScene.java
index ac08875..6635398 100644
--- a/NeoSuit/src/main/java/ui/MainScene.java
+++ b/NeoSuit/src/main/java/ui/MainScene.java
@@ -18,8 +18,28 @@ public class MainScene extends Control {
 	TextArea parallelCodeField;
 
 	private void setDemoText() {
-		currentCodeField.setText("# TODO: Put non parallel some code here");
-		parallelCodeField.setText("# TODO: put some parallel code here");
+		String current = "\n"
+				+ "public List<Output> processInputs(List<Input> inputs) throws InterruptedException, ExecutionException {\n"
+				+ "\t List<Output> outputs = new ArrayList<Output>();\n" + "\t for (Input input : inputs) {\n"
+				+ "\t\t Output result = 42; /* process your input here and compute the output */ \n"
+				+ "\t\t outputs.add(result);\n" + "\t } \n" + "\t return outputs; \n" + "}";
+
+		String parallel = "\n"
+				+ "public List<Output> processInputs(List<Input> inputs) throws InterruptedException, ExecutionException {\n"
+				+ "\t int threads = Runtime.getRuntime().availableProcessors();\n"
+				+ "\t ExecutorService service = Executors.newFixedThreadPool(threads);\n" + "\n"
+				+ "\t List<Future<Output>> futures = new ArrayList<Future<Output>>();\n"
+				+ "\t for (final Input input : inputs) {\n"
+				+ "\t\t Callable<Output> callable = new Callable<Output>() {\n"
+				+ "\t\t\t public Output call() throws Exception {\n" + "\t\t\t\t Output output = new Output();\n"
+				+ "\t\t\t\t // process your input here and compute the output\n" + "\t\t\t\t return output;\n"
+				+ "\t\t\t }\n" + "\t\t };\n" + "\t\t futures.add(service.submit(callable));\n" + "\t }\n"
+				+ "\t service.shutdown();\n" + "\n" + "\t List<Output> outputs = new ArrayList<Output>();\n"
+				+ "\t for (Future<Output> future : futures) {\n" + "\t\t outputs.add(future.get());\n" + "\t } \n"
+				+ "\t return outputs; \n" + "}";
+
+		currentCodeField.setText(current);
+		parallelCodeField.setText(parallel);
 	}
 
 	@FXML
@@ -36,6 +56,7 @@ public class MainScene extends Control {
 
 	@FXML
 	private void handleStartAction(ActionEvent event) {
+		setDemoText();
 		progressBar.setProgress(0.9);
 	}
 
-- 
GitLab