OrderedCollection.st
changeset 24894 09ca874a6160
parent 24892 2213eb56e0c7
child 25351 30b332af1f33
equal deleted inserted replaced
24893:373cc0ac5f71 24894:09ca874a6160
   595     "Modified: 12.4.1996 / 13:52:41 / cg"
   595     "Modified: 12.4.1996 / 13:52:41 / cg"
   596 !
   596 !
   597 
   597 
   598 addAll:aCollection beforeIndex:index
   598 addAll:aCollection beforeIndex:index
   599     "insert all elements of the argument, anObject to become located at index.
   599     "insert all elements of the argument, anObject to become located at index.
   600      The collection may be unordered, but then order of the sliced-in elements
   600      The collection may be unordered, but then the order of the sliced-in elements
   601      is undefined.
   601      is undefined.
   602      Return the receiver."
   602      Return the receiver."
   603 
   603 
   604     |idx count|
   604     |idx count|
   605 
   605 
   606     aCollection isSequenceable ifTrue:[
   606     aCollection isSequenceable ifTrue:[
   607 	"/ we are lucky - that thing can count & do bulk copies
   607         "/ we are lucky - that thing can count & do bulk copies
   608 
   608 
   609 	count := aCollection size.
   609         count := aCollection size.
   610 	idx := self makeRoomAtIndex:(index + firstIndex - 1) for:count.
   610         idx := self makeRoomAtIndex:(index + firstIndex - 1) for:count.
   611 	"/ notice: the above may change firstIndex
   611         "/ notice: the above may change firstIndex
   612 	contentsArray replaceFrom:idx to:(idx + count - 1) with:aCollection startingAt:1.
   612         contentsArray replaceFrom:idx to:(idx + count - 1) with:aCollection startingAt:1.
   613 	^ self
   613         ^ self
   614     ].
   614     ].
   615 
   615 
   616     idx := index.
   616     idx := index.
   617     aCollection do:[:element |
   617     aCollection do:[:element |
   618 	self add:element beforeIndex:idx.
   618         self add:element beforeIndex:idx.
   619 	idx := idx + 1.
   619         idx := idx + 1.
   620     ].
   620     ].
   621 
   621 
   622     "
   622     "
   623      |c|
   623      |c|
   624      c := #(1 2 3 4) asOrderedCollection.
   624      c := #(1 2 3 4) asOrderedCollection.
   665     "/ we are lucky - that thing can count & do bulk copies
   665     "/ we are lucky - that thing can count & do bulk copies
   666     "/ notice: the above may change firstIndex
   666     "/ notice: the above may change firstIndex
   667     contentsArray replaceFrom:idx to:(idx + count - 1) with:aCollection startingAt:startIndex.
   667     contentsArray replaceFrom:idx to:(idx + count - 1) with:aCollection startingAt:startIndex.
   668 
   668 
   669     "Created: / 30-07-2018 / 11:15:05 / Stefan Vogel"
   669     "Created: / 30-07-2018 / 11:15:05 / Stefan Vogel"
       
   670 !
       
   671 
       
   672 addAllFirst:aCollection
       
   673     "insert all elements of the argument, aCollection at the beginning
       
   674      of the receiver. Returns the argument, aCollection."
       
   675 
       
   676     self addAll:aCollection beforeIndex:1.
       
   677     ^ aCollection
       
   678 
       
   679     "
       
   680      |c|
       
   681      c := #(1 2 3 4) asOrderedCollection.
       
   682      c addAllFirst:#(10 20 30).
       
   683      c                        
       
   684     "
       
   685     "
       
   686      |c|
       
   687      c := #(1 2 3 4) asOrderedCollection.
       
   688      c addAllFirst:#().
       
   689      c   
       
   690     "
       
   691 
       
   692     "
       
   693      |c|
       
   694      c := #() asOrderedCollection.
       
   695      c addAllFirst:#(10 20 30).
       
   696      c   
       
   697     "
       
   698     "
       
   699      |c|
       
   700      c := #() asOrderedCollection.
       
   701      c addAllFirst:#().
       
   702      c   
       
   703     "
       
   704 
       
   705     "Modified: / 12.11.1997 / 17:58:05 / cg"
   670 !
   706 !
   671 
   707 
   672 addFirst:anObject
   708 addFirst:anObject
   673     "add the argument, anObject to the beginning of the collection.
   709     "add the argument, anObject to the beginning of the collection.
   674      Return the argument, anObject."
   710      Return the argument, anObject."
  1822 
  1858 
  1823     "Modified: / 30-07-2018 / 12:06:33 / Claus Gittinger"
  1859     "Modified: / 30-07-2018 / 12:06:33 / Claus Gittinger"
  1824 ! !
  1860 ! !
  1825 
  1861 
  1826 
  1862 
  1827 
       
  1828 !OrderedCollection methodsFor:'private'!
  1863 !OrderedCollection methodsFor:'private'!
  1829 
  1864 
  1830 containerClass
  1865 containerClass
  1831     "the class of the underlying container.
  1866     "the class of the underlying container.
  1832      Here Array; redefined in WeakOrderedCollection to use a WeakArray"
  1867      Here Array; redefined in WeakOrderedCollection to use a WeakArray"