Author: pete.muir(a)jboss.org
Date: 2009-04-05 09:03:52 -0400 (Sun, 05 Apr 2009)
New Revision: 2301
Modified:
ri/trunk/impl/src/main/java/org/jboss/webbeans/util/collections/multi/ConcurrentSetHashMultiMap.java
ri/trunk/impl/src/main/java/org/jboss/webbeans/util/collections/multi/ConcurrentSetMultiMap.java
ri/trunk/impl/src/main/java/org/jboss/webbeans/util/collections/multi/SetMultiMap.java
Log:
Stronger Set semantics
Modified:
ri/trunk/impl/src/main/java/org/jboss/webbeans/util/collections/multi/ConcurrentSetHashMultiMap.java
===================================================================
---
ri/trunk/impl/src/main/java/org/jboss/webbeans/util/collections/multi/ConcurrentSetHashMultiMap.java 2009-04-05
12:54:49 UTC (rev 2300)
+++
ri/trunk/impl/src/main/java/org/jboss/webbeans/util/collections/multi/ConcurrentSetHashMultiMap.java 2009-04-05
13:03:52 UTC (rev 2301)
@@ -15,37 +15,38 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+import java.util.Collections;
+import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
+import java.util.concurrent.CopyOnWriteArraySet;
-import org.jboss.webbeans.util.collections.ConcurrentCollection;
-import org.jboss.webbeans.util.collections.ConcurrentList;
import org.jboss.webbeans.util.collections.ForwardingConcurrentMap;
/**
* An concurrent multimap which is internally backed by a a ConcurrentHashMap
- * and a CopyOnWriteArrayList
+ * and a CopyOnWriteArraySet
*
* @author Pete Muir
*/
-public class ConcurrentSetHashMultiMap<K, V> extends ForwardingConcurrentMap<K,
ConcurrentCollection<V>> implements ConcurrentSetMultiMap<K, V>
+public class ConcurrentSetHashMultiMap<K, V> extends ForwardingConcurrentMap<K,
Set<V>> implements ConcurrentSetMultiMap<K, V>
{
- private final ConcurrentCollection<V> EMPTY_COLLECTION =
ConcurrentList.emptyList();
+ private final Set<V> EMPTY_COLLECTION = Collections.emptySet();
// The map delegate
- private ConcurrentMap<K, ConcurrentCollection<V>> delegate;
+ private ConcurrentMap<K, Set<V>> delegate;
/**
* Constructor.
*/
public ConcurrentSetHashMultiMap()
{
- delegate = new ConcurrentHashMap<K, ConcurrentCollection<V>>();
+ delegate = new ConcurrentHashMap<K, Set<V>>();
}
@Override
- protected ConcurrentMap<K, ConcurrentCollection<V>> delegate()
+ protected ConcurrentMap<K, Set<V>> delegate()
{
return delegate;
}
@@ -59,16 +60,16 @@
* matches.
*/
@Override
- public ConcurrentCollection<V> get(Object key)
+ public Set<V> get(Object key)
{
- ConcurrentCollection<V> values = super.get(key);
+ Set<V> values = super.get(key);
return values != null ? values : EMPTY_COLLECTION;
}
public void put(K key, V value)
{
- delegate().putIfAbsent(key, new ConcurrentList<V>());
- get(key).addIfAbsent(value);
+ delegate().putIfAbsent(key, new CopyOnWriteArraySet<V>());
+ get(key).add(value);
}
}
\ No newline at end of file
Modified:
ri/trunk/impl/src/main/java/org/jboss/webbeans/util/collections/multi/ConcurrentSetMultiMap.java
===================================================================
---
ri/trunk/impl/src/main/java/org/jboss/webbeans/util/collections/multi/ConcurrentSetMultiMap.java 2009-04-05
12:54:49 UTC (rev 2300)
+++
ri/trunk/impl/src/main/java/org/jboss/webbeans/util/collections/multi/ConcurrentSetMultiMap.java 2009-04-05
13:03:52 UTC (rev 2301)
@@ -16,18 +16,17 @@
*/
package org.jboss.webbeans.util.collections.multi;
+import java.util.Set;
import java.util.concurrent.ConcurrentMap;
-import org.jboss.webbeans.util.collections.ConcurrentCollection;
-
/**
- * A concurrent multimap, in which the multi-values are stored with Set
- * semantics for {@link #put(Object, Object)} operations
+ * A concurrent multimap, in which the multi-values are stored in a concurrent
+ * Set
*
* @author Pete Muir
*
*/
-public interface ConcurrentSetMultiMap<K, V> extends ConcurrentMap<K,
ConcurrentCollection<V>>
+public interface ConcurrentSetMultiMap<K, V> extends ConcurrentMap<K,
Set<V>>
{
/**
Modified:
ri/trunk/impl/src/main/java/org/jboss/webbeans/util/collections/multi/SetMultiMap.java
===================================================================
---
ri/trunk/impl/src/main/java/org/jboss/webbeans/util/collections/multi/SetMultiMap.java 2009-04-05
12:54:49 UTC (rev 2300)
+++
ri/trunk/impl/src/main/java/org/jboss/webbeans/util/collections/multi/SetMultiMap.java 2009-04-05
13:03:52 UTC (rev 2301)
@@ -20,8 +20,7 @@
import java.util.Set;
/**
- * A concurrent multimap, in which the multi-values are stored with Set
- * semantics for {@link #put(Object, Object)} operations
+ * A concurrent multimap, in which the multi-values are stored in a Set
*
* @author Pete Muir
*
Show replies by date