APL/DEV 3.2/TP06/Hachage/Hachage.java

103 lines
2.1 KiB
Java
Raw Normal View History

2022-11-17 16:20:15 +01:00
import java.util.Collection;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Map;
import java.util.Set;
public class Hachage<K, V> implements Map<K, V> {
LinkedList<Map.Entry<K, V>> list;
public Hachage() {
list = new LinkedList<>();
}
@Override
public void clear() {
list.clear();
}
@Override
public boolean containsKey(Object key) {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean containsValue(Object value) {
// TODO Auto-generated method stub
return false;
}
@Override
public Set<Entry<K, V>> entrySet() {
// TODO Auto-generated method stub
return null;
}
@Override
public V get(Object key) {
for (Map.Entry<K, V> entry : list) {
if (key.equals(entry.getKey())) {
return entry.getValue();
}
}
return null;
}
@Override
public boolean isEmpty() {
// TODO Auto-generated method stub
return false;
}
@Override
public Set<K> keySet() {
Set<K> set = new HashSet<>(list.size());
for (Entry<K, V> entry : list) {
set.add(entry.getKey());
}
return set;
}
@Override
public V put(K key, V value) {
for (Map.Entry<K, V> entry : list) {
if (key.equals(entry.getKey())) {
V oldValue = entry.getValue();
entry.setValue(value);
return oldValue;
}
}
list.add(new Entree<K, V>(key ,value));
return null;
}
@Override
public void putAll(Map<? extends K, ? extends V> m) {
// TODO Auto-generated method stub
}
@Override
public V remove(Object key) {
// TODO Auto-generated method stub
return null;
}
@Override
public int size() {
return list.size();
}
@Override
public Collection<V> values() {
// TODO Auto-generated method stub
return null;
}
}