Fix `Collection >> #sortedBy:` w.r.t unordered collections jv
authorJan Vrany <jan.vrany@labware.com>
Mon, 29 Mar 2021 21:22:40 +0100
branchjv
changeset 25412 f34d8a7f4b7c
parent 25411 248600ba8fd9
child 25413 565bf29e3a20
Fix `Collection >> #sortedBy:` w.r.t unordered collections ...such as `Set`s
Collection.st
--- a/Collection.st	Thu Mar 25 20:30:03 2021 +0000
+++ b/Collection.st	Mon Mar 29 21:22:40 2021 +0100
@@ -2,6 +2,7 @@
 
 "
  COPYRIGHT (c) 1989 by Claus Gittinger
+ COPYRIGHT (c) 2021 LabWare
               All Rights Reserved
 
  This software is furnished under a license and may be used
@@ -28,6 +29,7 @@
 copyright
 "
  COPYRIGHT (c) 1989 by Claus Gittinger
+ COPYRIGHT (c) 2021 LabWare
               All Rights Reserved
 
  This software is furnished under a license and may be used
@@ -266,14 +268,8 @@
     ^ self newWithSize:n
 ! !
 
-!Collection class methodsFor:'Compatibility-Squeak'!
-
-ofSize:n
-    "return a new collection which really provides space for n elements.
-     Kludges around the stupid definition of OrderedCollection>>new:"
-
-    ^ self newWithSize:n
-! !
+
+
 
 
 !Collection class methodsFor:'Signal constants'!
@@ -345,6 +341,11 @@
     ^ self
 ! !
 
+
+
+
+
+
 !Collection methodsFor:'Compatibility-ANSI'!
 
 identityIncludes:anObject
@@ -354,37 +355,6 @@
     ^ self includesIdentical:anObject.
 ! !
 
-!Collection methodsFor:'Compatibility-Dolphin'!
-
-includesAnyOf:aCollection
-    "same as #includesAny for Dolphin compatibility."
-
-    ^ self includesAny:aCollection
-
-    "
-     #(1 2 3 4 5 6 7) includesAny:#(1 2 3)
-     #('hello' 'there' 'world') includesAny:#('hello' 'world')
-     #(1 2 3 4 5 6 7) includesAny:#(7 8 9)
-     #(1 2 3 4 5 6 7) includesAny:#(8 9 10)
-    "
-!
-
-symmetricDifference:aCollection
-    "return a new set containing all elements, 
-     which are contained in either the receiver or aCollection, but not in both.
-     Same as xor: - for compatibility"
-
-    ^ self xor:aCollection
-
-    "
-     |c1 c2|
-
-     c1 := #( foo bar baz baloo ).
-     c2 := #( foe bar banana baloo ).
-     c1 symmetricDifference:c2.         
-     self assert:(c1 symmetricDifference:c2) asSet = (c2 symmetricDifference:c1) asSet
-    "
-! !
 
 !Collection methodsFor:'Compatibility-Squeak'!
 
@@ -542,14 +512,6 @@
     "return ifNotEmptyValue if not empty, ifEmptyValue otherwise"
 
     ^ self ifEmpty:ifEmptyValue ifNotEmpty:ifNotEmptyValue
-!
-
-intersection:aCollection
-    "same as intersect: for Squeak compatibility"
-    
-    ^ self intersect:aCollection
-
-    "Created: / 22-10-2008 / 21:29:27 / cg"
 ! !
 
 
@@ -5388,11 +5350,15 @@
 
     |newCollection|
 
-    newCollection := self speciesForAdding new:self size.
+    newCollection := self isOrdered 
+                        ifTrue: [self speciesForAdding new:self size] 
+                        ifFalse: [OrderedCollection new: self size].
     self addAllTo:newCollection.
     newCollection sort:aTwoArgBlock.
 
     ^ newCollection
+
+    "Modified: / 25-03-2021 / 20:42:13 / Jan Vrany <jan.vrany@labware.com>"
 !
 
 sortedBySelector:aSelector
@@ -6023,6 +5989,11 @@
 
 version_CVS
     ^ '$Header$'
+!
+
+version_HG
+
+    ^ '$Changeset: <not expanded> $'
 ! !