4 changed files with 5 additions and 167 deletions
@ -1,7 +1,10 @@ |
|||
<?xml version="1.0" encoding="UTF-8"?> |
|||
<classpath> |
|||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/> |
|||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"> |
|||
<attributes> |
|||
<attribute name="module" value="true"/> |
|||
</attributes> |
|||
</classpathentry> |
|||
<classpathentry kind="src" path="src"/> |
|||
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/5"/> |
|||
<classpathentry kind="output" path="bin"/> |
|||
</classpath> |
|||
|
@ -1,118 +0,0 @@ |
|||
package solution; |
|||
|
|||
import java.util.function.Consumer; |
|||
|
|||
import testat.ISimpleMap; |
|||
|
|||
public class SimpleArrayMap<K, V> implements ISimpleMap<K, V> { |
|||
|
|||
private K[] keys; |
|||
private V[] values; |
|||
private int size; |
|||
|
|||
public SimpleArrayMap(int arraySize) { |
|||
|
|||
this.keys = (K[]) new Object[arraySize]; |
|||
this.values = (V[]) new Object[arraySize]; |
|||
this.size = 0; |
|||
} |
|||
|
|||
@Override |
|||
public V put(K k, V v) { |
|||
|
|||
V tempValue; |
|||
|
|||
if (k == null || v == null) { |
|||
return null; |
|||
} |
|||
|
|||
for (int i = 0; i < values.length; i++) { |
|||
if (k.equals(keys[i])) { |
|||
tempValue = values[i]; |
|||
values[i] = v; |
|||
return tempValue; |
|||
} |
|||
} |
|||
|
|||
for (int i = 0; i < values.length; i++) { |
|||
if (keys[i] == null) { |
|||
keys[i] = k; |
|||
values[i] = v; |
|||
size++; |
|||
break; |
|||
} |
|||
} |
|||
|
|||
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])) { |
|||
return values[i]; |
|||
} |
|||
} |
|||
|
|||
return null; |
|||
} |
|||
|
|||
@Override |
|||
public V remove(K k) { |
|||
|
|||
V tempValue; |
|||
|
|||
if (k == null) { |
|||
return null; |
|||
} |
|||
|
|||
for (int i = 0; i < values.length; i++) { |
|||
if (k.equals(keys[i])) { |
|||
tempValue = values[i]; |
|||
keys[i] = null; |
|||
values[i] = null; |
|||
size--; |
|||
return tempValue; |
|||
} |
|||
} |
|||
|
|||
return null; |
|||
} |
|||
|
|||
@Override |
|||
public boolean contains(V v) { |
|||
|
|||
if (v == null) { |
|||
return false; |
|||
} |
|||
|
|||
for (int i = 0; i < values.length; i++) { |
|||
if (v.equals(values[i])) { |
|||
return true; |
|||
} |
|||
} |
|||
|
|||
return false; |
|||
} |
|||
|
|||
@Override |
|||
public void forEach(Consumer<? super V> consumer) { |
|||
|
|||
for (int i = 0; i < values.length; i++) { |
|||
if (keys[i] != null) { |
|||
consumer.accept(values[i]); |
|||
} |
|||
} |
|||
} |
|||
|
|||
@Override |
|||
public int size() { |
|||
return size; |
|||
} |
|||
|
|||
} |
@ -1,13 +0,0 @@ |
|||
package solution; |
|||
|
|||
import testat.ASimpleMapTest; |
|||
import testat.ISimpleMap; |
|||
|
|||
public class SimpleMapTest extends ASimpleMapTest{ |
|||
|
|||
@Override |
|||
protected ISimpleMap<String, String> getInstance() { |
|||
|
|||
return new SimpleArrayMap<>(5); |
|||
} |
|||
} |
@ -1,34 +0,0 @@ |
|||
package testat; |
|||
|
|||
import java.util.function.Consumer; |
|||
|
|||
public interface ISimpleMap<K, V> { |
|||
|
|||
// speichert zu dem Schlüssel k den Wert v, sofern beide nicht null sind
|
|||
// (ist mind. einer null, 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ückgegeben.
|
|||
// Falls zu k noch kein Wert gespeichert war, wird zu k der Wert v
|
|||
// aufgenommen und 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 ist
|
|||
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 (zu irgendeinem Schlüssel)
|
|||
// gespeichert ist
|
|||
boolean contains(V v); |
|||
|
|||
// wendet die Methode consumer.accept(v) auf alle in der
|
|||
// Map gespeicherten Werte an
|
|||
void forEach(Consumer<? super V> consumer); |
|||
|
|||
// Anzahl an in der Map gespeicherten Werte
|
|||
int size(); |
|||
} |
Loading…
Reference in new issue