added identity-element compare: #identicalContentsAs:
authorClaus Gittinger <cg@exept.de>
Fri, 18 Feb 2000 19:01:04 +0100
changeset 5275 87127c0e3167
parent 5274 c7355bfa2efc
child 5276 0048d0e7cbda
added identity-element compare: #identicalContentsAs:
SequenceableCollection.st
--- a/SequenceableCollection.st	Fri Feb 18 15:45:54 2000 +0100
+++ b/SequenceableCollection.st	Fri Feb 18 19:01:04 2000 +0100
@@ -928,6 +928,40 @@
     "Modified: / 27.3.1998 / 17:33:49 / cg"
 !
 
+identicalContentsAs:aCollection
+    "return true if the receiver and aCollection represent collections
+     with identical contents. This is much like #=, but compares
+     elements using #== instead of #=."
+
+    |index "{ Class: SmallInteger }"
+     stop  "{ Class: SmallInteger }" |
+
+    (aCollection == self) ifTrue:[^ true].
+    (aCollection isSequenceable) ifFalse:[^ false].
+
+    stop := self size.
+    stop == (aCollection size) ifFalse:[^ false].
+
+    index := 1.
+    [index <= stop] whileTrue:[
+        (self at:index) == (aCollection at:index) ifFalse:[^ false].
+        index := index + 1
+    ].
+    ^ true
+
+    "
+     #(1 2 3 4 5) = #(1 2 3 4 5)                        
+     #(1 2 3 4 5) = #(1.0 2 3 4.0 5)                        
+     #($1 $2 $3 $4 $5) = '12345'     
+
+     #(1 2 3 4 5) identicalContentsAs:#(1 2 3 4 5) 
+     #(1 2 3 4 5) identicalContentsAs: #(1.0 2 3 4.0 5)                        
+     #($1 $2 $3 $4 $5) identicalContentsAs: '12345'     
+    "
+
+    "Modified: / 18.2.2000 / 19:04:27 / cg"
+!
+
 startsWith:aCollection
     "return true, if the receivers first elements match those
      of aCollection
@@ -4664,6 +4698,6 @@
 !SequenceableCollection class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/SequenceableCollection.st,v 1.128 2000-02-03 13:18:32 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/SequenceableCollection.st,v 1.129 2000-02-18 18:01:04 cg Exp $'
 ! !
 SequenceableCollection initialize!