add useful method to get a->b pairs out

This commit is contained in:
Terence Parr 2012-02-26 15:55:46 -08:00
parent 41be88dcd5
commit e9a3de645a
1 changed files with 12 additions and 0 deletions

View File

@ -29,6 +29,8 @@
package org.antlr.v4.runtime.misc;
import com.sun.tools.javac.util.Pair;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
@ -42,4 +44,14 @@ public class MultiMap<K, V> extends LinkedHashMap<K, List<V>> {
}
elementsForKey.add(value);
}
public List<Pair<K,V>> getPairs() {
List<Pair<K,V>> pairs = new ArrayList<Pair<K,V>>();
for (K key : keySet()) {
for (V value : get(key)) {
pairs.add(new Pair<K,V>(key, value));
}
}
return pairs;
}
}