BiMap est maintenant Iterable
This commit is contained in:
parent
f37c32ea9e
commit
37593e26f8
@ -1,8 +1,11 @@
|
|||||||
package fr.pandacube.java.util;
|
package fr.pandacube.java.util;
|
||||||
|
|
||||||
import java.util.HashMap;
|
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<K, V> map = new HashMap<>();
|
||||||
HashMap<V, K> inversedMap = new HashMap<>();
|
HashMap<V, K> inversedMap = new HashMap<>();
|
||||||
@ -44,4 +47,15 @@ public class BiMap<K,V> {
|
|||||||
return 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());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user