From 9fba1289e34b9949da1805fe39c1f82c62720136 Mon Sep 17 00:00:00 2001 From: Johannes Theiner Date: Sat, 12 May 2018 12:24:41 +0200 Subject: [PATCH] Changes and stuff --- .../java2/praktikum/praktikum3/Vorlesung.java | 2 +- .../praktikum3/Vorlesungsverzeichnis.java | 10 ++--- .../de/joethei/hs/java2/vorlesungen/Sieb.java | 38 ---------------- .../hs/java2/vorlesungen/binaryTree/Node.java | 44 ------------------- .../hs/java2/vorlesungen/binaryTree/Tree.java | 15 ------- .../hs/java2/tests/GrosseZahlTest.java | 1 + .../hs/java2/tests/VorlesungsTest.java | 38 ---------------- 7 files changed, 7 insertions(+), 141 deletions(-) delete mode 100644 src/main/java/de/joethei/hs/java2/vorlesungen/Sieb.java delete mode 100644 src/main/java/de/joethei/hs/java2/vorlesungen/binaryTree/Node.java delete mode 100644 src/main/java/de/joethei/hs/java2/vorlesungen/binaryTree/Tree.java delete mode 100644 src/test/java/de/joethei/hs/java2/tests/VorlesungsTest.java diff --git a/src/main/java/de/joethei/hs/java2/praktikum/praktikum3/Vorlesung.java b/src/main/java/de/joethei/hs/java2/praktikum/praktikum3/Vorlesung.java index f75b5da..35cb624 100644 --- a/src/main/java/de/joethei/hs/java2/praktikum/praktikum3/Vorlesung.java +++ b/src/main/java/de/joethei/hs/java2/praktikum/praktikum3/Vorlesung.java @@ -9,7 +9,7 @@ public class Vorlesung { private int teilnehmerzahl; public Vorlesung(List list) throws TextFileFormatException { - if(list.size() <1 || list.size() > 4) throw new TextFileFormatException("invalid number of Strings in list"); + if(list.size() != 4) throw new TextFileFormatException("invalid number of Strings in list"); this.studiengruppe = list.get(0); this.title = list.get(1); this.dozent = list.get(2); diff --git a/src/main/java/de/joethei/hs/java2/praktikum/praktikum3/Vorlesungsverzeichnis.java b/src/main/java/de/joethei/hs/java2/praktikum/praktikum3/Vorlesungsverzeichnis.java index 4a9a56a..6cfc80c 100644 --- a/src/main/java/de/joethei/hs/java2/praktikum/praktikum3/Vorlesungsverzeichnis.java +++ b/src/main/java/de/joethei/hs/java2/praktikum/praktikum3/Vorlesungsverzeichnis.java @@ -28,11 +28,11 @@ public class Vorlesungsverzeichnis implements Comparator{ */ private List> load(String filename) throws IOException { List> result = new ArrayList<>(); - BufferedReader br = new BufferedReader(new FileReader(filename)); - for (String line = br.readLine(); line != null; line = br.readLine()) - result.add(Arrays.asList(line.split(":"))); - br.close(); - return result; + try(BufferedReader br = new BufferedReader(new FileReader(filename))) { + for (String line = br.readLine(); line != null; line = br.readLine()) + result.add(Arrays.asList(line.split(":"))); + return result; + } } /** diff --git a/src/main/java/de/joethei/hs/java2/vorlesungen/Sieb.java b/src/main/java/de/joethei/hs/java2/vorlesungen/Sieb.java deleted file mode 100644 index 34554f5..0000000 --- a/src/main/java/de/joethei/hs/java2/vorlesungen/Sieb.java +++ /dev/null @@ -1,38 +0,0 @@ -package de.joethei.hs.java2.vorlesungen; - -import java.util.Set; -import java.util.TreeSet; - -public class Sieb { - private int n; - - public Sieb(int n) { - this.n = n; - } - - public Set getPrimzahl() { - Set set = new TreeSet<>(); - for(int i = 2; i <= n; i++) { - set.add(i); - } - Set not = new TreeSet<>(); - int mult; - int number = 2; - do{ - mult = 2*number; - while (mult <= n) { - not.add(mult); - mult += number; - } - do { - number++; - } - while (not.contains(number)); - }while (number * number <= n); - set.removeAll(not); - - return set; - } - - -} \ No newline at end of file diff --git a/src/main/java/de/joethei/hs/java2/vorlesungen/binaryTree/Node.java b/src/main/java/de/joethei/hs/java2/vorlesungen/binaryTree/Node.java deleted file mode 100644 index 0832ef7..0000000 --- a/src/main/java/de/joethei/hs/java2/vorlesungen/binaryTree/Node.java +++ /dev/null @@ -1,44 +0,0 @@ -package de.joethei.hs.java2.vorlesungen.binaryTree; - -import java.util.logging.Logger; - -public class Node { - - private T value; - private Node left; - private Node right; - - private Logger logger = Logger.getLogger(getClass().getName()); - - public Node(T value) { - this.value = value; - } - - public Node(T value, Node left, Node right) { - this.value = value; - this.left = left; - this.right = right; - } - - public T getValue() { - return value; - } - - public Node getLeft() { - return left; - } - - public Node getRight() { - return right; - } - - @Override - public boolean equals(Object obj) { - if (obj instanceof Node) { - Node node = (Node) obj; - if(node.value.equals(this.value) && node.left == null && node.right == null) return true; - return node.value.equals(this.value) && node.left.equals(this.left) && node.right.equals(this.right); - } - return false; - } -} \ No newline at end of file diff --git a/src/main/java/de/joethei/hs/java2/vorlesungen/binaryTree/Tree.java b/src/main/java/de/joethei/hs/java2/vorlesungen/binaryTree/Tree.java deleted file mode 100644 index a594a5e..0000000 --- a/src/main/java/de/joethei/hs/java2/vorlesungen/binaryTree/Tree.java +++ /dev/null @@ -1,15 +0,0 @@ -package de.joethei.hs.java2.vorlesungen.binaryTree; - -public class Tree { - - private Node root; - - public Tree(Node root) { - this.root = root; - } - - public Node getRoot() { - return root; - } - -} \ No newline at end of file diff --git a/src/test/java/de/joethei/hs/java2/tests/GrosseZahlTest.java b/src/test/java/de/joethei/hs/java2/tests/GrosseZahlTest.java index 6c36b19..c3ec885 100644 --- a/src/test/java/de/joethei/hs/java2/tests/GrosseZahlTest.java +++ b/src/test/java/de/joethei/hs/java2/tests/GrosseZahlTest.java @@ -80,6 +80,7 @@ public class GrosseZahlTest { @Test(expected = IllegalArgumentException.class) public void wrongInput() { new GrosseZahl("42B"); + new GrosseZahl("42/"); } } \ No newline at end of file diff --git a/src/test/java/de/joethei/hs/java2/tests/VorlesungsTest.java b/src/test/java/de/joethei/hs/java2/tests/VorlesungsTest.java deleted file mode 100644 index 16397d2..0000000 --- a/src/test/java/de/joethei/hs/java2/tests/VorlesungsTest.java +++ /dev/null @@ -1,38 +0,0 @@ -package de.joethei.hs.java2.tests; - -import de.joethei.hs.java2.vorlesungen.Sieb; -import de.joethei.hs.java2.vorlesungen.binaryTree.Node; -import de.joethei.hs.java2.vorlesungen.binaryTree.Tree; -import org.junit.Test; - -import java.util.Arrays; -import java.util.Set; -import java.util.TreeSet; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertTrue; - - -public class VorlesungsTest { - - @Test - public void sieb() { - Set set = new TreeSet<>(Arrays.asList(2, 3, 5, 7, 11, 13, 17, 19)); - assertEquals(set, new Sieb(20).getPrimzahl()); - } - - @Test - public void binaryTree() { - Tree tree = new Tree<>(new Node<>(45, new Node<>(14), new Node<>(16))); - Node node = new Node<>(45, new Node<>(14), new Node<>(16)); - assertEquals(Integer.valueOf(45), tree.getRoot().getValue()); - assertEquals(Integer.valueOf(14), tree.getRoot().getLeft().getValue()); - assertEquals(Integer.valueOf(16), tree.getRoot().getRight().getValue()); - - assertEquals(tree.getRoot(), node); - - - assertNotEquals(node, "HalloWelt"); - } -} \ No newline at end of file