From d726ea629607be5f4a50047eea3349f335c689ac Mon Sep 17 00:00:00 2001 From: hertero Date: Thu, 1 Sep 2022 10:12:44 +0200 Subject: [PATCH] =?UTF-8?q?Zur=C3=BCcksetzen=20des=20Testats=20auf=20Anfan?= =?UTF-8?q?g?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/solution/SimpleArrayMap.java | 107 ------------------ .../src/solution/SimpleArrayMapTest.java | 13 --- SimpleArrayMap/src/testat/ISimpleMap.java | 33 ------ 3 files changed, 153 deletions(-) delete mode 100644 SimpleArrayMap/src/solution/SimpleArrayMap.java delete mode 100644 SimpleArrayMap/src/solution/SimpleArrayMapTest.java delete mode 100644 SimpleArrayMap/src/testat/ISimpleMap.java diff --git a/SimpleArrayMap/src/solution/SimpleArrayMap.java b/SimpleArrayMap/src/solution/SimpleArrayMap.java deleted file mode 100644 index 902d7fe..0000000 --- a/SimpleArrayMap/src/solution/SimpleArrayMap.java +++ /dev/null @@ -1,107 +0,0 @@ -package solution; - -import java.util.function.Consumer; - -import testat.ISimpleMap; - -public class SimpleArrayMap implements ISimpleMap { - - private int size; - private K[] keys; - private V[] values; - - public SimpleArrayMap(int maxSize) { - size = 0; - keys = (K[]) new Object[maxSize]; - values = (V[]) new Object[maxSize]; - } - - @Override - public V put(K k, V v) { - - if (k == null || v == null) { - return null; - } - for (int i = 0; i < values.length; i++) { - if (k.equals(keys[i])) { // found - V result = values[i]; - values[i] = v; - return result; - } - } - for (int i = 0; i < values.length; i++) { - if (keys[i] == null) { // empty - keys[i] = k; - values[i] = v; - size++; - return null; - } - } - return null; - } - - @Override - public V get(K k) { - if (k == null) { - return null; - } - for (int i = 0; i < values.length; i++) { - if (k.equals(keys[i])) { // found - return values[i]; - } - } - return null; - } - - @Override - public V remove(K k) { - if (k == null) { - return null; - } - for (int i = 0; i < values.length; i++) { - if (k.equals(keys[i])) { // found - V v = values[i]; - size--; - keys[i] = null; - values[i] = null; - return v; - } - } - return null; - } - - @Override - public boolean contains(V v) { - if (v == null) { - return false; - } - int counter = 0; - for (int i = 0; i < values.length; i++) { - if (v.equals(values[i])) { - return true; - } - if (values[i] != null) { - counter++; - } - if (counter == size) { - return false; - } - } - return false; - } - - @Override - public void forEach(Consumer consumer) { - for (int i = 0; i < values.length; i++) { - if (keys[i] != null) { // found - consumer.accept(values[i]); - } - } - } - - @Override - public int size() { - return size; - } - -} diff --git a/SimpleArrayMap/src/solution/SimpleArrayMapTest.java b/SimpleArrayMap/src/solution/SimpleArrayMapTest.java deleted file mode 100644 index 8cea516..0000000 --- a/SimpleArrayMap/src/solution/SimpleArrayMapTest.java +++ /dev/null @@ -1,13 +0,0 @@ -package solution; - -import testat.ASimpleMapTest; -import testat.ISimpleMap; - -public class SimpleArrayMapTest extends ASimpleMapTest { - - @Override - protected ISimpleMap getInstance() { - return new SimpleArrayMap<>(5); - } - -} diff --git a/SimpleArrayMap/src/testat/ISimpleMap.java b/SimpleArrayMap/src/testat/ISimpleMap.java deleted file mode 100644 index cb039dc..0000000 --- a/SimpleArrayMap/src/testat/ISimpleMap.java +++ /dev/null @@ -1,33 +0,0 @@ -package testat; - -import java.util.function.Consumer; - -public interface ISimpleMap { - - // speichert zu den Schlüssel k den Wert v, sofern beide nicht null sind (in - // diesem Fall wird null zurück gegeben) . - // Falls zu k bereits ein Wert w vorhanden ist, wird dieser durch v ersetzt. Der - // alte - // Wert w wird zurückgegebn. Falls zu k noch kein Wert gespeichert war, wird - // null zurückgegeben - V put(K k, V v); - - // Liefert den zum Schlüssel k gespeicherten Wert. Liefert null, falls k == - // null oder falls zu k kein Wert gespeichert war - V get(K k); - - // Entfernt den zum Schlüssel k gespeicherten Wert v und liefert v zurück. - // Liefert null, falls k == - // null oder falls zu k kein Wert gespeichert war - V remove(K k); - - // Liefert true, falls der Wert v in der Map gespeichert ist - boolean contains(V v); - - // wendet die Methode consumer.accept(v) auf alle in der Map gespeicherten Werte - // an - void forEach(Consumer consumer); - - int size(); // Anzahl an in der Map gespeicherten Werte - -}