class: IdentitySet
authorStefan Vogel <sv@exept.de>
Fri, 29 Mar 2013 00:19:39 +0100
changeset 14998 6bea48d14676
parent 14997 19ac0ce7ab74
child 14999 e6ad9751587b
class: IdentitySet added: #asNewIdentitySet
IdentitySet.st
--- a/IdentitySet.st	Fri Mar 29 00:16:19 2013 +0100
+++ b/IdentitySet.st	Fri Mar 29 00:19:39 2013 +0100
@@ -66,6 +66,25 @@
     ^ super remove:anObject ifAbsent:exceptionBlock
 ! !
 
+!IdentitySet methodsFor:'converting'!
+
+asNewIdentitySet
+    "make sure to return myself as a unique new set"
+
+    "could be an instance of a subclass..."
+    self class == IdentitySet ifTrue:[
+        ^ self copy
+    ].
+    ^ super asIdentitySet
+
+    "
+        |s|
+        s := #(1 2 3 4) asIdentitySet.
+        self assert:(s ~~ s asNewIdentitySet).
+        self assert:(s = s asNewIdentitySet).
+    "
+! !
+
 !IdentitySet methodsFor:'private'!
 
 collisionsFor:key
@@ -242,6 +261,6 @@
 !IdentitySet class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/IdentitySet.st,v 1.34 2013-01-15 16:33:59 stefan Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/IdentitySet.st,v 1.35 2013-03-28 23:19:39 stefan Exp $'
 ! !