diff --git a/src/main/java/de/joethei/hs/java2/praktikum/praktikum1/GrosseZahl.java b/src/main/java/de/joethei/hs/java2/praktikum/praktikum1/GrosseZahl.java index 0e585fb..8dd116c 100644 --- a/src/main/java/de/joethei/hs/java2/praktikum/praktikum1/GrosseZahl.java +++ b/src/main/java/de/joethei/hs/java2/praktikum/praktikum1/GrosseZahl.java @@ -2,7 +2,7 @@ package de.joethei.hs.java2.praktikum.praktikum1; public class GrosseZahl { - private int zahl[]; + private int[] zahl; public GrosseZahl(String d) { Boolean korrekteEingabe=true; @@ -37,7 +37,8 @@ public class GrosseZahl { public GrosseZahl add(GrosseZahl b) { int uebertrag = 0; - GrosseZahl rueckgabe, operand; + GrosseZahl rueckgabe; + GrosseZahl operand; if(this.less(b)) { rueckgabe = new GrosseZahl(b.toString()); operand = new GrosseZahl(this.toString()); @@ -65,9 +66,7 @@ public class GrosseZahl { public GrosseZahl sub(GrosseZahl b) { int uebertrag = 0; StringBuilder x; - if(this.equals(b)) { - return new GrosseZahl(0); - } else if(this.less(b)) { + if(this.equals(b) || this.less(b)) { return new GrosseZahl(0); } GrosseZahl rueckgabe = new GrosseZahl(this.toString()); @@ -94,8 +93,11 @@ public class GrosseZahl { } public GrosseZahl mult(GrosseZahl b) { - GrosseZahl rueckgabe, rueckgabe_b, operand, operand2; - rueckgabe_b = new GrosseZahl(0); + GrosseZahl rueckgabe; + GrosseZahl result; + GrosseZahl operand; + GrosseZahl operand2; + result = new GrosseZahl(0); if(this.less(b)) { operand2 = b; operand = this; @@ -108,12 +110,12 @@ public class GrosseZahl { for(int w = 0; w list= new ArrayList<>(this.list); + ArrayList list = new ArrayList<>(this.list); boolean removeCharacterOnce = false; for(int i=0; i commands = new HashMap<>(); + static Map getCommands() { return commands; } + public static Logger getLogger() { + return logger; + } + private boolean running; public KlausurenServer(int port) { @@ -23,8 +30,8 @@ public class KlausurenServer { commands.put("test", ((writer, args) -> writer.write("Hallo Welt"))); commands.put("delall", (writer, args) -> { - data.clear(); - save(); + data.clear(); + save(); }); commands.put("put", (writer, args) -> { if (args.size() >= 3) { @@ -52,9 +59,8 @@ public class KlausurenServer { Set> result = new HashSet<>(); set.forEach((key, value) -> set.forEach((s, integers) -> { - if(!value.equals(integers)) { - if (integers.containsAll(value)) - set.remove(key); + if (!value.equals(integers) && integers.containsAll(value)) { + set.remove(key); } })); @@ -62,7 +68,7 @@ public class KlausurenServer { result.removeIf(TreeSet::isEmpty); - writer.write(result.toString().substring(1, result.toString().length()-1).replace(" ", "")); + writer.write(result.toString().substring(1, result.toString().length() - 1).replace(" ", "")); } else { writer.write("0"); } @@ -91,7 +97,7 @@ public class KlausurenServer { Runnable runnable = () -> { try { serverSocket = new ServerSocket(port); - System.out.println("waiting for clients"); + logger.info("waiting for clients"); while (running) { executorService.submit(new ClientRunnable(serverSocket.accept())); } @@ -103,10 +109,10 @@ public class KlausurenServer { } serverSocket.close(); - System.out.println("server shutdown"); + logger.info("server shutdown"); Thread.currentThread().interrupt(); } catch (IOException e) { - e.printStackTrace(); + logger.throwing("KlausurenServer", "Constructor", e.getCause()); } }; @@ -114,12 +120,12 @@ public class KlausurenServer { thread.start(); } - synchronized void load() { + private synchronized void load() { FileReader fileReader = null; try { - fileReader = new FileReader(getClass().getClassLoader().getResource("praktikum4/data.txt").getFile()); + fileReader = new FileReader(Objects.requireNonNull(getClass().getClassLoader().getResource("praktikum4/data.txt")).getFile()); } catch (FileNotFoundException e) { - e.printStackTrace(); + logger.throwing("KlausurenServer", "load", e.getCause()); } try (BufferedReader br = new BufferedReader(Objects.requireNonNull(fileReader))) { for (String line = br.readLine(); line != null; line = br.readLine()) { @@ -131,15 +137,15 @@ public class KlausurenServer { data.put(array[0], set); } } catch (IOException e) { - e.printStackTrace(); + logger.throwing("KlausurenServer", "load", e.getCause()); } } - synchronized void save() { + private synchronized void save() { FileOutputStream fileOutputStream; PrintWriter printWriter = null; try { - fileOutputStream = new FileOutputStream(getClass().getClassLoader().getResource("praktikum4/data.txt").getFile()); + fileOutputStream = new FileOutputStream(Objects.requireNonNull(getClass().getClassLoader().getResource("praktikum4/data.txt")).getFile()); printWriter = new PrintWriter(fileOutputStream); for (Map.Entry> entry : data.entrySet()) { @@ -151,7 +157,7 @@ public class KlausurenServer { } } catch (IOException e) { - e.printStackTrace(); + logger.throwing("KlausurenServer", "save", e.getCause()); } finally { assert printWriter != null; printWriter.close();