From 37593e26f843cdac597f081ee1c4cd18b54568ee Mon Sep 17 00:00:00 2001 From: Marc Baloup Date: Sun, 25 Dec 2016 23:34:12 +0100 Subject: [PATCH] BiMap est maintenant Iterable --- src/main/java/fr/pandacube/java/util/BiMap.java | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/main/java/fr/pandacube/java/util/BiMap.java b/src/main/java/fr/pandacube/java/util/BiMap.java index b78684f..18d5e0e 100644 --- a/src/main/java/fr/pandacube/java/util/BiMap.java +++ b/src/main/java/fr/pandacube/java/util/BiMap.java @@ -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 { +public class BiMap implements Iterable> { HashMap map = new HashMap<>(); HashMap inversedMap = new HashMap<>(); @@ -43,5 +46,16 @@ public class BiMap { map.remove(k); return k; } + + @Override + public Iterator> iterator() { + return map.entrySet().iterator(); + } + + public synchronized void forEach(BiConsumer c) { + for(Entry entry : this) { + c.accept(entry.getKey(), entry.getValue()); + } + } }