[testng] 183/355: Fit with Java and/or Guava API

Eugene Zhukov eugene-guest at moszumanska.debian.org
Tue Aug 18 10:20:03 UTC 2015


This is an automated email from the git hooks/post-receive script.

eugene-guest pushed a commit to annotated tag OpenBSD
in repository testng.

commit 5f1174b27ba59ecbba6a5498cad5369f1d95bb97
Author: Julien Herr <julien.herr at alcatel-lucent.com>
Date:   Mon Apr 13 14:12:09 2015 +0200

    Fit with Java and/or Guava API
---
 .../java/org/testng/collections/ListMultiMap.java  | 52 +++++++++++++++++++---
 .../java/org/testng/collections/SetMultiMap.java   | 49 +++++++++++++++++---
 2 files changed, 88 insertions(+), 13 deletions(-)

diff --git a/src/main/java/org/testng/collections/ListMultiMap.java b/src/main/java/org/testng/collections/ListMultiMap.java
index c2ff651..1c7a8b2 100644
--- a/src/main/java/org/testng/collections/ListMultiMap.java
+++ b/src/main/java/org/testng/collections/ListMultiMap.java
@@ -3,6 +3,7 @@ package org.testng.collections;
 
 import java.util.ArrayList;
 import java.util.Collection;
+import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
@@ -12,23 +13,30 @@ import java.util.Set;
  * A container to hold lists indexed by a key.
  */
 public class ListMultiMap<K, V> {
-  private Map<K, List<V>> m_objects = Maps.newHashMap();
+  private final Map<K, List<V>> m_objects = Maps.newHashMap();
 
-  public void put(K key, V method) {
+  public boolean put(K key, V method) {
+    boolean setExists = true;
     List<V> l = m_objects.get(key);
     if (l == null) {
+      setExists = false;
       l = Lists.newArrayList();
       m_objects.put(key, l);
     }
-    l.add(method);
+    return l.add(method) && setExists;
   }
 
   public List<V> get(K key) {
     return m_objects.get(key);
   }
 
+  @Deprecated
   public List<K> getKeys() {
-    return new ArrayList(m_objects.keySet());
+    return new ArrayList<>(m_objects.keySet());
+  }
+
+  public Set<K> keySet() {
+    return new HashSet(m_objects.keySet());
   }
 
   public boolean containsKey(K k) {
@@ -38,7 +46,7 @@ public class ListMultiMap<K, V> {
   @Override
   public String toString() {
     StringBuilder result = new StringBuilder();
-    List<K> indices = getKeys();
+    Set<K> indices = keySet();
     for (K i : indices) {
       result.append("\n    ").append(i).append(" <-- ");
       for (Object o : m_objects.get(i)) {
@@ -52,26 +60,56 @@ public class ListMultiMap<K, V> {
     return m_objects.size() == 0;
   }
 
+  @Deprecated
   public int getSize() {
+    return size();
+  }
+
+  public int size() {
     return m_objects.size();
   }
 
+  @Deprecated
   public List<V> remove(K key) {
+    return removeAll(key);
+  }
+
+  public boolean remove(K key, V value) {
+    List<V> values = get(key);
+    if (values == null) {
+      return false;
+    }
+    return values.remove(value);
+  }
+
+  public List<V> removeAll(K key) {
     return m_objects.remove(key);
   }
 
+  @Deprecated
   public Set<Entry<K, List<V>>> getEntrySet() {
+    return entrySet();
+  }
+
+  public Set<Entry<K, List<V>>> entrySet() {
     return m_objects.entrySet();
   }
 
+  @Deprecated
   public Collection<List<V>> getValues() {
+    return values();
+  }
+
+  public Collection<List<V>> values() {
     return m_objects.values();
   }
 
-  public void putAll(K k, Collection<V> values) {
+  public boolean putAll(K k, Collection<? extends V> values) {
+    boolean result = false;
     for (V v : values) {
-      put(k, v);
+      result = put(k, v) || result;
     }
+    return result;
   }
 
   public static <K, V> ListMultiMap<K, V> create() {
diff --git a/src/main/java/org/testng/collections/SetMultiMap.java b/src/main/java/org/testng/collections/SetMultiMap.java
index 44bae95..9576bd1 100644
--- a/src/main/java/org/testng/collections/SetMultiMap.java
+++ b/src/main/java/org/testng/collections/SetMultiMap.java
@@ -10,22 +10,29 @@ import java.util.Set;
  * A container to hold sets indexed by a key.
  */
 public class SetMultiMap<K, V> {
-  private Map<K, Set<V>> m_objects = Maps.newHashMap();
+  private final Map<K, Set<V>> m_objects = Maps.newHashMap();
 
-  public void put(K key, V method) {
+  public boolean put(K key, V method) {
+    boolean setExists = true;
     Set<V> l = m_objects.get(key);
     if (l == null) {
+      setExists = false;
       l = Sets.newHashSet();
       m_objects.put(key, l);
     }
-    l.add(method);
+    return l.add(method) && setExists;
   }
 
   public Set<V> get(K key) {
     return m_objects.get(key);
   }
 
+  @Deprecated
   public Set<K> getKeys() {
+    return keySet();
+  }
+
+  public Set<K> keySet() {
     return new HashSet(m_objects.keySet());
   }
 
@@ -36,7 +43,7 @@ public class SetMultiMap<K, V> {
   @Override
   public String toString() {
     StringBuilder result = new StringBuilder();
-    Set<K> indices = getKeys();
+    Set<K> indices = keySet();
     for (K i : indices) {
       result.append("\n    ").append(i).append(" <-- ");
       for (Object o : m_objects.get(i)) {
@@ -50,25 +57,55 @@ public class SetMultiMap<K, V> {
     return m_objects.size() == 0;
   }
 
+  @Deprecated
   public int getSize() {
+    return size();
+  }
+
+  public int size() {
     return m_objects.size();
   }
 
+  @Deprecated
   public Set<V> remove(K key) {
+    return removeAll(key);
+  }
+
+  public boolean remove(K key, V value) {
+    Set<V> values = get(key);
+    if (values == null) {
+      return false;
+    }
+    return values.remove(value);
+  }
+
+  public Set<V> removeAll(K key) {
     return m_objects.remove(key);
   }
 
+  @Deprecated
   public Set<Entry<K, Set<V>>> getEntrySet() {
+    return entrySet();
+  }
+
+  public Set<Entry<K, Set<V>>> entrySet() {
     return m_objects.entrySet();
   }
 
+  @Deprecated
   public Collection<Set<V>> getValues() {
+    return values();
+  }
+
+  public Collection<Set<V>> values() {
     return m_objects.values();
   }
 
-  public void putAll(K k, Collection<V> values) {
+  public boolean putAll(K k, Collection<? extends V> values) {
+    boolean result = false;
     for (V v : values) {
-      put(k, v);
+      result = put(k, v) || result;
     }
+    return result;
   }
 }

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-java/testng.git



More information about the pkg-java-commits mailing list