There's a method for that.

git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@6159 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Ray Greenwell
2010-09-16 17:38:29 +00:00
parent e24ddecabb
commit 5c411bf6e7
@@ -8,6 +8,8 @@ import java.io.IOException;
import java.nio.channels.SelectionKey; import java.nio.channels.SelectionKey;
import java.nio.channels.Selector; import java.nio.channels.Selector;
import com.google.common.collect.Iterators;
import static com.threerings.presents.Log.log; import static com.threerings.presents.Log.log;
/** /**
@@ -38,23 +40,7 @@ public class SelectorIterable
public Iterator<SelectionKey> iterator () public Iterator<SelectionKey> iterator ()
{ {
final Iterator<SelectionKey> it = select().iterator(); return Iterators.consumingIterator(select().iterator());
return new Iterator<SelectionKey>() {
public boolean hasNext () {
return it.hasNext();
}
public SelectionKey next () {
SelectionKey key = it.next();
it.remove();
return key;
}
public void remove () {
throw new UnsupportedOperationException(
"Removing from the selected keys is done automatically on next()");
}
};
} }
protected Set<SelectionKey> select () protected Set<SelectionKey> select ()