logo       

Re: [FIX] SortedCollectionFix-sr: msg#00676

lang.smalltalk.squeak.general

Subject: Re: [FIX] SortedCollectionFix-sr

- >>addLast: should be forbidden as >>addFirst is already;

Why should addLast: or addFirst: be given a complete veto?

Why not
addFirst: anItem
self isEmpty ifTrue: [^super addFirst: anItem].
(sortBlock
ifNil: [anItem <= self first]
ifNotNil: [sortBlock value: anItem value: self first]
) ifFalse: [
self error: 'new item would be out of order'
].
^super addFirst: anItem.

addLast: anItem
self isEmpty ifTrue: [^super addLast: anItem].
(sortBlock
ifNil: [self last <= anItem]
ifNotNil: [sortBlock value: self last value: anItem]
) ifFalse: [
self error: 'new item would be out of order'
].
^super addLast: anItem.

This way we DON'T have to invent a new method to use when someone
wants to build up a SortedCollection one element at a time and knows
they can do it in the correct order, and we still don't allow these
methods to spoil the order of the collection.





<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise