[testng] 185/355: Use inheritance for collections classes
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 acff4d0df99822f580ff03b532cfba59ab4c1a9f
Author: Julien Herr <julien.herr at alcatel-lucent.com>
Date: Mon Apr 13 14:46:23 2015 +0200
Use inheritance for collections classes
---
.../java/org/testng/collections/ListMultiMap.java | 105 +--------------------
.../{SetMultiMap.java => MultiMap.java} | 36 +++----
.../java/org/testng/collections/SetMultiMap.java | 103 +-------------------
3 files changed, 24 insertions(+), 220 deletions(-)
diff --git a/src/main/java/org/testng/collections/ListMultiMap.java b/src/main/java/org/testng/collections/ListMultiMap.java
index 88d27e6..5750c84 100644
--- a/src/main/java/org/testng/collections/ListMultiMap.java
+++ b/src/main/java/org/testng/collections/ListMultiMap.java
@@ -1,115 +1,16 @@
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;
-import java.util.Set;
/**
* A container to hold lists indexed by a key.
*/
-public class ListMultiMap<K, V> {
- private final Map<K, List<V>> m_objects = Maps.newHashMap();
-
- 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);
- }
- 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());
- }
-
- public Set<K> keySet() {
- return new HashSet(m_objects.keySet());
- }
-
- public boolean containsKey(K k) {
- return m_objects.containsKey(k);
- }
+public class ListMultiMap<K, V> extends MultiMap<K, V, List<V>> {
@Override
- public String toString() {
- StringBuilder result = new StringBuilder();
- Set<K> indices = keySet();
- for (K i : indices) {
- result.append("\n ").append(i).append(" <-- ");
- for (Object o : m_objects.get(i)) {
- result.append(o).append(" ");
- }
- }
- return result.toString();
- }
-
- public boolean isEmpty() {
- 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 boolean putAll(K k, Collection<? extends V> values) {
- boolean result = false;
- for (V v : values) {
- result = put(k, v) || result;
- }
- return result;
+ protected List<V> createValue() {
+ return Lists.newArrayList();
}
@Deprecated
diff --git a/src/main/java/org/testng/collections/SetMultiMap.java b/src/main/java/org/testng/collections/MultiMap.java
similarity index 72%
copy from src/main/java/org/testng/collections/SetMultiMap.java
copy to src/main/java/org/testng/collections/MultiMap.java
index 9576bd1..c606645 100644
--- a/src/main/java/org/testng/collections/SetMultiMap.java
+++ b/src/main/java/org/testng/collections/MultiMap.java
@@ -1,35 +1,35 @@
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;
import java.util.Set;
-/**
- * A container to hold sets indexed by a key.
- */
-public class SetMultiMap<K, V> {
- private final Map<K, Set<V>> m_objects = Maps.newHashMap();
+public abstract class MultiMap<K, V, C extends Collection<V>> {
+ protected final Map<K, C> m_objects = Maps.newHashMap();
+
+ protected abstract C createValue();
public boolean put(K key, V method) {
boolean setExists = true;
- Set<V> l = m_objects.get(key);
+ C l = m_objects.get(key);
if (l == null) {
setExists = false;
- l = Sets.newHashSet();
+ l = createValue();
m_objects.put(key, l);
}
return l.add(method) && setExists;
}
- public Set<V> get(K key) {
+ public C get(K key) {
return m_objects.get(key);
}
@Deprecated
- public Set<K> getKeys() {
- return keySet();
+ public List<K> getKeys() {
+ return new ArrayList<>(keySet());
}
public Set<K> keySet() {
@@ -67,37 +67,37 @@ public class SetMultiMap<K, V> {
}
@Deprecated
- public Set<V> remove(K key) {
+ public C remove(K key) {
return removeAll(key);
}
public boolean remove(K key, V value) {
- Set<V> values = get(key);
+ C values = get(key);
if (values == null) {
return false;
}
return values.remove(value);
}
- public Set<V> removeAll(K key) {
+ public C removeAll(K key) {
return m_objects.remove(key);
}
@Deprecated
- public Set<Entry<K, Set<V>>> getEntrySet() {
+ public Set<Map.Entry<K, C>> getEntrySet() {
return entrySet();
}
- public Set<Entry<K, Set<V>>> entrySet() {
+ public Set<Map.Entry<K, C>> entrySet() {
return m_objects.entrySet();
}
@Deprecated
- public Collection<Set<V>> getValues() {
+ public Collection<C> getValues() {
return values();
}
- public Collection<Set<V>> values() {
+ public Collection<C> values() {
return m_objects.values();
}
diff --git a/src/main/java/org/testng/collections/SetMultiMap.java b/src/main/java/org/testng/collections/SetMultiMap.java
index 9576bd1..f85ba25 100644
--- a/src/main/java/org/testng/collections/SetMultiMap.java
+++ b/src/main/java/org/testng/collections/SetMultiMap.java
@@ -1,111 +1,14 @@
package org.testng.collections;
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Map.Entry;
import java.util.Set;
/**
* A container to hold sets indexed by a key.
*/
-public class SetMultiMap<K, V> {
- private final Map<K, Set<V>> m_objects = Maps.newHashMap();
-
- 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);
- }
- 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());
- }
-
- public boolean containsKey(K k) {
- return m_objects.containsKey(k);
- }
+public class SetMultiMap<K, V> extends MultiMap<K, V, Set<V>> {
@Override
- public String toString() {
- StringBuilder result = new StringBuilder();
- Set<K> indices = keySet();
- for (K i : indices) {
- result.append("\n ").append(i).append(" <-- ");
- for (Object o : m_objects.get(i)) {
- result.append(o).append(" ");
- }
- }
- return result.toString();
- }
-
- public boolean isEmpty() {
- 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 boolean putAll(K k, Collection<? extends V> values) {
- boolean result = false;
- for (V v : values) {
- result = put(k, v) || result;
- }
- return result;
+ protected Set<V> createValue() {
+ return Sets.newHashSet();
}
}
--
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