BiMap est maintenant Iterable

This commit is contained in:
Marc Baloup 2016-12-25 23:34:12 +01:00
parent f37c32ea9e
commit 37593e26f8
1 changed files with 15 additions and 1 deletions

View File

@ -1,8 +1,11 @@
package fr.pandacube.java.util;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map.Entry;
import java.util.function.BiConsumer;
public class BiMap<K,V> {
public class BiMap<K, V> implements Iterable<Entry<K, V>> {
HashMap<K, V> map = new HashMap<>();
HashMap<V, K> inversedMap = new HashMap<>();
@ -43,5 +46,16 @@ public class BiMap<K,V> {
map.remove(k);
return k;
}
@Override
public Iterator<Entry<K, V>> iterator() {
return map.entrySet().iterator();
}
public synchronized void forEach(BiConsumer<K, V> c) {
for(Entry<K, V> entry : this) {
c.accept(entry.getKey(), entry.getValue());
}
}
}