[squeak-dev] Question About Collections

Ron Teitelbaum ron at usmedrec.com
Mon Jan 6 21:32:42 UTC 2014


Hi JRM,

How about 

RadioProgramSchedule
	iv: 'programs'

initialize 
	programs := Dictionary new.

addShow: aShowName airsOn: aDate

	self programs at: aShowName ifAbsentPut: [SortedCollection new].
	(self programs at: aShowName) add: aDate.
	
With this you end up with 

Dictionary 
	Dr. Who
		SortedCollection
			1/1/2014
			1/2/2014
 			1/3/2014
	The Who
		SortedCollection
			2/1/1985
	Horton Hears a Who
		....

	But this will also allow you to add the same date twice.  You could use set instead of SortedCollection or check for the date first before adding it.

All the best,

Ron Teitelbaum
Head Of Engineering
3d Immersive Collaboration Consulting
ron at 3dicc.com
Follow Me On Twitter: @RonTeitelbaum
www.3dicc.com 
https://www.google.com/+3dicc


> -----Original Message-----
> From: squeak-dev-bounces at lists.squeakfoundation.org [mailto:squeak-dev-
> bounces at lists.squeakfoundation.org] On Behalf Of JohnReed Maffeo
> Sent: Monday, January 06, 2014 3:56 PM
> To: The general-purpose Squeak developers list
> Subject: [squeak-dev] Question About Collections
> 
> I havea collection of radio program schedule objects which includes title and
> broadcast date.
> 
> (title, date)is unique, but title is not, because radio shows can be repeated. I just
> need a list with the title and the last broadcast date.
> 
> What is the Smalltalk way of creating a new collection where title is unique? I
> know how to do this in procedural code, but I expect that there is a more
> elegant, OO way.
> 
> OrderedCollection
> 
> Dr Who  1/1/14
> Dr Who  1/2/14
> Dr Who  1/3/14
> 
> Result
> Dr Who  1/3/14
> 
> Thanks,
> jrm
> 




More information about the Squeak-dev mailing list