[FIX] SortedCollectionFix-sr

Richard A. O'Keefe ok at cs.otago.ac.nz
Thu Sep 26 05:30:45 UTC 2002


	- >>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.




More information about the Squeak-dev mailing list