You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mina.apache.org by tr...@apache.org on 2007/08/17 14:03:42 UTC

svn commit: r567031 - in /mina/trunk/core/src/main/java/org/apache/mina/util: ConcurrentHashSet.java IdentityHashSet.java MapBackedSet.java

Author: trustin
Date: Fri Aug 17 05:03:37 2007
New Revision: 567031

URL: http://svn.apache.org/viewvc?view=rev&rev=567031
Log:
* Added ConcurrentHashSet, which is backed by ConcurrentHashMap
* Extracted common part of IdentityHastSet and ConcurrentHashSet into MapBackedSet

Added:
    mina/trunk/core/src/main/java/org/apache/mina/util/ConcurrentHashSet.java   (with props)
    mina/trunk/core/src/main/java/org/apache/mina/util/MapBackedSet.java   (with props)
Modified:
    mina/trunk/core/src/main/java/org/apache/mina/util/IdentityHashSet.java

Added: mina/trunk/core/src/main/java/org/apache/mina/util/ConcurrentHashSet.java
URL: http://svn.apache.org/viewvc/mina/trunk/core/src/main/java/org/apache/mina/util/ConcurrentHashSet.java?view=auto&rev=567031
==============================================================================
--- mina/trunk/core/src/main/java/org/apache/mina/util/ConcurrentHashSet.java (added)
+++ mina/trunk/core/src/main/java/org/apache/mina/util/ConcurrentHashSet.java Fri Aug 17 05:03:37 2007
@@ -0,0 +1,40 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+package org.apache.mina.util;
+
+import java.util.Collection;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * A {@link ConcurrentHashMap}-backed {@link Set}.
+ *
+ * @author The Apache MINA Project (dev@mina.apache.org)
+ * @version $Rev$, $Date$
+ */
+public class ConcurrentHashSet<E> extends MapBackedSet<E> {
+    public ConcurrentHashSet() {
+        super(new ConcurrentHashMap<E, Boolean>());
+    }
+
+    public ConcurrentHashSet(Collection<E> c) {
+        super(new ConcurrentHashMap<E, Boolean>(), c);
+    }
+}

Propchange: mina/trunk/core/src/main/java/org/apache/mina/util/ConcurrentHashSet.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: mina/trunk/core/src/main/java/org/apache/mina/util/ConcurrentHashSet.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: mina/trunk/core/src/main/java/org/apache/mina/util/IdentityHashSet.java
URL: http://svn.apache.org/viewvc/mina/trunk/core/src/main/java/org/apache/mina/util/IdentityHashSet.java?view=diff&rev=567031&r1=567030&r2=567031
==============================================================================
--- mina/trunk/core/src/main/java/org/apache/mina/util/IdentityHashSet.java (original)
+++ mina/trunk/core/src/main/java/org/apache/mina/util/IdentityHashSet.java Fri Aug 17 05:03:37 2007
@@ -19,11 +19,8 @@
  */
 package org.apache.mina.util;
 
-import java.util.AbstractSet;
 import java.util.Collection;
 import java.util.IdentityHashMap;
-import java.util.Iterator;
-import java.util.Map;
 import java.util.Set;
 
 /**
@@ -32,43 +29,12 @@
  * @author The Apache MINA Project (dev@mina.apache.org)
  * @version $Rev$, $Date$
  */
-public class IdentityHashSet<E> extends AbstractSet<E> {
-    private final Map<E, Boolean> delegate = new IdentityHashMap<E, Boolean>();
-
+public class IdentityHashSet<E> extends MapBackedSet<E> {
     public IdentityHashSet() {
+        super(new IdentityHashMap<E, Boolean>());
     }
 
     public IdentityHashSet(Collection<E> c) {
-        addAll(c);
-    }
-
-    @Override
-    public int size() {
-        return delegate.size();
-    }
-
-    @Override
-    public boolean contains(Object o) {
-        return delegate.containsKey(o);
-    }
-
-    @Override
-    public Iterator<E> iterator() {
-        return delegate.keySet().iterator();
-    }
-
-    @Override
-    public boolean add(E arg0) {
-        return delegate.put(arg0, Boolean.TRUE) == null;
-    }
-
-    @Override
-    public boolean remove(Object arg0) {
-        return delegate.remove(arg0) != null;
-    }
-
-    @Override
-    public void clear() {
-        delegate.clear();
+        super(new IdentityHashMap<E, Boolean>(), c);
     }
 }

Added: mina/trunk/core/src/main/java/org/apache/mina/util/MapBackedSet.java
URL: http://svn.apache.org/viewvc/mina/trunk/core/src/main/java/org/apache/mina/util/MapBackedSet.java?view=auto&rev=567031
==============================================================================
--- mina/trunk/core/src/main/java/org/apache/mina/util/MapBackedSet.java (added)
+++ mina/trunk/core/src/main/java/org/apache/mina/util/MapBackedSet.java Fri Aug 17 05:03:37 2007
@@ -0,0 +1,75 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+package org.apache.mina.util;
+
+import java.util.AbstractSet;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * A {@link Map}-backed {@link Set}.
+ *
+ * @author The Apache MINA Project (dev@mina.apache.org)
+ * @version $Rev$, $Date$
+ */
+public class MapBackedSet<E> extends AbstractSet<E> {
+    private final Map<E, Boolean> delegate;
+
+    public MapBackedSet(Map<E, Boolean> map) {
+        this.delegate = map;
+    }
+
+    public MapBackedSet(Map<E, Boolean> map, Collection<E> c) {
+        this. delegate = map;
+        addAll(c);
+    }
+
+    @Override
+    public int size() {
+        return delegate.size();
+    }
+
+    @Override
+    public boolean contains(Object o) {
+        return delegate.containsKey(o);
+    }
+
+    @Override
+    public Iterator<E> iterator() {
+        return delegate.keySet().iterator();
+    }
+
+    @Override
+    public boolean add(E arg0) {
+        return delegate.put(arg0, Boolean.TRUE) == null;
+    }
+
+    @Override
+    public boolean remove(Object arg0) {
+        return delegate.remove(arg0) != null;
+    }
+
+    @Override
+    public void clear() {
+        delegate.clear();
+    }
+}

Propchange: mina/trunk/core/src/main/java/org/apache/mina/util/MapBackedSet.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: mina/trunk/core/src/main/java/org/apache/mina/util/MapBackedSet.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date