From fc2df137900297cfd49a96845ef80135e5321153 Mon Sep 17 00:00:00 2001 From: Leonardo Brandenberger Date: Thu, 11 Nov 2021 22:10:33 +0100 Subject: [PATCH] added error method missing text and implemented indexOutput and print to throw it when empty --- src/TextOutput.java | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/TextOutput.java b/src/TextOutput.java index 4b5c46e..2d32977 100644 --- a/src/TextOutput.java +++ b/src/TextOutput.java @@ -14,7 +14,10 @@ public class TextOutput { * @param text the ArrayList which is then formatted into the desired output. */ public void print(ArrayList text) { - if (formatRaw) { + if(text.size() == 0) { + errorMissingText(); + } + else if (formatRaw) { printFormated(text); } else { toFormat(text); @@ -112,8 +115,13 @@ public class TextOutput { * @param index ArrayList with words and in which part they have */ public void indexOutput(ArrayList index) { - for (String word : index) { - System.out.println(word); + if(index.size() == 0) { + errorMissingText(); + } + else { + for (String word : index) { + System.out.println(word); + } } } @@ -130,4 +138,11 @@ public class TextOutput { public void errorInvalidCommand() { System.err.println("Invalid Command"); } + + /** + * Method to give out the Error "Missing Text". + */ + public void errorMissingText() { + System.err.println("Missing Text"); + } }