Let ChannelLocal implement Iterable. See #307

This commit is contained in:
norman 2012-05-04 13:20:08 +02:00
parent 3a99550132
commit 85a280b356

View File

@ -15,6 +15,9 @@
*/ */
package org.jboss.netty.channel; package org.jboss.netty.channel;
import java.util.Collections;
import java.util.Iterator;
import java.util.Map.Entry;
import java.util.concurrent.ConcurrentMap; import java.util.concurrent.ConcurrentMap;
import org.jboss.netty.util.internal.ConcurrentIdentityWeakKeyHashMap; import org.jboss.netty.util.internal.ConcurrentIdentityWeakKeyHashMap;
@ -30,7 +33,7 @@ import org.jboss.netty.util.internal.ConcurrentIdentityWeakKeyHashMap;
* property, which performs better. * property, which performs better.
* @apiviz.stereotype utility * @apiviz.stereotype utility
*/ */
public class ChannelLocal<T> { public class ChannelLocal<T> implements Iterable<Entry<Channel, T>>{
private final ConcurrentMap<Channel, T> map = private final ConcurrentMap<Channel, T> map =
new ConcurrentIdentityWeakKeyHashMap<Channel, T>(); new ConcurrentIdentityWeakKeyHashMap<Channel, T>();
@ -153,4 +156,11 @@ public class ChannelLocal<T> {
return removed; return removed;
} }
} }
/**
* Returns a <strong>read-only</strong> {@link Iterator} that holds all {@link Entry}'s of this ChannelLocal
*/
public Iterator<Entry<Channel, T>> iterator() {
return Collections.unmodifiableSet(map.entrySet()).iterator();
}
} }