Object subclass: #OrderedDictionary instanceVariableNames: 'collection' classVariableNames: '' poolDictionaries: '' category: 'OrderedDictionary'! !OrderedDictionary methodsFor: 'adding' stamp: 'nm 6/11/2009 09:21'! add: association ^self collection add: association! ! !OrderedDictionary methodsFor: 'adding' stamp: 'nm 6/11/2009 09:21'! addAll: aCollection aCollection do: [:each | self add: each]! ! !OrderedDictionary methodsFor: 'enumerating' stamp: 'nm 6/11/2009 10:12'! associationsDo: aBlock self collection do: [:assoc | aBlock value: assoc ]! ! !OrderedDictionary methodsFor: 'enumerating' stamp: 'nm 6/11/2009 10:13'! collect: aBlock | newCollection | newCollection _ self species new. self associationsDo: [:each | newCollection add: (aBlock value: each value)]. ^newCollection! ! !OrderedDictionary methodsFor: 'enumerating' stamp: 'nm 6/11/2009 09:31'! do: aBlock self collection do: [:assoc | aBlock value: assoc value]! ! !OrderedDictionary methodsFor: 'enumerating' stamp: 'nm 6/11/2009 10:07'! keysAndValuesDo: aBlock ^self associationsDo:[:assoc| aBlock value: assoc key value: assoc value].! ! !OrderedDictionary methodsFor: 'enumerating' stamp: 'nm 6/11/2009 10:07'! keysDo: aBlock "Evaluate aBlock for each of the receiver's keys." self associationsDo: [:association | aBlock value: association key]! ! !OrderedDictionary methodsFor: 'enumerating' stamp: 'nm 6/11/2009 10:14'! reject: aBlock | newCollection | newCollection _ self species new. self associationsDo: [:each | (aBlock value: each value) ifFalse: [newCollection add: each]]. ^newCollection! ! !OrderedDictionary methodsFor: 'enumerating' stamp: 'nm 6/11/2009 10:11'! select: aBlock | newCollection | newCollection _ self species new. self associationsDo: [:each | (aBlock value: each value) ifTrue: [newCollection add: each]]. ^newCollection! ! !OrderedDictionary methodsFor: 'enumerating' stamp: 'nm 6/11/2009 10:08'! valuesDo: aBlock "Evaluate aBlock for each of the receiver's values." self associationsDo: [:association | aBlock value: association value]! ! !OrderedDictionary methodsFor: 'accessing' stamp: 'nm 6/19/2009 18:34'! at: anObject ^self at: anObject ifAbsent: [self error: 'Item ',anObject,' not found']! ! !OrderedDictionary methodsFor: 'accessing' stamp: 'nm 6/11/2009 09:44'! at: anObject ifAbsent: absentBlock | assoc | assoc:= self findElementOrNil: anObject. assoc notNil ifTrue:[^assoc value] ifFalse:[^absentBlock value]! ! !OrderedDictionary methodsFor: 'accessing' stamp: 'nm 6/11/2009 09:21'! at: anObject ifAbsentPut: putBlock | value | ^self at: anObject ifAbsent: [ value := putBlock value. self add: anObject -> value. value]! ! !OrderedDictionary methodsFor: 'accessing' stamp: 'nm 6/11/2009 10:38'! at: anObject put: aValue | assoc | assoc:= self findElementOrNil: anObject. assoc notNil ifTrue:[assoc value: aValue] ifFalse:[self add: (anObject -> aValue)]. ^aValue ! ! !OrderedDictionary methodsFor: 'accessing' stamp: 'nm 6/11/2009 09:21'! collection ^collection! ! !OrderedDictionary methodsFor: 'accessing' stamp: 'nm 6/11/2009 09:21'! collection: anObject collection := anObject! ! !OrderedDictionary methodsFor: 'accessing' stamp: 'nm 6/11/2009 09:57'! doesNotUnderstand: aMessage ^self collection perform: aMessage selector withArguments: aMessage arguments! ! !OrderedDictionary methodsFor: 'accessing' stamp: 'hfm 5/26/2010 17:32'! findElementOrNil: anObject ^ self collection detect:[: each | each key = anObject] ifNone: [nil] ! ! !OrderedDictionary methodsFor: 'accessing' stamp: 'nm 6/11/2009 10:02'! keys ^self collection collect:[:each | each key]! ! !OrderedDictionary methodsFor: 'accessing' stamp: 'nm 6/11/2009 09:21'! size ^self collection size! ! !OrderedDictionary methodsFor: 'accessing' stamp: 'nm 6/11/2009 10:02'! values ^self collection collect:[:each | each value]! ! !OrderedDictionary methodsFor: 'initialize-release' stamp: 'nm 6/11/2009 09:21'! clear self collection: OrderedCollection new ! ! !OrderedDictionary methodsFor: 'initialize-release' stamp: 'nm 6/11/2009 09:21'! initialize self clear! ! !OrderedDictionary methodsFor: 'as yet unclassified' stamp: 'nm 6/11/2009 09:21'! groupBy: aBlock | answer | answer := self class new. self collection do: [:assoc | (answer at: (aBlock value: assoc value) ifAbsentPut: [OrderedCollection new]) add: assoc value. ]. ^answer! ! !OrderedDictionary methodsFor: 'testing' stamp: 'nm 6/11/2009 09:21'! isEmpty ^self collection isEmpty! ! !OrderedDictionary methodsFor: 'testing' stamp: 'nm 6/11/2009 09:21'! notEmpty ^self collection notEmpty! ! !OrderedDictionary methodsFor: 'printing' stamp: 'nm 6/11/2009 10:06'! printOn: aStream super printOn: aStream. self collection printElementsOn: aStream! ! "-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "! OrderedDictionary class instanceVariableNames: ''! !OrderedDictionary class methodsFor: 'as yet unclassified' stamp: 'nm 6/11/2009 09:21'! group: aCollection by: aBlock | answer | answer := self new. aCollection do: [:value | (answer at: (aBlock value: value) ifAbsentPut: [OrderedCollection new]) add: value. ]. ^answer! ! Object subclass: #SortedDictionary instanceVariableNames: 'collection' classVariableNames: '' poolDictionaries: '' category: 'OrderedDictionary'! !SortedDictionary methodsFor: 'adding' stamp: 'dl 3/14/2007 16:47'! add: association ^self collection add: association! ! !SortedDictionary methodsFor: 'adding' stamp: 'dl 3/14/2007 17:05'! addAll: aCollection aCollection do: [:each | self add: each]! ! !SortedDictionary methodsFor: 'accessing' stamp: 'dl 3/14/2007 16:54'! at: anObject ^self at: anObject ifAbsent: [self error: 'Item not found']! ! !SortedDictionary methodsFor: 'accessing' stamp: 'dl 3/14/2007 18:11'! at: anObject ifAbsent: absentBlock ^(self collection findBinary: (self findBlockFor: anObject) ifNone: [^absentBlock value]) value! ! !SortedDictionary methodsFor: 'accessing' stamp: 'dl 3/14/2007 17:48'! at: anObject ifAbsentPut: putBlock | value | ^self at: anObject ifAbsent: [ value := putBlock value. self add: anObject -> value. value]! ! !SortedDictionary methodsFor: 'accessing' stamp: 'dl 3/14/2007 18:11'! at: anObject put: aValue | index | index := self collection findBinaryIndex: (self findBlockFor: anObject) ifNone: [0]. index > 0 ifTrue: [ self collection removeAt: index. ]. ^self add: (anObject -> aValue) ! ! !SortedDictionary methodsFor: 'accessing' stamp: 'nm 6/4/2009 21:22'! clear self collection: SortedCollection new ! ! !SortedDictionary methodsFor: 'accessing' stamp: 'dl 3/14/2007 16:41'! collection ^collection! ! !SortedDictionary methodsFor: 'accessing' stamp: 'dl 3/14/2007 16:41'! collection: anObject collection := anObject! ! !SortedDictionary methodsFor: 'accessing' stamp: 'dl 3/14/2007 17:45'! groupBy: aBlock | answer | answer := self class new. self collection do: [:assoc | (answer at: (aBlock value: assoc value) ifAbsentPut: [OrderedCollection new]) add: assoc value. ]. ^answer! ! !SortedDictionary methodsFor: 'accessing' stamp: 'dl 3/14/2007 17:03'! size ^self collection size! ! !SortedDictionary methodsFor: 'accessing' stamp: 'nm 6/4/2009 21:22'! sortBlock ^[:a :b | (self compareBlock value: a value: b) < 0]! ! !SortedDictionary methodsFor: 'private' stamp: 'dl 3/14/2007 17:00'! compareBlock ^[:a :b | (a key compare: b key) - 2]! ! !SortedDictionary methodsFor: 'private' stamp: 'dl 3/14/2007 18:11'! findBlockFor: anObject ^[:b | self compareBlock value: (anObject -> nil) value: b]! ! !SortedDictionary methodsFor: 'enumerating' stamp: 'dl 3/14/2007 17:12'! do: aBlock self collection do: aBlock! ! !SortedDictionary methodsFor: 'enumerating' stamp: 'nm 6/4/2009 21:11'! select: aBlock | newCollection | newCollection _ self species new. self do: [:each | (aBlock value: each value) ifTrue: [newCollection add: each]]. ^newCollection! ! !SortedDictionary methodsFor: 'initialize-release' stamp: 'dl 3/14/2007 16:54'! initialize self clear! ! !SortedDictionary methodsFor: 'testing' stamp: 'nm 6/4/2009 21:04'! isEmpty ^self collection isEmpty! ! !SortedDictionary methodsFor: 'testing' stamp: 'nm 6/4/2009 21:04'! notEmpty ^self collection notEmpty! ! "-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "! SortedDictionary class instanceVariableNames: ''! !SortedDictionary class methodsFor: 'as yet unclassified' stamp: 'dl 3/14/2007 18:24'! group: aCollection by: aBlock | answer | answer := self new. aCollection do: [:value | (answer at: (aBlock value: value) ifAbsentPut: [OrderedCollection new]) add: value. ]. ^answer! !