Clean up code and document differences between #add: and #addLast:
authorStefan Vogel <sv@exept.de>
Wed, 21 Nov 2007 18:24:02 +0100
changeset 1915 c7fbd33fc982
parent 1914 8a6e5feaeaef
child 1916 9815828d0bf8
Clean up code and document differences between #add: and #addLast:
OrderedSet.st
--- a/OrderedSet.st	Mon Nov 19 12:47:32 2007 +0100
+++ b/OrderedSet.st	Wed Nov 21 18:24:02 2007 +0100
@@ -9,7 +9,6 @@
  other person.  No title to or ownership of the software is
  hereby transferred.
 "
-
 "{ Package: 'stx:libbasic2' }"
 
 Set subclass:#OrderedSet
@@ -142,9 +141,17 @@
 
 add:anObject 
     "Add anObject to the receiver (if not already included). 
-     Also, remember in the order (i.e. add to the end)"
+     Also, remember in the order (i.e. add to the end)
+     If anAssociation is already present in the dictionary,
+     the order will not be changed. (See also: #addLast:)"
 
-    self addLast:anObject.
+    anObject isNil ifTrue:[
+        ^ self invalidElementError.
+    ].
+    (self includes:anObject) ifFalse:[
+        super add:anObject.
+        order add:anObject.
+    ].
     ^ anObject
 !
 
@@ -164,15 +171,19 @@
 
 addLast:anObject 
     "Add anObject to the receiver (if not already included). 
-     Also, remember in the order (i.e. add to the end)"
+     Also, remember in the order (i.e. add to the end)
+     If anAssociation is already present in the receiver,
+     it will be moved to the end. (See also: #add:)"
 
     anObject isNil ifTrue:[
         ^ self invalidElementError.
     ].
-    (self includes:anObject) ifFalse:[
+    (self includes:anObject) ifTrue:[
+        order remove:anObject ifAbsent:[].
+    ] ifFalse:[
         super add:anObject.
-        order addLast:anObject.
     ].
+    order add:anObject.
     ^ anObject
 !
 
@@ -316,5 +327,5 @@
 !OrderedSet class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic2/Attic/OrderedSet.st,v 1.12 2006-03-06 08:54:58 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic2/Attic/OrderedSet.st,v 1.13 2007-11-21 17:24:02 stefan Exp $'
 ! !