Collection.st
changeset 15812 5301a3a03510
parent 15807 67f21e530e48
child 15856 9f5861a3c36c
child 18107 d46c13a0795b
equal deleted inserted replaced
15811:7d3cc7a1961f 15812:5301a3a03510
  1439         ((1 to:10) collect:[:n | n squared]) sum = ((1 to:10) sum:[:n | n squared])
  1439         ((1 to:10) collect:[:n | n squared]) sum = ((1 to:10) sum:[:n | n squared])
  1440      )
  1440      )
  1441     "
  1441     "
  1442 
  1442 
  1443     "Modified: / 23-08-2010 / 18:19:42 / cg"
  1443     "Modified: / 23-08-2010 / 18:19:42 / cg"
       
  1444 ! !
       
  1445 
       
  1446 !Collection methodsFor:'comparing'!
       
  1447 
       
  1448 identicalContentsAs:aCollection
       
  1449     "return true if the receiver and aCollection represent collections
       
  1450      with identical contents. This is much like #sameContentsAs:, but compares
       
  1451      elements using #== instead of #=."
       
  1452 
       
  1453     aCollection size ~~ self size ifTrue:[
       
  1454         ^ false
       
  1455     ].
       
  1456 
       
  1457     ^ aCollection conform:[:e | (self includesIdentical:e)]
       
  1458 
       
  1459     "
       
  1460      #(1 2 3 4 5) = #(1 2 3 4 5)
       
  1461      #(1 2 3 4 5) = #(1.0 2 3 4.0 5)
       
  1462      #($1 $2 $3 $4 $5) = '12345'
       
  1463 
       
  1464      #(1 2 3 4 5) identicalContentsAs:#(1 2 3 4 5)
       
  1465      #(1 2 3 4 5) identicalContentsAs: #(1.0 2 3 4.0 5)
       
  1466      #($1 $2 $3 $4 $5) identicalContentsAs: '12345'
       
  1467     "
       
  1468 
       
  1469     "Modified: / 31.10.2001 / 11:30:18 / cg"
       
  1470 !
       
  1471 
       
  1472 sameContentsAs:aCollection
       
  1473     "answer true, if all the elements in self and aCollection
       
  1474      are common. This is not defined as #=, since we cannot redefine #hash
       
  1475      for aCollection."
       
  1476 
       
  1477     aCollection size ~~ self size ifTrue:[
       
  1478         ^ false
       
  1479     ].
       
  1480 
       
  1481     ^ aCollection conform:[:e | (self includes:e)]
       
  1482 
       
  1483     "
       
  1484       #(1 2 3) asSet sameContentsAs: #(1 2 3)
       
  1485       #(1 2 3 4) asSet sameContentsAs: #(1 2 3)
       
  1486       #(1 2 3) asSet sameContentsAs: #(1 2 3 3)
       
  1487       #(1 2 3 'aa') asSet sameContentsAs: #(1 2 3 'aa')
       
  1488       #(1 2 3 'aa') asIdentitySet sameContentsAs: #(1 2 3 'aa')
       
  1489       #(1 2 3 #aa) asIdentitySet sameContentsAs: #(1 2 3 #aa)
       
  1490     "
       
  1491 !
       
  1492 
       
  1493 sameContentsAs:aCollection whenComparedWith:compareBlock
       
  1494     "answer true, if all the elements in self and aCollection
       
  1495      are common. This is not defined as #=, since we cannot redefine #hash
       
  1496      for aCollection."
       
  1497 
       
  1498     aCollection size ~~ self size ifTrue:[
       
  1499         ^ false
       
  1500     ].
       
  1501 
       
  1502     ^ aCollection conform:[:otherElement | 
       
  1503             self contains:[:myElement | 
       
  1504                 compareBlock value:myElement value:otherElement
       
  1505             ].
       
  1506         ].
       
  1507 
       
  1508    "
       
  1509      #(1 2 3 4 5) asSet sameContentsAs: #(1 2 3 4 5) whenComparedWith:[:a :b | a = b]
       
  1510      #(1 2 3 4 5) sameContentsAs: #(1 2 3 4 5) asSet whenComparedWith:[:a :b | a = b]
       
  1511      #(1 2 3 4 5) asSet sameContentsAs: #(1 2 3 4 5)     whenComparedWith:[:a :b | a == b]
       
  1512      #(1 2 3 4 5) asSet sameContentsAs: #(1.0 2 3 4.0 5) whenComparedWith:[:a :b | a = b]
       
  1513      #(1 2 3 4 5) asSet sameContentsAs: #(1.0 2 3 4.0 5) whenComparedWith:[:a :b | a == b]
       
  1514 
       
  1515      #('Hello' 'ABC' 'worlD') asSet sameContentsAs: #('Hello' 'ABC' 'worlD') whenComparedWith:[:a :b | a sameAs:b]
       
  1516    "
  1444 ! !
  1517 ! !
  1445 
  1518 
  1446 !Collection methodsFor:'converting'!
  1519 !Collection methodsFor:'converting'!
  1447 
  1520 
  1448 asArray
  1521 asArray
  4911 ! !
  4984 ! !
  4912 
  4985 
  4913 !Collection class methodsFor:'documentation'!
  4986 !Collection class methodsFor:'documentation'!
  4914 
  4987 
  4915 version
  4988 version
  4916     ^ '$Header: /cvs/stx/stx/libbasic/Collection.st,v 1.317 2013-11-12 18:17:10 stefan Exp $'
  4989     ^ '$Header: /cvs/stx/stx/libbasic/Collection.st,v 1.318 2013-11-14 15:30:58 stefan Exp $'
  4917 !
  4990 !
  4918 
  4991 
  4919 version_CVS
  4992 version_CVS
  4920     ^ '$Header: /cvs/stx/stx/libbasic/Collection.st,v 1.317 2013-11-12 18:17:10 stefan Exp $'
  4993     ^ '$Header: /cvs/stx/stx/libbasic/Collection.st,v 1.318 2013-11-14 15:30:58 stefan Exp $'
  4921 ! !
  4994 ! !
  4922 
  4995 
  4923 
  4996 
  4924 Collection initialize!
  4997 Collection initialize!