APL/DEV 3.2/TP08/Authentification/TreeMap.java

97 lines
1.8 KiB
Java
Raw Normal View History

2023-03-07 16:14:57 +01:00
import java.util.Collection;
import java.util.Map;
import java.util.Set;
public class TreeMap<K,V> implements Map<K,V> {
private TreeNode<K,V> root;
private TreeComparator<K> comparator;
public TreeMap() {
}
public TreeComparator<K> getComparator() {
return comparator;
}
public void setComparator(TreeComparator<K> comparator) {
this.comparator = comparator;
}
@Override
public void clear() {
root = null;
}
@Override
public boolean containsKey(Object key) {
if (root == null) return false;
else return root.containsKey((K)key);
}
@Override
public boolean containsValue(Object value) {
return false;
}
@Override
public Set<Entry<K, V>> entrySet() {
return null;
}
@Override
public V get(Object key) {
if (root == null) return null;
return root.get((K)key);
}
@Override
public boolean isEmpty() {
return root == null;
}
@Override
public Set<K> keySet() {
return null;
}
@Override
public V put(K key, V value) {
if (root == null) {
root = new TreeNode<K,V>(this, key, value);
return null;
}
return root.put(key, value);
}
@Override
public void putAll(Map<? extends K, ? extends V> m) {
}
@Override
public V remove(Object key) {
if (root == null) return null;
else if (comparator.compare(root.getKey(), (K)key) == 0) {
V value = root.getValue();
root = null;
return value;
} else {
return root.remove((K)key);
}
}
@Override
public int size() {
return 0;
}
@Override
public Collection<V> values() {
return null;
}
}