Provide an immutable view of a DSet a Set for when you want to roll Java
Collections style. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@5319 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -23,9 +23,11 @@ package com.threerings.presents.dobj;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import java.util.AbstractSet;
|
||||
import java.util.Comparator;
|
||||
import java.util.ConcurrentModificationException;
|
||||
import java.util.Iterator;
|
||||
import java.util.Set;
|
||||
|
||||
import com.samskivert.util.ArrayUtil;
|
||||
|
||||
@@ -256,6 +258,31 @@ public class DSet<E extends DSet.Entry>
|
||||
return array;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an <b>immutable</b> view of this distributed set as a Java set.
|
||||
*/
|
||||
public Set<E> toSet ()
|
||||
{
|
||||
return new AbstractSet<E>() {
|
||||
@Override public boolean add (E o) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
@Override public boolean remove (Object o) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
@Override public boolean contains (Object o) {
|
||||
@SuppressWarnings("unchecked") E elem = (E)o;
|
||||
return DSet.this.contains(elem);
|
||||
}
|
||||
@Override public Iterator<E> iterator () {
|
||||
return DSet.this.iterator();
|
||||
}
|
||||
@Override public int size () {
|
||||
return DSet.this.size();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated use {@link #toArray(Entry[])}.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user