Is there anything in Java that implements something like the following
interface MSet<T> extends Iterable<T> {
/**
* return a new set which consists of this set plus a new element.
* This set is not changed.
*/
MSet<T> add(T t);
/**
* return a new set which consists of this set minus a designated element.
* This set is not changed.
*/
MSet<T> remove(T t);
}
edit: I want something like CopyOnWriteArraySet
, except that class is mutable and I want something that is an immutable set that allows creation of a new set. The reason for this is that I need to hand out references to the old set and leave them immutable.
edit 2: how does Scala implement scala.collection.immutable.Set? This is the kind of behavior I need, just that I don't want to suck in all of Scala just for this.