diff -r 429ec70365a6 -r 9ebf6de8a764 OrderedCollection.st --- a/OrderedCollection.st Thu Jul 30 18:05:41 1998 +0200 +++ b/OrderedCollection.st Thu Jul 30 18:06:34 1998 +0200 @@ -663,7 +663,8 @@ ! removeFirst - "remove the first element from the collection; return the element." + "remove the first element from the collection; return the element. + If there is no element in the receiver collection, raise an error." |anObject fI "{ Class: SmallInteger }" | @@ -695,7 +696,7 @@ (SortedCollection withAll:#(5 4 3 2 1)) removeFirst; yourself " - "Modified: / 12.11.1997 / 17:58:43 / cg" + "Modified: / 30.7.1998 / 13:19:59 / cg" ! removeFirst:n @@ -738,6 +739,45 @@ "Modified: 8.2.1997 / 19:20:18 / cg" ! +removeFirstIfAbsent:exceptionBlock + "remove the first element from the collection; return the element. + If there is no element in the receiver collection, return the value from + exceptionBlock." + + |anObject fI "{ Class: SmallInteger }" | + + fI := firstIndex. + + fI > lastIndex ifTrue:[ + "error if collection is empty" + ^ exceptionBlock value. + ]. + + anObject := contentsArray basicAt:fI. + + "/ nil it out, to allow GC to reclaim it. + contentsArray basicAt:fI put:nil. + + fI := fI + 1. + + fI > lastIndex ifTrue:[ + "reset to avoid ever growing" + fI := 1. + lastIndex := 0 + ]. + firstIndex := fI. + ^ anObject + + " + (OrderedCollection withAll:#(1 2 3 4 5)) removeFirst; yourself + OrderedCollection new removeFirst + (SortedCollection withAll:#(5 4 3 2 1)) removeFirst; yourself + " + + "Modified: / 12.11.1997 / 17:58:43 / cg" + "Created: / 30.7.1998 / 13:19:42 / cg" +! + removeFrom:startIndex to:stopIndex "added for ST-80 compatibility. Same as removeFromIndex:toIndex:." @@ -1725,5 +1765,5 @@ !OrderedCollection class methodsFor:'documentation'! version - ^ '$Header: /cvs/stx/stx/libbasic/OrderedCollection.st,v 1.67 1998-04-07 11:38:56 ca Exp $' + ^ '$Header: /cvs/stx/stx/libbasic/OrderedCollection.st,v 1.68 1998-07-30 16:06:34 cg Exp $' ! !