Collection.st
changeset 15386 d9c9360104ad
parent 15378 5c82887fc830
child 15408 8fdba8d23307
child 18066 89d51443ba6f
equal deleted inserted replaced
15385:2ca0c225509e 15386:d9c9360104ad
   692     "
   692     "
   693      #(1 2 3 4) fourth
   693      #(1 2 3 4) fourth
   694     "
   694     "
   695 !
   695 !
   696 
   696 
       
   697 keysSorted
       
   698     "return the keys as a sorted sequenceable collection.
       
   699      Some collections (which keep their keys already sorted) may
       
   700      redefine this method to return the keys as they are kept internally.
       
   701      The fallback here sorts them into an OrderedCollection"
       
   702 
       
   703     ^ self keys asNewOrderedCollection sort
       
   704 !
       
   705 
   697 last
   706 last
   698     "return the last element of the collection.
   707     "return the last element of the collection.
   699      This should be redefined in subclasses."
   708      This should be redefined in subclasses."
   700 
   709 
   701     |theLastOne any|
   710     |theLastOne any|
  1548 
  1557 
  1549     ^ self asIntegerArray:LongIntegerArray
  1558     ^ self asIntegerArray:LongIntegerArray
  1550 !
  1559 !
  1551 
  1560 
  1552 asNewArray
  1561 asNewArray
  1553     "return a new Array with the receiver collections elements"
  1562     "return a new Array with the receiver collection's elements.
       
  1563      This method ensures that the returned collection is a new one, not
       
  1564      the same or shared with the original receiver"
  1554 
  1565 
  1555     ^ self asArray
  1566     ^ self asArray
  1556 !
  1567 !
  1557 
  1568 
  1558 asNewDictionary
  1569 asNewDictionary
  1559     "return a new Dictionary with the receiver collections elements"
  1570     "return a new Dictionary with the receiver collection's elements.
       
  1571      This method ensures that the returned collection is a new one, not
       
  1572      the same or shared with the original receiver"
  1560 
  1573 
  1561     ^ self asDictionary
  1574     ^ self asDictionary
  1562 !
  1575 !
  1563 
  1576 
  1564 asNewIdentitySet
  1577 asNewIdentitySet
  1565     "return a new IdentitySet with the receiver collections elements"
  1578     "return a new IdentitySet with the receiver collection's elements.
       
  1579      This method ensures that the returned collection is a new one, not
       
  1580      the same or shared with the original receiver"
  1566 
  1581 
  1567     ^ self asIdentitySet
  1582     ^ self asIdentitySet
  1568 !
  1583 !
  1569 
  1584 
  1570 asNewOrderedCollection
  1585 asNewOrderedCollection
  1571     "return a new OrderedCollection with the receiver collections elements"
  1586     "return a new OrderedCollection with the receiver collection's elements.
       
  1587      This method ensures that the returned collection is a new one, not
       
  1588      the same or shared with the original receiver"
  1572 
  1589 
  1573     ^ self asOrderedCollection
  1590     ^ self asOrderedCollection
  1574 !
  1591 !
  1575 
  1592 
  1576 asNewOrderedSet
  1593 asNewOrderedSet
  1577     "return a new OrderedSet with the receiver collections elements"
  1594     "return a new OrderedSet with the receiver collection's elements.
       
  1595      This method ensures that the returned collection is a new one, not
       
  1596      the same or shared with the original receiver"
  1578 
  1597 
  1579     ^ self asOrderedSet
  1598     ^ self asOrderedSet
  1580 !
  1599 !
  1581 
  1600 
  1582 asNewSet
  1601 asNewSet
  1583     "return a new Set with the receiver collections elements"
  1602     "return a new Set with the receiver collection's elements.
       
  1603      This method ensures that the returned collection is a new one, not
       
  1604      the same or shared with the original receiver"
  1584 
  1605 
  1585     ^ self asSet
  1606     ^ self asSet
  1586 !
  1607 !
  1587 
  1608 
  1588 asNilIfEmpty
  1609 asNilIfEmpty
  1599 
  1620 
  1600     ^ self addAllTo:(OrderedCollection new:self size)
  1621     ^ self addAllTo:(OrderedCollection new:self size)
  1601 !
  1622 !
  1602 
  1623 
  1603 asOrderedSet
  1624 asOrderedSet
  1604     "return a new OrderedSet with the receiver collections elements"
  1625     "return a new OrderedSet with the receiver collection's elements.
       
  1626      Notice: this is redefined in OrderedSet, where it returns the receiver. 
       
  1627      Use asNewOrderedSet, if you intent to modify the returned collection."
  1605 
  1628 
  1606     ^ self addAllTo:(OrderedSet new:self size)
  1629     ^ self addAllTo:(OrderedSet new:self size)
  1607 !
  1630 !
  1608 
  1631 
  1609 asRunArray
  1632 asRunArray
  4744 ! !
  4767 ! !
  4745 
  4768 
  4746 !Collection class methodsFor:'documentation'!
  4769 !Collection class methodsFor:'documentation'!
  4747 
  4770 
  4748 version
  4771 version
  4749     ^ '$Header: /cvs/stx/stx/libbasic/Collection.st,v 1.303 2013-06-06 12:11:42 cg Exp $'
  4772     ^ '$Header: /cvs/stx/stx/libbasic/Collection.st,v 1.304 2013-06-09 13:03:50 cg Exp $'
  4750 !
  4773 !
  4751 
  4774 
  4752 version_CVS
  4775 version_CVS
  4753     ^ '$Header: /cvs/stx/stx/libbasic/Collection.st,v 1.303 2013-06-06 12:11:42 cg Exp $'
  4776     ^ '$Header: /cvs/stx/stx/libbasic/Collection.st,v 1.304 2013-06-09 13:03:50 cg Exp $'
  4754 ! !
  4777 ! !
  4755 
  4778 
  4756 
  4779 
  4757 Collection initialize!
  4780 Collection initialize!