changeset 208:5207ecad8a4e

Implement Multimap.putAll().
author shade
date Wed, 23 Oct 2013 20:02:07 +0400
parents f46ab6671746
children 1d5924d127bc
files jmh-core/src/main/java/org/openjdk/jmh/util/internal/HashMultimap.java jmh-core/src/main/java/org/openjdk/jmh/util/internal/HashsetMultimap.java jmh-core/src/main/java/org/openjdk/jmh/util/internal/Multimap.java jmh-core/src/main/java/org/openjdk/jmh/util/internal/TreeMultimap.java jmh-core/src/main/java/org/openjdk/jmh/util/internal/TreesetMultimap.java
diffstat 5 files changed, 47 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/jmh-core/src/main/java/org/openjdk/jmh/util/internal/HashMultimap.java	Wed Oct 23 15:58:20 2013 +0400
+++ b/jmh-core/src/main/java/org/openjdk/jmh/util/internal/HashMultimap.java	Wed Oct 23 20:02:07 2013 +0400
@@ -50,6 +50,16 @@
     }
 
     @Override
+    public void putAll(K key, Collection<V> vvs) {
+        Collection<V> vs = map.get(key);
+        if (vs == null) {
+            vs = new ArrayList<V>();
+            map.put(key, vs);
+        }
+        vs.addAll(vvs);
+    }
+
+    @Override
     public Collection<V> get(K key) {
         Collection<V> vs = map.get(key);
         return (vs == null) ? Collections.<V>emptyList() : Collections.unmodifiableCollection(vs);
--- a/jmh-core/src/main/java/org/openjdk/jmh/util/internal/HashsetMultimap.java	Wed Oct 23 15:58:20 2013 +0400
+++ b/jmh-core/src/main/java/org/openjdk/jmh/util/internal/HashsetMultimap.java	Wed Oct 23 20:02:07 2013 +0400
@@ -51,6 +51,16 @@
     }
 
     @Override
+    public void putAll(K key, Collection<V> values) {
+        Collection<V> vs = map.get(key);
+        if (vs == null) {
+            vs = new HashSet<V>();
+            map.put(key, vs);
+        }
+        vs.addAll(values);
+    }
+
+    @Override
     public Collection<V> get(K key) {
         Collection<V> vs = map.get(key);
         return (vs == null) ? Collections.<V>emptyList() : Collections.unmodifiableCollection(vs);
--- a/jmh-core/src/main/java/org/openjdk/jmh/util/internal/Multimap.java	Wed Oct 23 15:58:20 2013 +0400
+++ b/jmh-core/src/main/java/org/openjdk/jmh/util/internal/Multimap.java	Wed Oct 23 20:02:07 2013 +0400
@@ -44,6 +44,13 @@
     void put(K key, V value);
 
     /**
+     * Put multiple pairs.
+     * @param k key
+     * @param vs values
+     */
+    void putAll(K k, Collection<V> vs);
+
+    /**
      * Get all values associated with the key
      * @param key key
      * @return collection of values
--- a/jmh-core/src/main/java/org/openjdk/jmh/util/internal/TreeMultimap.java	Wed Oct 23 15:58:20 2013 +0400
+++ b/jmh-core/src/main/java/org/openjdk/jmh/util/internal/TreeMultimap.java	Wed Oct 23 20:02:07 2013 +0400
@@ -50,6 +50,16 @@
     }
 
     @Override
+    public void putAll(K key, Collection<V> vvs) {
+        Collection<V> vs = map.get(key);
+        if (vs == null) {
+            vs = new ArrayList<V>();
+            map.put(key, vs);
+        }
+        vs.addAll(vvs);
+    }
+
+    @Override
     public Collection<V> get(K key) {
         Collection<V> vs = map.get(key);
         return (vs == null) ? Collections.<V>emptyList() : Collections.unmodifiableCollection(vs);
--- a/jmh-core/src/main/java/org/openjdk/jmh/util/internal/TreesetMultimap.java	Wed Oct 23 15:58:20 2013 +0400
+++ b/jmh-core/src/main/java/org/openjdk/jmh/util/internal/TreesetMultimap.java	Wed Oct 23 20:02:07 2013 +0400
@@ -51,6 +51,16 @@
     }
 
     @Override
+    public void putAll(K key, Collection<V> values) {
+        Collection<V> vs = map.get(key);
+        if (vs == null) {
+            vs = new TreeSet<V>();
+            map.put(key, vs);
+        }
+        vs.addAll(values);
+    }
+
+    @Override
     public Collection<V> get(K key) {
         Collection<V> vs = map.get(key);
         return (vs == null) ? Collections.<V>emptyList() : Collections.unmodifiableCollection(vs);