OrderedCollection.st
changeset 3695 9ebf6de8a764
parent 3368 5b84482d26c9
child 3968 a526029723ac
equal deleted inserted replaced
3694:429ec70365a6 3695:9ebf6de8a764
   661 
   661 
   662     "Modified: 8.2.1997 / 19:19:00 / cg"
   662     "Modified: 8.2.1997 / 19:19:00 / cg"
   663 !
   663 !
   664 
   664 
   665 removeFirst
   665 removeFirst
   666     "remove the first element from the collection; return the element."
   666     "remove the first element from the collection; return the element.
       
   667      If there is no element in the receiver collection, raise an error."
   667 
   668 
   668     |anObject fI "{ Class: SmallInteger }" |
   669     |anObject fI "{ Class: SmallInteger }" |
   669 
   670 
   670     fI := firstIndex.
   671     fI := firstIndex.
   671 
   672 
   693      (OrderedCollection withAll:#(1 2 3 4 5)) removeFirst; yourself
   694      (OrderedCollection withAll:#(1 2 3 4 5)) removeFirst; yourself
   694      OrderedCollection new removeFirst
   695      OrderedCollection new removeFirst
   695      (SortedCollection withAll:#(5 4 3 2 1)) removeFirst; yourself
   696      (SortedCollection withAll:#(5 4 3 2 1)) removeFirst; yourself
   696     "
   697     "
   697 
   698 
   698     "Modified: / 12.11.1997 / 17:58:43 / cg"
   699     "Modified: / 30.7.1998 / 13:19:59 / cg"
   699 !
   700 !
   700 
   701 
   701 removeFirst:n
   702 removeFirst:n
   702     "remove the first n elements from the collection; 
   703     "remove the first n elements from the collection; 
   703      Return a collection containing the removed elements."
   704      Return a collection containing the removed elements."
   734      (OrderedCollection withAll:#(1 2 3 4 5)) removeFirst:6 
   735      (OrderedCollection withAll:#(1 2 3 4 5)) removeFirst:6 
   735      (SortedCollection withAll:#(5 4 3 2 1)) removeFirst:2; yourself  
   736      (SortedCollection withAll:#(5 4 3 2 1)) removeFirst:2; yourself  
   736     "
   737     "
   737 
   738 
   738     "Modified: 8.2.1997 / 19:20:18 / cg"
   739     "Modified: 8.2.1997 / 19:20:18 / cg"
       
   740 !
       
   741 
       
   742 removeFirstIfAbsent:exceptionBlock
       
   743     "remove the first element from the collection; return the element.
       
   744      If there is no element in the receiver collection, return the value from
       
   745      exceptionBlock."
       
   746 
       
   747     |anObject fI "{ Class: SmallInteger }" |
       
   748 
       
   749     fI := firstIndex.
       
   750 
       
   751     fI > lastIndex ifTrue:[
       
   752         "error if collection is empty"
       
   753         ^ exceptionBlock value.
       
   754     ].
       
   755 
       
   756     anObject := contentsArray basicAt:fI.
       
   757 
       
   758     "/ nil it out, to allow GC to reclaim it.
       
   759     contentsArray basicAt:fI put:nil.
       
   760 
       
   761     fI := fI + 1.
       
   762 
       
   763     fI > lastIndex ifTrue:[
       
   764         "reset to avoid ever growing"
       
   765         fI := 1.
       
   766         lastIndex := 0 
       
   767     ].
       
   768     firstIndex := fI.
       
   769     ^ anObject
       
   770 
       
   771     "
       
   772      (OrderedCollection withAll:#(1 2 3 4 5)) removeFirst; yourself
       
   773      OrderedCollection new removeFirst
       
   774      (SortedCollection withAll:#(5 4 3 2 1)) removeFirst; yourself
       
   775     "
       
   776 
       
   777     "Modified: / 12.11.1997 / 17:58:43 / cg"
       
   778     "Created: / 30.7.1998 / 13:19:42 / cg"
   739 !
   779 !
   740 
   780 
   741 removeFrom:startIndex to:stopIndex
   781 removeFrom:startIndex to:stopIndex
   742     "added for ST-80 compatibility.
   782     "added for ST-80 compatibility.
   743      Same as removeFromIndex:toIndex:."
   783      Same as removeFromIndex:toIndex:."
  1723 ! !
  1763 ! !
  1724 
  1764 
  1725 !OrderedCollection class methodsFor:'documentation'!
  1765 !OrderedCollection class methodsFor:'documentation'!
  1726 
  1766 
  1727 version
  1767 version
  1728     ^ '$Header: /cvs/stx/stx/libbasic/OrderedCollection.st,v 1.67 1998-04-07 11:38:56 ca Exp $'
  1768     ^ '$Header: /cvs/stx/stx/libbasic/OrderedCollection.st,v 1.68 1998-07-30 16:06:34 cg Exp $'
  1729 ! !
  1769 ! !