|
|
@ -4,22 +4,45 @@ import java.util.function.Consumer; |
|
|
|
|
|
|
|
import testat.ISimpleMap; |
|
|
|
|
|
|
|
public class SimpleArrayMap<K, V> implements ISimpleMap<K, V>{ |
|
|
|
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) { |
|
|
|
// TODO Auto-generated method stub
|
|
|
|
|
|
|
|
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; |
|
|
|
} |
|
|
|
|
|
|
|