From ae5d67017fea73b72c2ce9abe482e7a352688f30 Mon Sep 17 00:00:00 2001 From: hertero Date: Fri, 23 Sep 2022 09:55:16 +0200 Subject: [PATCH] Testat SimpleLinkedList clean --- SimpleLinkedList/.classpath | 1 - SimpleLinkedList/src/solution/ICommand.java | 6 - .../src/solution/ISimpleList.java | 54 ------- SimpleLinkedList/src/solution/Node.java | 36 ----- .../src/solution/SimpleLinkedList.java | 152 ------------------ .../src/solution/SimpleLinkedListTest.java | 9 -- 6 files changed, 258 deletions(-) delete mode 100644 SimpleLinkedList/src/solution/ICommand.java delete mode 100644 SimpleLinkedList/src/solution/ISimpleList.java delete mode 100644 SimpleLinkedList/src/solution/Node.java delete mode 100644 SimpleLinkedList/src/solution/SimpleLinkedList.java delete mode 100644 SimpleLinkedList/src/solution/SimpleLinkedListTest.java diff --git a/SimpleLinkedList/.classpath b/SimpleLinkedList/.classpath index dbe3bbf..2197894 100644 --- a/SimpleLinkedList/.classpath +++ b/SimpleLinkedList/.classpath @@ -6,6 +6,5 @@ - diff --git a/SimpleLinkedList/src/solution/ICommand.java b/SimpleLinkedList/src/solution/ICommand.java deleted file mode 100644 index b3130b8..0000000 --- a/SimpleLinkedList/src/solution/ICommand.java +++ /dev/null @@ -1,6 +0,0 @@ -package solution; - -public interface ICommand { - - void execute(E e); -} diff --git a/SimpleLinkedList/src/solution/ISimpleList.java b/SimpleLinkedList/src/solution/ISimpleList.java deleted file mode 100644 index 77837f0..0000000 --- a/SimpleLinkedList/src/solution/ISimpleList.java +++ /dev/null @@ -1,54 +0,0 @@ -package solution; - -import java.util.Collection; -import java.util.Comparator; - -public interface ISimpleList { - - // Anzahl der Elemente in der Liste - int size(); - - // fügt das Element e am Ende der Liste ein, sofern es ungleich null ist: - // Liefert true, falls ein Element eingefügt wurde (false sonst) - boolean add(E e); - - // fügt alle Elemente der Collection c ein (sofern diese nicht null sind). - boolean add(Collection c); - - // prüft, ob das Objekt o in der Liste enthalten ist (o == null führt zur - // Rückgabe false) - boolean contains(Object o); - - // entfernt das Objekt o aus der Liste // true: Ein Element wurde entfernt, - // false sonst - boolean remove(Object o); - - // Durchläuft alle Elemente der Liste und wendet command.execute auf jedes - // Element an - void forAll(ICommand command); - - // fügt das Element an der Position i ein, sofern es nicht null ist und 0 <= i - // <= Anzahl an Elementen gilt. Rückgabe true, false sonst. - default void add(int i, E e) throws IndexOutOfBoundsException { - } - - // Liefert das Element, das an Position i steht, null falls i keinen gültigen - // Index darstellt. - default E get(int i) throws IndexOutOfBoundsException { - return null; - } - - // Ersetzt das i-te Element durch e, sofern es vorhanden ist (Index gültig) - default void set(int i, E e) throws IndexOutOfBoundsException { - } - - // Löscht das i-te Element, sofern der Index gültig ist. Rückgabe true, false - // sonst. - default boolean remove(int i) { - return false; - } - - // Sortiermethode mittels Comparator - default void sort(Comparator comparator) { - } -} \ No newline at end of file diff --git a/SimpleLinkedList/src/solution/Node.java b/SimpleLinkedList/src/solution/Node.java deleted file mode 100644 index 425c5f3..0000000 --- a/SimpleLinkedList/src/solution/Node.java +++ /dev/null @@ -1,36 +0,0 @@ -package solution; - -public class Node { - private Node predecessor; // Vorgänger - private Node successor; // Nachfolger - private E payload; // Nutzlast - - //Konstruktor mit Parameter payload - public Node(E payload) { - this.payload = payload; - } - - public Node getPredecessor() { - return predecessor; - } - - public void setPredecessor(Node predecessor) { - this.predecessor = predecessor; - } - - public Node getSuccessor() { - return successor; - } - - public void setSuccessor(Node e) { - this.successor = e; - } - - public E getPayload() { - return payload; - } - - public void setPayload(E payload) { - this.payload = payload; - } -} diff --git a/SimpleLinkedList/src/solution/SimpleLinkedList.java b/SimpleLinkedList/src/solution/SimpleLinkedList.java deleted file mode 100644 index ea4bc75..0000000 --- a/SimpleLinkedList/src/solution/SimpleLinkedList.java +++ /dev/null @@ -1,152 +0,0 @@ -package solution; - -public class SimpleLinkedList extends AbstractSimpleList { - - Node firstNode; - int size; - - public SimpleLinkedList() { - firstNode = null; - size = 0; - } - - @Override - public int size() { - return size; - } - - @Override - public boolean add(E e) { - if (e == null) { - return false; - } else if (firstNode == null) { - firstNode = new Node(e); - } else { - Node currentNode = firstNode; - while (currentNode != null) { - if (currentNode.getSuccessor() == null) { - break; - } - currentNode = currentNode.getSuccessor(); - } - Node newNode = new Node(e); - currentNode.setSuccessor(newNode); - newNode.setPredecessor(currentNode); - } - - size++; - return true; - } - - @Override - public boolean remove(Object o) { - if (o == null) { - return false; - } - Node currentNode = firstNode; - while (currentNode != null) { - if (o.equals(currentNode.getPayload())) { - currentNode.setPayload(null); - size--; - return true; - } - - if (currentNode.getSuccessor() == null) { - break; - } - currentNode = currentNode.getSuccessor(); - } - return false; - } - - @Override - public boolean contains(Object o) { - if (o == null) { - return false; - } - Node currentNode = firstNode; - while (currentNode != null) { - if (o.equals(currentNode.getPayload())) { - return true; - } - - currentNode = currentNode.getSuccessor(); - } - - return false; - } - - @Override - public void forAll(ICommand command) { - if (command != null) { - Node currentNode = firstNode; - while (currentNode != null) { - command.execute(currentNode.getPayload()); - currentNode = currentNode.getSuccessor(); - } - } - } - - private Node getIndex(int i) { - - if (i < 0 || size <= i) { - return null; - } - Node currentNode = firstNode; - int currentIndex = 0; - while (currentNode != null) { - if (currentIndex >= i) { - - if (currentNode.getPayload() != null) { - return currentNode; - } - } - currentNode = currentNode.getSuccessor(); - currentIndex++; - } - return null; - } - - public E get(int i) throws IndexOutOfBoundsException { - - return getIndex(i).getPayload(); - } - - public void set(int i, E e) throws IndexOutOfBoundsException { - - getIndex(i).setPayload(e); - } - - public boolean remove(int i) throws IndexOutOfBoundsException { - - if (getIndex(i) != null) { - getIndex(i).setPayload(null); - size--; - return true; - } - return false; - } - - public void add(int i, E e) throws IndexOutOfBoundsException { - if (size == 0) { - if (i != 0) { - throw new IndexOutOfBoundsException("Index " + i + " is out of bounds!"); - } - set(0, e); - - } else if (i == size) { - add(e); - - } else if (size > 0 && i < size) { - Node newNode = new Node<>(e);// node3 - - Node tempNode = getIndex(i); // node2 - Node preTempNode = getIndex(i).getPredecessor(); // node1 - - preTempNode.setSuccessor(newNode); - newNode.setPredecessor(preTempNode); - newNode.setSuccessor(tempNode); - tempNode.setPredecessor(newNode); - } - } -} diff --git a/SimpleLinkedList/src/solution/SimpleLinkedListTest.java b/SimpleLinkedList/src/solution/SimpleLinkedListTest.java deleted file mode 100644 index 64eefcd..0000000 --- a/SimpleLinkedList/src/solution/SimpleLinkedListTest.java +++ /dev/null @@ -1,9 +0,0 @@ -package solution; - -public class SimpleLinkedListTest extends SimpleListTest90{ - - @Override - protected ISimpleList getInstance1() { - return new SimpleLinkedList<>(); - } -}